Skip to content

Commit

Permalink
feat: add user delete endpoint (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
jshah4517 authored Jun 3, 2024
1 parent ce2f274 commit bcbfb51
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 14 deletions.
10 changes: 10 additions & 0 deletions src/Api/User/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ public function updateUser(int $id, UpdateUser $data): User
return $this->createUserModel($this->decodeBody($response)['data']);
}

/**
* @throws HttpResponseException
*/
public function deleteUser(int $id): bool
{
$response = $this->getApiClient()->deleteUser($id);

return $this->decodeBody($response)['status'] === 'success';
}

/**
* @param array<mixed> $data
*/
Expand Down
24 changes: 12 additions & 12 deletions src/Http/User/UserApis.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@ public function getUser(int $userId): ResponseInterface
*/
public function putUser(int $userId, array $body): ResponseInterface
{
$request = $this->getRequest()->create(
'PUT',
ApiDictionary::USER_USER . '/' . $userId,
[],
$body
);
$request = $this->getRequest()->create('PUT', ApiDictionary::USER_USER . '/' . $userId, [], $body);

return $this->sendRequest($request);
}
Expand All @@ -56,12 +51,17 @@ public function putUser(int $userId, array $body): ResponseInterface
*/
public function postUser(array $body): ResponseInterface
{
$request = $this->getRequest()->create(
'POST',
ApiDictionary::USER_USER,
[],
$body
);
$request = $this->getRequest()->create('POST', ApiDictionary::USER_USER, [], $body);

return $this->sendRequest($request);
}

/**
* @throws HttpResponseException
*/
public function deleteUser(int $id): ResponseInterface
{
$request = $this->getRequest()->create('DELETE', ApiDictionary::USER_USER . '/' . $id);

return $this->sendRequest($request);
}
Expand Down
10 changes: 10 additions & 0 deletions test/DataFixtures/ApiCalls/UserApisData.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,14 @@ public function putApiCalls(): array
'updateUser' => [1, $updateUser->getFilledInstance(), $updateUser->getResponse()],
];
}

/**
* @return array<string, int>
*/
public function deleteApiCalls(): array
{
return [
'deleteUser' => 1,
];
}
}
2 changes: 1 addition & 1 deletion test/Functional/Api/UserApisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected function getPutEndpoints(): array
*/
protected function getDeleteEndpoints(): array
{
return [];
return (new UserApisData)->deleteApiCalls();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/Integration/Api/UserApisComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected function getPutEndpoints(): array
*/
protected function getDeleteEndpoints(): array
{
return [];
return (new UserApisData)->deleteApiCalls();
}

/**
Expand Down
13 changes: 13 additions & 0 deletions test/Unit/Api/User/UserApisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,17 @@ public function testUpdateUser(): void
$user = $this->api->updateUser(self::TEST_ID, $updateUser);
self::assertEquals($output, $user);
}

public function testDeleteUser(): void
{
$response = $this->makeSuccessResponse();

$this->apiClient
->deleteUser(1)
->shouldBeCalled()
->willReturn($response->reveal());

$apiResponse = $this->api->deleteUser(1);
self::assertTrue($apiResponse);
}
}

0 comments on commit bcbfb51

Please sign in to comment.