Skip to content

Commit

Permalink
fix(taggedMemebers) - Fix issue when email param is array.
Browse files Browse the repository at this point in the history
This fixes the issue when the $email param is an array. This use case was not supported even tho the signature of the function allowed it.
  • Loading branch information
adrorocker committed Apr 5, 2023
1 parent d74d74d commit fa01676
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Endpoint/TaggedMembers/TaggedMembers.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,20 @@ final class TaggedMembers extends AbstractEndpoint implements EndpointInterface
*/
public function tagMember(string|array $email, int $memberTagId): mixed
{
if (is_array($email)) {
$emailParam = '';
foreach ($email as $e) {
$emailParam .= "user_email[]={$e}&";
}

$emailParam = trim($emailParam, '&');
} else {
$emailParam = "user_email={$email}";
}

return $this->factorResponse(
$this->circleSo->getHttpClient()->post(
"/tagged_members?user_email={$email}&member_tag_id={$memberTagId}"
"/tagged_members?{$emailParam}&member_tag_id={$memberTagId}"
)
);
}
Expand Down
14 changes: 14 additions & 0 deletions tests/Endpoint/TaggedMembers/TaggedMembersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ public function test_tag_member_ok(): void
$this->assertSame(true, $response['success']);
}

public function test_tag_member_array_ok(): void
{
$circleSo = $this->getSdkWithMockedClient([
new Response(200, [], json_response('success_true')),
]);

$response = $circleSo->taggedMembers()
->tagMember(['[email protected]', '[email protected]'], 123456);

$this->assertArrayHasKey('success', $response);

$this->assertSame(true, $response['success']);
}

public function test_untag_member_ok(): void
{
$circleSo = $this->getSdkWithMockedClient([
Expand Down

0 comments on commit fa01676

Please sign in to comment.