[API] Added checking order response after successfull checkout requests

This commit is contained in:
Mateusz Zalewski 2016-09-01 15:27:00 +02:00
parent ca34ca43cd
commit 6fa9fc156c
11 changed files with 270 additions and 13 deletions

View file

@ -52,8 +52,7 @@ class AddDefaultBillingAddressOnOrderFormSubscriber implements EventSubscriberIn
private function shouldBillingAndShippingAddressBeTheSame(array $orderData)
{
return
(!isset($orderData['differentBillingAddress']) ||
false === $orderData['differentBillingAddress']) &&
(!isset($orderData['differentBillingAddress']) || false === $orderData['differentBillingAddress']) &&
isset($orderData['shippingAddress'])
;
}

View file

@ -48,9 +48,9 @@ final class CheckoutAddressingApiTest extends CheckoutApiTestCase
public function it_does_not_allow_to_address_order_for_unexisting_customer()
{
$this->loadFixturesFromFile('authentication/api_administrator.yml');
$orders = $this->loadFixturesFromFile('resources/checkout.yml');
$checkoutData = $this->loadFixturesFromFile('resources/checkout.yml');
$url = sprintf('/api/checkouts/addressing/%d/0', $orders['order1']->getId());
$url = sprintf('/api/checkouts/addressing/%d/0', $checkoutData['order1']->getId());
$this->client->request('PUT', $url, [], [], static::$authorizedHeaderWithContentType);
$response = $this->client->getResponse();
@ -64,7 +64,7 @@ final class CheckoutAddressingApiTest extends CheckoutApiTestCase
{
$this->loadFixturesFromFile('authentication/api_administrator.yml');
$customers = $this->loadFixturesFromFile('resources/customers.yml');
$orders = $this->loadFixturesFromFile('resources/checkout.yml');
$checkoutData = $this->loadFixturesFromFile('resources/checkout.yml');
$data =
<<<EOT
@ -73,7 +73,7 @@ final class CheckoutAddressingApiTest extends CheckoutApiTestCase
}
EOT;
$url = sprintf('/api/checkouts/addressing/%d/%d', $orders['order1']->getId(), $customers['customer_Oliver']->getId());
$url = sprintf('/api/checkouts/addressing/%d/%d', $checkoutData['order1']->getId(), $customers['customer_Oliver']->getId());
$this->client->request('PUT', $url, [], [], static::$authorizedHeaderWithContentType, $data);
$response = $this->client->getResponse();
@ -88,7 +88,7 @@ EOT;
$this->loadFixturesFromFile('authentication/api_administrator.yml');
$this->loadFixturesFromFile('resources/countries.yml');
$customers = $this->loadFixturesFromFile('resources/customers.yml');
$orders = $this->loadFixturesFromFile('resources/checkout.yml');
$checkoutData = $this->loadFixturesFromFile('resources/checkout.yml');
$data =
<<<EOT
@ -105,7 +105,7 @@ EOT;
}
EOT;
$url = sprintf('/api/checkouts/addressing/%d/%d', $orders['order1']->getId(), $customers['customer_Oliver']->getId());
$url = sprintf('/api/checkouts/addressing/%d/%d', $checkoutData['order1']->getId(), $customers['customer_Oliver']->getId());
$this->client->request('PUT', $url, [], [], static::$authorizedHeaderWithContentType, $data);
$response = $this->client->getResponse();
@ -120,7 +120,7 @@ EOT;
$this->loadFixturesFromFile('authentication/api_administrator.yml');
$this->loadFixturesFromFile('resources/countries.yml');
$customers = $this->loadFixturesFromFile('resources/customers.yml');
$orders = $this->loadFixturesFromFile('resources/checkout.yml');
$checkoutData = $this->loadFixturesFromFile('resources/checkout.yml');
$data =
<<<EOT
@ -137,7 +137,7 @@ EOT;
}
EOT;
$url = sprintf('/api/checkouts/addressing/%d/%d', $orders['order1']->getId(), $customers['customer_Oliver']->getId());
$url = sprintf('/api/checkouts/addressing/%d/%d', $checkoutData['order1']->getId(), $customers['customer_Oliver']->getId());
$this->client->request('PUT', $url, [], [], static::$authorizedHeaderWithContentType, $data);
$response = $this->client->getResponse();
@ -152,7 +152,7 @@ EOT;
$this->loadFixturesFromFile('authentication/api_administrator.yml');
$this->loadFixturesFromFile('resources/countries.yml');
$customers = $this->loadFixturesFromFile('resources/customers.yml');
$orders = $this->loadFixturesFromFile('resources/checkout.yml');
$checkoutData = $this->loadFixturesFromFile('resources/checkout.yml');
$data =
<<<EOT
@ -177,10 +177,15 @@ EOT;
}
EOT;
$url = sprintf('/api/checkouts/addressing/%d/%d', $orders['order1']->getId(), $customers['customer_Oliver']->getId());
$url = sprintf('/api/checkouts/addressing/%d/%d', $checkoutData['order1']->getId(), $customers['customer_Oliver']->getId());
$this->client->request('PUT', $url, [], [], static::$authorizedHeaderWithContentType, $data);
$response = $this->client->getResponse();
$this->assertResponseCode($response, Response::HTTP_NO_CONTENT);
$this->client->request('GET', sprintf('/api/checkouts/%d', $checkoutData['order1']->getId()), [], [], static::$authorizedHeaderWithAccept);
$response = $this->client->getResponse();
$this->assertResponse($response, 'checkout/addressed_order_response');
}
}

View file

@ -26,6 +26,14 @@ class CheckoutApiTestCase extends JsonApiTestCase
'CONTENT_TYPE' => 'application/json',
];
/**
* @var array
*/
protected static $authorizedHeaderWithAccept = [
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ',
'ACCEPT' => 'application/json',
];
/**
* @param int $orderId
*/

View file

@ -79,5 +79,10 @@ final class CheckoutCompleteApiTest extends CheckoutApiTestCase
$response = $this->client->getResponse();
$this->assertResponseCode($response, Response::HTTP_NO_CONTENT);
$this->client->request('GET', sprintf('/api/checkouts/%d', $checkoutData['order1']->getId()), [], [], static::$authorizedHeaderWithAccept);
$response = $this->client->getResponse();
$this->assertResponse($response, 'checkout/completed_order_response');
}
}

View file

@ -120,5 +120,10 @@ EOT;
$response = $this->client->getResponse();
$this->assertResponseCode($response, Response::HTTP_NO_CONTENT);
$this->client->request('GET', sprintf('/api/checkouts/%d', $checkoutData['order1']->getId()), [], [], static::$authorizedHeaderWithAccept);
$response = $this->client->getResponse();
$this->assertResponse($response, 'checkout/payment_selected_order_response');
}
}

View file

@ -122,7 +122,11 @@ EOT;
$this->client->request('PUT', $url, [], [], static::$authorizedHeaderWithContentType, $data);
$response = $this->client->getResponse();
$this->assertResponseCode($response, Response::HTTP_NO_CONTENT);
$this->client->request('GET', sprintf('/api/checkouts/%d', $checkoutData['order1']->getId()), [], [], static::$authorizedHeaderWithAccept);
$response = $this->client->getResponse();
$this->assertResponse($response, 'checkout/shipping_selected_order_response');
}
}

View file

@ -3,6 +3,7 @@ Sylius\Component\Core\Model\Order:
channel: @channel
currencyCode: "EUR"
addItem: [@orderItem1]
localeCode: "en_US"
Sylius\Component\Core\Model\OrderItem:
orderItem1:

View file

@ -0,0 +1,55 @@
{
"id": @integer@,
"items": @array@,
"items_total": @integer@,
"adjustments": @array@,
"comments": [],
"adjustments_total": @integer@,
"total": @integer@,
"state": "cart",
"created_at": "@string@.isDateTime()",
"updated_at": "@string@.isDateTime()",
"expires_at": "@string@.isDateTime()",
"channel": {
"id": @integer@,
"code": "CHANNEL",
"name": "Channel",
"description": "Lorem ipsum",
"hostname": "localhost",
"color": "black",
"created_at": "@string@.isDateTime()",
"updated_at": "@string@.isDateTime()",
"enabled": true,
"tax_calculation_strategy": "order_items_based",
"_links": {
"self": {
"href": @string@
}
}
},
"shipping_address": {
"id": @integer@,
"first_name": "Hieronim",
"last_name": "Bosch",
"country_code": "NL",
"street": "Surrealism St.",
"city": "s-Hertogenbosch",
"postcode": "99-999",
"created_at": "@string@.isDateTime()",
"updated_at": "@string@.isDateTime()"
},
"billing_address": {
"id": @integer@,
"first_name": "Vincent",
"last_name": "van Gogh",
"country_code": "NL",
"street": "Post-Impressionism St.",
"city": "Groot Zundert",
"postcode": "88-888",
"created_at": "@string@.isDateTime()",
"updated_at": "@string@.isDateTime()"
},
"payments": @array@,
"shipments": @array@,
"checkout_state": "addressed"
}

