Skip to content

Commit

Permalink
AUT-2569: add limit and offset params to contactlist fetching endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Gergely Illyes committed Mar 6, 2024
1 parent b8d6f21 commit 462405e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Suite/Api/ContactList.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ public function getContactsOfList(int $customerId, int $contactListId, int $limi
}
}

public function getContactIdsInList(int $customerId, int $contactListId)
public function getContactIdsInList(int $customerId, int $contactListId, int $limit = null, int $offset = null)
{
try {
$response = $this->apiClient->get($this->endPoints->contactIdsInList($customerId, $contactListId));
$response = $this->apiClient->get($this->endPoints->contactIdsInList($customerId, $contactListId, $limit, $offset));
return $response['data'] ?? [];
} catch (Error $error) {
throw new RequestFailed('Could not fetch contact ids: ' . $error->getMessage(), $error->getCode(), $error);
Expand Down
8 changes: 6 additions & 2 deletions src/Suite/Api/ContactListEndPoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@ 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)
public function contactIdsInList(int $customerId, int $contactListId, int $limit = null, int $offset = null)
{
return $this->baseUrl($customerId) . "/{$contactListId}/contactIds";
$result = $this->baseUrl($customerId) . "/{$contactListId}/contactIds";
if (null !== $limit && null !== $offset) {
$result .= "?\$top={$limit}&\$skiptoken={$offset}";
}
return $result;
}

public function deleteContactsFromList(int $customerId, int $contactListId): string
Expand Down
15 changes: 15 additions & 0 deletions test/unit/Suite/Api/ContactListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,21 @@ public function getContactIdsInList_CalledWithProperUrl_ApiResponseConverted():
$this->assertEquals($response, $result);
}

/**
* @test
*/
public function getContactIdsInList_CalledWithProperUrlAndParams_ApiResponseConverted(): void
{
$response = ['value' => [1, 2, 3], 'next' => null];
$this->apiClient
->method('get')
->with("api_base_url/$this->customerId/contactlist/$this->contactListId/contactIds?\$top=1&\$skiptoken=1")
->willReturn($this->apiSuccess($response));

$result = $this->listService->getContactIdsInList($this->customerId, $this->contactListId, 1, 1);
$this->assertEquals($response, $result);
}

/**
* @test
*/
Expand Down

0 comments on commit 462405e

Please sign in to comment.