public function CartUpdateItemResourceTest::testInvalidPayload in Commerce Cart API 8
Tests malformed payloads.
File
- tests/
src/ Functional/ CartUpdateItemResourceTest.php, line 98
Class
- CartUpdateItemResourceTest
- Tests the cart update items resource.
Namespace
Drupal\Tests\commerce_cart_api\FunctionalCode
public function testInvalidPayload() {
$request_options = $this
->getAuthenticationRequestOptions('PATCH');
$request_options[RequestOptions::HEADERS]['Content-Type'] = static::$mimeType;
$cart = $this->cartProvider
->createCart('default', $this->store, $this->account);
$this->cartManager
->addEntity($cart, $this->variation, 2);
$this
->assertEquals(count($cart
->getItems()), 1);
$items = $cart
->getItems();
$order_item = $items[0];
$url = Url::fromUri('base:cart/' . $cart
->id() . '/items/' . $order_item
->id());
$url
->setOption('query', [
'_format' => static::$format,
]);
$request_options[RequestOptions::BODY] = '{"quantity":"1", "another_field":"1"}';
$response = $this
->request('PATCH', $url, $request_options);
$this
->assertResourceErrorResponse(422, 'You only have access to update the quantity', $response);
$request_options[RequestOptions::BODY] = '{"not_quantity":"1"}';
$response = $this
->request('PATCH', $url, $request_options);
$this
->assertResourceErrorResponse(422, 'You only have access to update the quantity', $response);
$request_options[RequestOptions::BODY] = '{"quantity":"-1"}';
$response = $this
->request('PATCH', $url, $request_options);
$this
->assertResourceErrorResponse(422, 'Quantity must be positive value', $response);
}