mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
[API] Checkout API reselect shipping step tests
This commit is contained in:
parent
283d8cf343
commit
6198c3d1e5
2 changed files with 165 additions and 0 deletions
146
tests/Controller/CheckoutReselectingShippingApiTest.php
Normal file
146
tests/Controller/CheckoutReselectingShippingApiTest.php
Normal file
|
|
@ -0,0 +1,146 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Sylius package.
|
||||||
|
*
|
||||||
|
* (c) Paweł Jędrzejewski
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Sylius\Tests\Controller;
|
||||||
|
|
||||||
|
use Lakion\ApiTestCase\JsonApiTestCase;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mateusz Zalewski <mateusz.zalewski@lakion.com>
|
||||||
|
*/
|
||||||
|
class CheckoutReselectingShippingApiTest extends JsonApiTestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private static $authorizedHeaderWithContentType = [
|
||||||
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ',
|
||||||
|
'CONTENT_TYPE' => 'application/json',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function it_denies_reselecting_order_shipping_for_non_authenticated_user()
|
||||||
|
{
|
||||||
|
$this->client->request('PUT', '/api/checkouts/reselect-shipping/1');
|
||||||
|
|
||||||
|
$response = $this->client->getResponse();
|
||||||
|
$this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function it_does_not_allow_to_reselect_shipping_of_unexisting_order()
|
||||||
|
{
|
||||||
|
$this->loadFixturesFromFile('authentication/api_administrator.yml');
|
||||||
|
|
||||||
|
$this->client->request('PUT', '/api/checkouts/reselect-shipping/1', [], [], static::$authorizedHeaderWithContentType);
|
||||||
|
|
||||||
|
$response = $this->client->getResponse();
|
||||||
|
$this->assertResponseCode($response, Response::HTTP_NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function it_does_not_allow_to_reselect_shipping_of_order_that_has_no_shipment_method_selected()
|
||||||
|
{
|
||||||
|
$this->loadFixturesFromFile('authentication/api_administrator.yml');
|
||||||
|
$checkoutData = $this->loadFixturesFromFile('resources/checkout.yml');
|
||||||
|
|
||||||
|
$orderId = $checkoutData['order1']->getId();
|
||||||
|
$this->addressOrder($orderId);
|
||||||
|
|
||||||
|
$url = sprintf('/api/checkouts/reselect-shipping/%d', $orderId);
|
||||||
|
$this->client->request('PUT', $url, [], [], static::$authorizedHeaderWithContentType);
|
||||||
|
|
||||||
|
$response = $this->client->getResponse();
|
||||||
|
$this->assertResponseCode($response, Response::HTTP_BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function it_allows_to_reselect_shipping_of_order_with_shipment_method_selected()
|
||||||
|
{
|
||||||
|
$this->loadFixturesFromFile('authentication/api_administrator.yml');
|
||||||
|
$checkoutData = $this->loadFixturesFromFile('resources/checkout.yml');
|
||||||
|
|
||||||
|
$orderId = $checkoutData['order1']->getId();
|
||||||
|
$this->addressOrder($orderId);
|
||||||
|
$this->selectOrderShippingMethod($orderId, $checkoutData['ups']->getId());
|
||||||
|
|
||||||
|
$url = sprintf('/api/checkouts/reselect-shipping/%d', $orderId);
|
||||||
|
$this->client->request('PUT', $url, [], [], static::$authorizedHeaderWithContentType);
|
||||||
|
|
||||||
|
$response = $this->client->getResponse();
|
||||||
|
$this->assertResponse($response, 'checkout/reselect_shipping_response', Response::HTTP_OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $orderId
|
||||||
|
*/
|
||||||
|
private function addressOrder($orderId)
|
||||||
|
{
|
||||||
|
$this->loadFixturesFromFile('resources/countries.yml');
|
||||||
|
$customers = $this->loadFixturesFromFile('resources/customers.yml');
|
||||||
|
|
||||||
|
$data =
|
||||||
|
<<<EOT
|
||||||
|
{
|
||||||
|
"shippingAddress": {
|
||||||
|
"firstName": "Hieronim",
|
||||||
|
"lastName": "Bosch",
|
||||||
|
"street": "Surrealism St.",
|
||||||
|
"countryCode": "NL",
|
||||||
|
"city": "’s-Hertogenbosch",
|
||||||
|
"postcode": "99-999"
|
||||||
|
},
|
||||||
|
"billingAddress": {
|
||||||
|
"firstName": "Vincent",
|
||||||
|
"lastName": "van Gogh",
|
||||||
|
"street": "Post-Impressionism St.",
|
||||||
|
"countryCode": "NL",
|
||||||
|
"city": "Groot Zundert",
|
||||||
|
"postcode": "88-888"
|
||||||
|
},
|
||||||
|
"differentBillingAddress": true
|
||||||
|
}
|
||||||
|
EOT;
|
||||||
|
|
||||||
|
$url = sprintf('/api/checkouts/addressing/%d/%d', $orderId, $customers['customer_Oliver']->getId());
|
||||||
|
$this->client->request('PUT', $url, [], [], static::$authorizedHeaderWithContentType, $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $orderId
|
||||||
|
* @param int $shippingMethodId
|
||||||
|
*/
|
||||||
|
private function selectOrderShippingMethod($orderId, $shippingMethodId)
|
||||||
|
{
|
||||||
|
$data =
|
||||||
|
<<<EOT
|
||||||
|
{
|
||||||
|
"shipments": [
|
||||||
|
{
|
||||||
|
"method": {$shippingMethodId}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
EOT;
|
||||||
|
|
||||||
|
$url = sprintf('/api/checkouts/select-shipping/%d', $orderId);
|
||||||
|
$this->client->request('PUT', $url, [], [], static::$authorizedHeaderWithContentType, $data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
{
|
||||||
|
"id": @integer@,
|
||||||
|
"items": @array@,
|
||||||
|
"items_total": @integer@,
|
||||||
|
"adjustments": @wildcard@,
|
||||||
|
"comments": @array@,
|
||||||
|
"adjustments_total": @integer@,
|
||||||
|
"total": @integer@,
|
||||||
|
"state": "cart",
|
||||||
|
"created_at": @string@,
|
||||||
|
"updated_at": @string@,
|
||||||
|
"expires_at": @string@,
|
||||||
|
"channel": @wildcard@,
|
||||||
|
"shipping_address": @wildcard@,
|
||||||
|
"billing_address": @wildcard@,
|
||||||
|
"payments": @array@,
|
||||||
|
"shipments": @array@,
|
||||||
|
"checkout_state": "addressed"
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue