Skip to content

Commit

Permalink
[Unit][Orders] Add tests for adding items to the cart validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafikooo committed Jul 3, 2023
1 parent 09a5b65 commit 84669f4
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions tests/Api/Shop/OrdersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -477,4 +477,58 @@ public function it_returns_unprocessable_entity_status_if_tries_to_remove_an_ite

$this->assertResponseCode($this->client->getResponse(), Response::HTTP_UNPROCESSABLE_ENTITY);
}

/** @test */
public function it_prevents_from_adding_an_item_to_the_cart_if_product_variant_is_missing(): void
{
$this->loadFixturesFromFiles(['channel.yaml', 'cart.yaml']);

$tokenValue = 'nAWw2jewpA';

/** @var MessageBusInterface $commandBus */
$commandBus = self::getContainer()->get('sylius.command_bus');

$pickupCartCommand = new PickupCart($tokenValue);
$pickupCartCommand->setChannelCode('WEB');
$commandBus->dispatch($pickupCartCommand);

$this->client->request(
method: 'POST',
uri: sprintf('/api/v2/shop/orders/%s/items', $tokenValue),
server: self::CONTENT_TYPE_HEADER,
content: json_encode([
'quantity' => 3,
], JSON_THROW_ON_ERROR),
);
$response = $this->client->getResponse();

$this->assertResponseCode($response, Response::HTTP_UNPROCESSABLE_ENTITY);
}

/** @test */
public function it_prevents_from_adding_an_item_to_the_cart_if_quantity_is_missing(): void
{
$this->loadFixturesFromFiles(['channel.yaml', 'cart.yaml']);

$tokenValue = 'nAWw2jewpA';

/** @var MessageBusInterface $commandBus */
$commandBus = self::getContainer()->get('sylius.command_bus');

$pickupCartCommand = new PickupCart($tokenValue);
$pickupCartCommand->setChannelCode('WEB');
$commandBus->dispatch($pickupCartCommand);

$this->client->request(
method: 'POST',
uri: sprintf('/api/v2/shop/orders/%s/items', $tokenValue),
server: self::CONTENT_TYPE_HEADER,
content: json_encode([
'productVariant' => 'MUG_BLUE',
], JSON_THROW_ON_ERROR),
);
$response = $this->client->getResponse();

$this->assertResponseCode($response, Response::HTTP_UNPROCESSABLE_ENTITY);
}
}

0 comments on commit 84669f4

Please sign in to comment.