Skip to content
This repository was archived by the owner on Oct 24, 2023. It is now read-only.

Commit b3606b6

Browse files
author
Jens Schulze
committed
test(Inventory): test product search for availability by multiple channels
1 parent f4e2c0e commit b3606b6

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

tests/integration/Inventory/InventoryUpdateRequestTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use Commercetools\Core\Model\CustomField\CustomFieldObject;
1010
use Commercetools\Core\Model\Inventory\InventoryDraft;
1111
use Commercetools\Core\Model\Message\InventoryEntryDeletedMessage;
12+
use Commercetools\Core\Model\Product\ProductProjection;
13+
use Commercetools\Core\Model\Product\Search\Filter;
1214
use Commercetools\Core\Model\Type\TypeReference;
1315
use Commercetools\Core\Request\CustomField\Command\SetCustomFieldAction;
1416
use Commercetools\Core\Request\CustomField\Command\SetCustomTypeAction;
@@ -22,6 +24,7 @@
2224
use Commercetools\Core\Request\Inventory\InventoryDeleteRequest;
2325
use Commercetools\Core\Request\Inventory\InventoryUpdateRequest;
2426
use Commercetools\Core\Request\Messages\MessageQueryRequest;
27+
use Commercetools\Core\Request\Products\ProductProjectionSearchRequest;
2528

2629
class InventoryUpdateRequestTest extends ApiTestCase
2730
{
@@ -180,6 +183,45 @@ public function testSetSupplyChannel()
180183
$this->deleteRequest->setVersion($result->getVersion());
181184
}
182185

186+
public function testQueryChannels()
187+
{
188+
$channel = $this->getChannel();
189+
$draft = $this->getDraft('sku');
190+
$draft = $draft->setQuantityOnStock(1);
191+
$draft->setSupplyChannel($channel->getReference());
192+
$this->createInventory($draft);
193+
194+
$product = $this->getProduct();
195+
196+
$retries = 0;
197+
do {
198+
$retries++;
199+
sleep(1);
200+
$request = ProductProjectionSearchRequest::of()
201+
->addFilterQuery(Filter::ofName('id')->setValue($product->getId()))
202+
->limit(1);
203+
$response = $request->executeWithClient($this->getClient());
204+
$result = $request->mapResponse($response);
205+
} while ($result->count() > 0 && $retries <= 9);
206+
207+
$request = ProductProjectionSearchRequest::of()
208+
->addFilterQuery(
209+
Filter::ofName('variants.availability.isOnStockInChannels')->setValue([$channel->getId()])
210+
)
211+
->limit(1);
212+
$response = $request->executeWithClient($this->getClient());
213+
$result = $request->mapResponse($response);
214+
215+
$this->assertSame(
216+
$product->getId(),
217+
$result->current()->getId()
218+
);
219+
$this->assertSame(
220+
$channel->getId(),
221+
$result->current()->getMasterVariant()->getAvailability()->getChannels()->key()
222+
);
223+
}
224+
183225
/**
184226
* @large
185227
*/

0 commit comments

Comments
 (0)