Implement Miniflux user deletion
This commit is contained in:
parent
bf95b134bd
commit
31f0539dc0
2 changed files with 35 additions and 2 deletions
|
@ -480,6 +480,15 @@ class V1 extends \JKingWeb\Arsse\REST\AbstractHandler {
|
|||
return new Response($out);
|
||||
}
|
||||
|
||||
protected function deleteUserByNum(array $path): ResponseInterface {
|
||||
try {
|
||||
Arsse::$user->remove(Arsse::$user->lookup((int) $path[1]));
|
||||
} catch (ExceptionConflict $e) {
|
||||
return new ErrorResponse("404", 404);
|
||||
}
|
||||
return new EmptyResponse(204);
|
||||
}
|
||||
|
||||
protected function getCategories(): ResponseInterface {
|
||||
$out = [];
|
||||
$meta = Arsse::$user->propertiesGet(Arsse::$user->id, false);
|
||||
|
|
|
@ -371,11 +371,35 @@ class TestV1 extends \JKingWeb\Arsse\Test\AbstractTest {
|
|||
}
|
||||
|
||||
public function testAddAUserWithoutAuthority(): void {
|
||||
Arsse::$user = $this->createMock(User::class);
|
||||
Arsse::$user->method("propertiesGet")->willReturn(['num' => 1, 'admin' => false]);
|
||||
$this->assertMessage(new ErrorResponse("403", 403), $this->req("POST", "/users", []));
|
||||
}
|
||||
|
||||
public function testDeleteAUser(): void {
|
||||
Arsse::$user = $this->createMock(User::class);
|
||||
Arsse::$user->method("propertiesGet")->willReturn(['admin' => true]);
|
||||
Arsse::$user->method("lookup")->willReturn("john.doe@example.com");
|
||||
Arsse::$user->method("remove")->willReturn(true);
|
||||
Arsse::$user->expects($this->exactly(1))->method("lookup")->with(2112);
|
||||
Arsse::$user->expects($this->exactly(1))->method("remove")->with("john.doe@example.com");
|
||||
$this->assertMessage(new EmptyResponse(204), $this->req("DELETE", "/users/2112"));
|
||||
}
|
||||
|
||||
public function testDeleteAMissingUser(): void {
|
||||
Arsse::$user = $this->createMock(User::class);
|
||||
Arsse::$user->method("propertiesGet")->willReturn(['admin' => true]);
|
||||
Arsse::$user->method("lookup")->willThrowException(new ExceptionConflict("doesNotExist"));
|
||||
Arsse::$user->method("remove")->willReturn(true);
|
||||
Arsse::$user->expects($this->exactly(1))->method("lookup")->with(2112);
|
||||
Arsse::$user->expects($this->exactly(0))->method("remove");
|
||||
$this->assertMessage(new ErrorResponse("404", 404), $this->req("DELETE", "/users/2112"));
|
||||
}
|
||||
|
||||
public function testDeleteAUserWithoutAuthority(): void {
|
||||
Arsse::$user->expects($this->exactly(0))->method("lookup");
|
||||
Arsse::$user->expects($this->exactly(0))->method("remove");
|
||||
$this->assertMessage(new ErrorResponse("403", 403), $this->req("DELETE", "/users/2112"));
|
||||
}
|
||||
|
||||
public function testListCategories(): void {
|
||||
\Phake::when(Arsse::$db)->folderList->thenReturn(new Result($this->v([
|
||||
['id' => 1, 'name' => "Science"],
|
||||
|
|
Loading…
Reference in a new issue