Skip to content

Commit

Permalink
next url returned from Suite API fetch contactIds endpoint is a relat…
Browse files Browse the repository at this point in the history
…ive URL

- AUT-3246

Co-authored-by: Bence Kadar <[email protected]>
  • Loading branch information
fqqdk and bencekadaremar committed Sep 20, 2024
1 parent b6eb66c commit 4433009
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/Suite/Api/ContactList.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,11 @@ public function getContactIdsInList(int $customerId, int $contactListId, int $to

public function getListChunkIterator(int $customerId, int $contactListId, int $chunkSize = null) : iterable
{
$next = $this->endPoints->contactIdsInList($customerId, $contactListId, $chunkSize);
$nextUrlFull = $this->endPoints->contactIdsInList($customerId, $contactListId, $chunkSize);
try {
do {
['value' => $value, 'next' => $next] = $this->apiClient->get($next)['data'];
['value' => $value, 'next' => $next] = $this->apiClient->get($nextUrlFull)['data'];
$nextUrlFull = $this->endPoints->contactIdsInListNextChunk($customerId, $next);
yield $value;
} while ($next !== null);
} catch (Error $error) {
Expand Down
5 changes: 5 additions & 0 deletions src/Suite/Api/ContactListEndPoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public function contactIdsInList(int $customerId, int $contactListId, int $top =
);
}

public function contactIdsInListNextChunk(int $customerId, string $next = null): ?string
{
return $next ? "{$this->apiBaseUrl}/{$customerId}{$next}" : null;
}

public function deleteContactsFromList(int $customerId, int $contactListId): string
{
return $this->baseUrl($customerId) . "/{$contactListId}/delete";
Expand Down
8 changes: 4 additions & 4 deletions test/helper/ApiStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ public static function setUp()
return new Response(self::success(self::getRetryCount()));
});

$app->get('/{customerId}/contactlist/{contactListId}/contactIds', function (Request $request, $contactListId, $customerId) {
$app->get('/{customerId}/contactlist/{contactListId}/contactIds', function (Request $request, $contactListId) {
return match ($contactListId) {
(string) self::LIST_ID_FOR_EMPTY_LIST => new Response(self::success('{"value":[],"next":null}')),
(string) self::LIST_ID_FOR_LIST_WITH_SINGLE_CHUNK => new Response(self::success('{"value":[1,2,3],"next":null}')),
(string) self::LIST_ID_FOR_LIST_WITH_MULTIPLE_CHUNKS => match ($request->query->get('$skiptoken') ?? '0') {
'0' => new Response(self::success('{"value":[1,2,3],"next":"http://localhost:7984/'.$customerId.'/contactlist/'.$contactListId.'/contactIds?$skiptoken=1"}')),
'1' => new Response(self::success('{"value":[4,5,6],"next":"http://localhost:7984/'.$customerId.'/contactlist/'.$contactListId.'/contactIds?$skiptoken=2"}')),
'2' => new Response(self::success('{"value":[7,8,9],"next":"http://localhost:7984/'.$customerId.'/contactlist/'.$contactListId.'/contactIds?$skiptoken=3"}')),
'0' => new Response(self::success('{"value":[1,2,3],"next":"/contactlist/'.$contactListId.'/contactIds?$skiptoken=1"}')),
'1' => new Response(self::success('{"value":[4,5,6],"next":"/contactlist/'.$contactListId.'/contactIds?$skiptoken=2"}')),
'2' => new Response(self::success('{"value":[7,8,9],"next":"/contactlist/'.$contactListId.'/contactIds?$skiptoken=3"}')),
'3' => new Response(self::success('{"value":[10,11],"next":null}')),
},
(string) self::LIST_ID_FOR_WRONG_RESPONSE => new Response(self::error('invalid response format')),
Expand Down

0 comments on commit 4433009

Please sign in to comment.