Skip to content

Commit

Permalink
next url returned from Suite API fetch contactIds endpoint is relativ…
Browse files Browse the repository at this point in the history
…e to /v2 (/internal/{customerId}/... for internal calls)

- AUT-3246

Co-authored-by: Bence Kadar <[email protected]>
  • Loading branch information
fqqdk and bencekadaremar committed Sep 20, 2024
1 parent 4433009 commit 1329e89
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
8 changes: 7 additions & 1 deletion src/Suite/Api/ContactListEndPoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,17 @@ 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;

return $next ? $this->getBaseUrlWithoutInternalPostfix() . "{$next}" : null;
}

public function deleteContactsFromList(int $customerId, int $contactListId): string
{
return $this->baseUrl($customerId) . "/{$contactListId}/delete";
}

public function getBaseUrlWithoutInternalPostfix(): string
{
return preg_replace('/\/internal$/', '', $this->apiBaseUrl);
}
}
2 changes: 1 addition & 1 deletion test/helper/AcceptanceBaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class AcceptanceBaseTestCase extends \PHPUnit\Framework\TestCase
/**
* @var string
*/
protected $apiBaseUrl = 'http://localhost:7984';
protected $apiBaseUrl = 'http://localhost:7984/internal';

protected function setUp(): void
{
Expand Down
20 changes: 10 additions & 10 deletions test/helper/ApiStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,42 +24,42 @@ public static function setUp()
$app->before(self::authenticateWithEscher());
$app->error(self::handleError());

$app->get('/', self::clientTestEndPoint());
$app->get('/internal/', self::clientTestEndPoint());

foreach (include __DIR__.'/stubs.php' as $route => $data) {
$app->get($route, function () use ($data) { return self::success($data); });
}

$app->post('/{customerId}/email/{campaignId}/preview/', function (Request $request) {
$app->post('/internal/{customerId}/email/{campaignId}/preview/', function (Request $request) {
$params = json_decode($request->getContent(), true);
return new Response(self::success('"'.$params['version'].' version"'));
});

$app->post('/{customerId}/email/{campaignId}/launch/', function (Request $request) {
$app->post('/internal/{customerId}/email/{campaignId}/launch/', function (Request $request) {
return new Response(self::success("null"));
});

$app->post('/{customerId}/email/delete/', function (Request $request) {
$app->post('/internal/{customerId}/email/delete/', function (Request $request) {
return new Response(self::success("null"));
});

$app->get('/serverError', function (Request $request) {
$app->get('/internal/serverError', function (Request $request) {
self::logRetry();
return new Response(self::error("null"), 500);
});

$app->get('/retryCount', function (Request $request) {
$app->get('/internal/retryCount', function (Request $request) {
return new Response(self::success(self::getRetryCount()));
});

$app->get('/{customerId}/contactlist/{contactListId}/contactIds', function (Request $request, $contactListId) {
$app->get('/internal/{customerId}/contactlist/{contactListId}/contactIds', function (Request $request, $contactListId, $customerId) {
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":"/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"}')),
'0' => new Response(self::success('{"value":[1,2,3],"next":"/internal/'.$customerId.'/contactlist/'.$contactListId.'/contactIds?$skiptoken=1"}')),
'1' => new Response(self::success('{"value":[4,5,6],"next":"/internal/'.$customerId.'/contactlist/'.$contactListId.'/contactIds?$skiptoken=2"}')),
'2' => new Response(self::success('{"value":[7,8,9],"next":"/internal/'.$customerId.'/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
10 changes: 5 additions & 5 deletions test/helper/stubs.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php return [
'/{customerId}/email/{campaignId}/' => '{
'/internal/{customerId}/email/{campaignId}/' => '{
"id": "1",
"language": "en",
"name": "20160407_1502_Copy of Test mail 1",
Expand Down Expand Up @@ -35,7 +35,7 @@
"source": "userlist"
}',

'/{customerId}/email/' => '[
'/internal/{customerId}/email/' => '[
{
"id": "2",
"administrator": "3",
Expand Down Expand Up @@ -87,7 +87,7 @@
"source": "profile"
}
]',
'/{customerId}/administrator/' => '[
'/internal/{customerId}/administrator/' => '[
{
"id": "1",
"username": "admin",
Expand Down Expand Up @@ -130,7 +130,7 @@
}
]',

'/{customerId}/event' => '[
'/internal/{customerId}/event' => '[
{
"id": "1",
"name": "event egy",
Expand All @@ -149,7 +149,7 @@
}
]',

'/{customerId}/filter' => '[
'/internal/{customerId}/filter' => '[
{
"id": "1",
"name": "segment 1",
Expand Down

0 comments on commit 1329e89

Please sign in to comment.