View file

@ -0,0 +1,37 @@
{
"id": @integer@,
"completed_at": "@string@.isDateTime()",
"number": @string@,
"items": @array@,
"items_total": @integer@,
"adjustments": @array@,
"comments": [],
"adjustments_total": @integer@,
"total": @integer@,
"state": "new",
"created_at": "@string@.isDateTime()",
"updated_at": "@string@.isDateTime()",
"expires_at": "@string@.isDateTime()",
"channel": {
"id": @integer@,
"code": "CHANNEL",
"name": "Channel",
"description": "Lorem ipsum",
"hostname": "localhost",
"color": "black",
"created_at": "@string@.isDateTime()",
"updated_at": "@string@.isDateTime()",
"enabled": true,
"tax_calculation_strategy": "order_items_based",
"_links": {
"self": {
"href": @string@
}
}
},
"shipping_address": @...@,
"billing_address": @...@,
"payments": @array@,
"shipments": @array@,
"checkout_state": "completed"
}

View file

@ -0,0 +1,65 @@
{
"id": @integer@,
"items": @array@,
"items_total": @integer@,
"adjustments": @array@,
"comments": [],
"adjustments_total": @integer@,
"total": @integer@,
"state": "cart",
"created_at": "@string@.isDateTime()",
"updated_at": "@string@.isDateTime()",
"expires_at": "@string@.isDateTime()",
"channel": {
"id": @integer@,
"code": "CHANNEL",
"name": "Channel",
"description": "Lorem ipsum",
"hostname": "localhost",
"color": "black",
"created_at": "@string@.isDateTime()",
"updated_at": "@string@.isDateTime()",
"enabled": true,
"tax_calculation_strategy": "order_items_based",
"_links": {
"self": {
"href": @string@
}
}
},
"shipping_address": @...@,
"billing_address": @...@,
"payments": [
{
"id": @integer@,
"method": {
"id": @integer@,
"code": "Cash on delivery",
"created_at": "@string@.isDateTime()",
"updated_at": "@string@.isDateTime()",
"_links": {
"self": {
"href": @string@
}
}
},
"amount": @integer@,
"state": "new",
"created_at": "@string@.isDateTime()",
"updated_at": "@string@.isDateTime()",
"_links": {
"self": {
"href": @string@
},
"payment-method": {
"href": @string@
},
"order": {
"href": @string@
}
}
}
],
"shipments": @array@,
"checkout_state": "payment_selected"
}

View file

@ -0,0 +1,73 @@
{
"id": @integer@,
"items": @array@,
"items_total": @integer@,
"adjustments": @array@,
"comments": [],
"adjustments_total": @integer@,
"total": @integer@,
"state": "cart",
"created_at": "@string@.isDateTime()",
"updated_at": "@string@.isDateTime()",
"expires_at": "@string@.isDateTime()",
"channel": {
"id": @integer@,
"code": "CHANNEL",
"name": "Channel",
"description": "Lorem ipsum",
"hostname": "localhost",
"color": "black",
"created_at": "@string@.isDateTime()",
"updated_at": "@string@.isDateTime()",
"enabled": true,
"tax_calculation_strategy": "order_items_based",
"_links": {
"self": {
"href": @string@
}
}
},
"shipping_address": @...@,
"billing_address": @...@,
"payments": @array@,
"shipments": [
{
"id": @integer@,
"state": "cart",
"method": {
"id": @integer@,
"code": "UPS",
"category_requirement": @integer@,
"calculator": "flat_rate",
"configuration": {
"amount": 10
},
"created_at": "@string@.isDateTime()",
"updated_at": "@string@.isDateTime()",
"enabled": true,
"_links": {
"self": {
"href": @string@
},
"zone": {
"href": @string@
}
}
},
"created_at": "@string@.isDateTime()",
"updated_at": "@string@.isDateTime()",
"_links": {
"self": {
"href": @string@
},
"method": {
"href": @string@
},
"order": {
"href": @string@
}
}
}
],
"checkout_state": "shipping_selected"
}