-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged PR 41388: Use do-while loop to fetch more than 1000 API items …
…(address books) ## What's being changed Dotdigital API calls fetch at most 1000 items per call. As currently our API endpoints are implemented we can't exceed that limit. So we added a do-while loop in our addressBooks controller in order to continuously fetch all the api items (addressBooks) for merchants that have more than 1000 address books. ## Why it's being changed In order to list all the available address books even if those are more than 1000. ## How to review / test this change - Confirm that you get all the address books - If you don't have more than 1000 address books in your dotdigital account change the SKIP_LIMIT const in AbstractClient to e.g 100. So if you have 300 address books you should still get all the address books in contact flow modal. Additionally you can put a breakpoint to the do-while loop and to see that process works as expected. Related work items: #192199
- Loading branch information
Showing
4 changed files
with
92 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Dotdigital\Tests\Controller; | ||
|
||
use DG\BypassFinals; | ||
use Dotdigital\Flow\Api\Controller\AddressBooksController; | ||
use Dotdigital\Flow\Service\Client\DotdigitalClient; | ||
use Dotdigital\Flow\Service\Client\DotdigitalClientFactory; | ||
use Dotdigital\Tests\Traits\InteractWithAddressBooksTrait; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
|
||
class AddressBooksControllerTest extends TestCase | ||
{ | ||
use InteractWithAddressBooksTrait; | ||
|
||
private const LIMIT_NOT_EXCEEDED = 900; | ||
private const LIMIT_EXCEEDED = 2500; | ||
|
||
private $dotdigitalClientMock; | ||
|
||
private $dotdigitalClientFactoryMock; | ||
|
||
protected function setUp(): void | ||
{ | ||
BypassFinals::enable(); | ||
$this->dotdigitalClientFactoryMock = $this->createMock(DotdigitalClientFactory::class); | ||
$this->dotdigitalClientMock = $this->createMock(DotdigitalClient::class); | ||
|
||
$this->dotdigitalClientFactoryMock->expects(static::any()) | ||
->method('createClient') | ||
->willReturn($this->dotdigitalClientMock); | ||
|
||
$this->addressBooksController = new AddressBooksController( | ||
$this->dotdigitalClientFactoryMock | ||
); | ||
} | ||
|
||
public function testControllerForLessItemsThanTheApiLimit(): void | ||
{ | ||
$this->dotdigitalClientMock->expects(static::any()) | ||
->method('getAddressBooks') | ||
->willReturn($this->generateAddressBookCollection(self::LIMIT_NOT_EXCEEDED)); | ||
|
||
$response = $this->addressBooksController->showAddressBooks(); | ||
|
||
static::assertInstanceOf(JsonResponse::class, $response); | ||
static::assertEquals(\count(json_decode($response->getContent())), self::LIMIT_NOT_EXCEEDED); | ||
} | ||
|
||
public function testControllerForMoreItemsThanTheApiLimit(): void | ||
{ | ||
$this->dotdigitalClientMock->expects(static::any()) | ||
->method('getAddressBooks') | ||
->willReturnOnConsecutiveCalls( | ||
$this->generateAddressBookCollection(1000), | ||
$this->generateAddressBookCollection(1000), | ||
$this->generateAddressBookCollection(500) | ||
); | ||
|
||
$response = $this->addressBooksController->showAddressBooks(); | ||
|
||
static::assertInstanceOf(JsonResponse::class, $response); | ||
static::assertEquals(\count(json_decode($response->getContent())), self::LIMIT_EXCEEDED); | ||
} | ||
} |