From 98cbe1e42494c6c7a8a6e5b511b94838241bdc3e Mon Sep 17 00:00:00 2001 From: Adro Rocker Date: Tue, 25 Apr 2023 16:21:00 -0600 Subject: [PATCH] Add functionality to remove member form community. --- src/Endpoint/Member/Members.php | 14 ++++++++ tests/Endpoint/Member/MembersTest.php | 32 +++++++++++++++++++ tests/stubs/responses/remove_member.json | 4 +++ .../stubs/responses/remove_member_failed.json | 4 +++ 4 files changed, 54 insertions(+) create mode 100644 tests/stubs/responses/remove_member.json create mode 100644 tests/stubs/responses/remove_member_failed.json diff --git a/src/Endpoint/Member/Members.php b/src/Endpoint/Member/Members.php index 3a43759..7e3a170 100644 --- a/src/Endpoint/Member/Members.php +++ b/src/Endpoint/Member/Members.php @@ -132,4 +132,18 @@ public function update( ) ); } + + /** + * Remove Member from Community + */ + public function remove(string $email, ?int $communityId = null): mixed + { + $this->ensureCommunityIdIsPresent($communityId); + + return $this->factorResponse( + $this->circleSo->getHttpClient()->delete( + "/community_members?community_id={$this->communityId}&email={$email}" + ) + ); + } } diff --git a/tests/Endpoint/Member/MembersTest.php b/tests/Endpoint/Member/MembersTest.php index 8b52f64..df76cd6 100644 --- a/tests/Endpoint/Member/MembersTest.php +++ b/tests/Endpoint/Member/MembersTest.php @@ -120,4 +120,36 @@ public function test_member_update_failed(): void data: ['first_name' => 'Adroeck'], ); } + + public function test_member_removed_ok(): void + { + $circleSo = $this->getSdkWithMockedClient([ + new Response(200, [], json_response('remove_member')), + ]); + + $response = $circleSo->members() + ->communityId(1) + ->remove('adro@example.com'); + + $this->assertSame(true, $response['success']); + $this->assertSame('This user has been removed from the community.', $response['message']); + } + + public function test_member_removed_failed(): void + { + $this->expectException(UnsuccessfulResponseException::class); + $this->expectExceptionMessage( + 'This user could not be removed. Please ensure that the user and community specified exists, and that the user is a member of the community.' + ); + $this->expectExceptionCode(500); + + $circleSo = $this->getSdkWithMockedClient([ + new Response(200, [], json_response('remove_member_failed')), + ]); + + $circleSo->members() + ->communityId(1) + ->remove('i_dont_exist@example.com'); + + } } diff --git a/tests/stubs/responses/remove_member.json b/tests/stubs/responses/remove_member.json new file mode 100644 index 0000000..fda72f1 --- /dev/null +++ b/tests/stubs/responses/remove_member.json @@ -0,0 +1,4 @@ +{ + "success": true, + "message": "This user has been removed from the community." +} \ No newline at end of file diff --git a/tests/stubs/responses/remove_member_failed.json b/tests/stubs/responses/remove_member_failed.json new file mode 100644 index 0000000..ee5a627 --- /dev/null +++ b/tests/stubs/responses/remove_member_failed.json @@ -0,0 +1,4 @@ +{ + "success": false, + "message": "This user could not be removed. Please ensure that the user and community specified exists, and that the user is a member of the community." +} \ No newline at end of file