From e8af41adeeb8f9a70eac12db36896585f646a1cb Mon Sep 17 00:00:00 2001 From: megakapa Date: Fri, 9 Feb 2024 11:56:55 +0100 Subject: [PATCH] add new endpoint to fetch contact ids from list - AUT-2568 --- src/Suite/Api/ContactList.php | 11 +++++++++++ src/Suite/Api/ContactListEndPoints.php | 5 +++++ test/unit/Suite/Api/ContactListTest.php | 25 +++++++++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/src/Suite/Api/ContactList.php b/src/Suite/Api/ContactList.php index 1a7e024..836bfa6 100644 --- a/src/Suite/Api/ContactList.php +++ b/src/Suite/Api/ContactList.php @@ -106,6 +106,9 @@ public function deleteContactsFromList(int $customerId, int $contactListId, arra } + /** + * @deprecated + */ public function getContactsOfList(int $customerId, int $contactListId, int $limit, int $offset) { try { @@ -116,6 +119,14 @@ public function getContactsOfList(int $customerId, int $contactListId, int $limi } } + public function getContactIdsInList(int $customerId, int $contactListId) + { + try { + return $this->apiClient->get($this->endPoints->contactIdsInList($customerId, $contactListId)); + } catch (Error $error) { + throw new RequestFailed('Could not fetch contact ids: ' . $error->getMessage(), $error->getCode(), $error); + } + } /** * @param int $customerId diff --git a/src/Suite/Api/ContactListEndPoints.php b/src/Suite/Api/ContactListEndPoints.php index 42758e9..1308916 100644 --- a/src/Suite/Api/ContactListEndPoints.php +++ b/src/Suite/Api/ContactListEndPoints.php @@ -44,6 +44,11 @@ public function contactsOfList(int $customerId, int $contactListId, int $limit, return $this->baseUrl($customerId) . "/{$contactListId}/contacts/?limit={$limit}&offset={$offset}"; } + public function contactIdsInList(int $customerId, int $contactListId) + { + return $this->baseUrl($customerId) . "/{$contactListId}/contactIds"; + } + public function deleteContactsFromList(int $customerId, int $contactListId): string { return $this->baseUrl($customerId) . "/{$contactListId}/delete"; diff --git a/test/unit/Suite/Api/ContactListTest.php b/test/unit/Suite/Api/ContactListTest.php index be68e7c..988e880 100644 --- a/test/unit/Suite/Api/ContactListTest.php +++ b/test/unit/Suite/Api/ContactListTest.php @@ -234,6 +234,31 @@ public function replaceContactList_ApiFailure_ThrowsException() $this->listService->replaceContactList($this->customerId, $this->contactListId, $contactIds); } + /** + * @test + */ + public function getContactIdsInList_Perfect_Perfect() + { + $response = ['value' => [1, 2, 3], 'next' => null]; + $this->apiClient->expects($this->once())->method('get')->with( + $this->endPoints->contactIdsInList($this->customerId, $this->contactListId) + )->willReturn($response); + + $result = $this->listService->getContactIdsInList($this->customerId, $this->contactListId); + $this->assertEquals($response, $result); + } + + /** + * @test + */ + public function getContactIdsInList_ApiCallFails_ExceptionThrown() + { + $this->apiClient->expects($this->once())->method('get')->will($this->apiFailure()); + $this->expectException(RequestFailed::class); + + $this->listService->getContactIdsInList($this->customerId, $this->contactListId); + } + /** * @test