Skip to content

Commit

Permalink
Add functionality to remove member form community.
Browse files Browse the repository at this point in the history
  • Loading branch information
adrorocker committed Apr 25, 2023
1 parent 9c1090d commit 98cbe1e
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Endpoint/Member/Members.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
)
);
}
}
32 changes: 32 additions & 0 deletions tests/Endpoint/Member/MembersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('[email protected]');

$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('[email protected]');

}
}
4 changes: 4 additions & 0 deletions tests/stubs/responses/remove_member.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"success": true,
"message": "This user has been removed from the community."
}
4 changes: 4 additions & 0 deletions tests/stubs/responses/remove_member_failed.json
Original file line number Diff line number Diff line change
@@ -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."
}

0 comments on commit 98cbe1e

Please sign in to comment.