mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-05 20:57:12 +00:00
[Unit] Add tests for shipping address of placed order
This commit is contained in:
parent
9b18a5bc67
commit
09e626608b
10 changed files with 313 additions and 26 deletions
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Api\Admin;
|
||||
namespace Sylius\Tests\Api\Admin;
|
||||
|
||||
use Sylius\Component\Core\Model\CustomerInterface;
|
||||
use Sylius\Component\Customer\Model\CustomerGroupInterface;
|
||||
|
|
|
|||
|
|
@ -72,15 +72,49 @@ final class OrdersTest extends JsonApiTestCase
|
|||
}
|
||||
|
||||
/** @test */
|
||||
public function it_updates_an_order_billing_address(): void
|
||||
public function it_gets_a_billing_address_of_placed_order(): void
|
||||
{
|
||||
$fixtures = $this->loadFixturesFromFiles([
|
||||
'authentication/api_administrator.yaml',
|
||||
'channel.yaml',
|
||||
'customer.yaml',
|
||||
'customer_order.yaml',
|
||||
'order/order.yaml',
|
||||
'order/customer.yaml',
|
||||
]);
|
||||
|
||||
$headers = $this
|
||||
->headerBuilder()
|
||||
->withJsonLdAccept()
|
||||
->withAdminUserAuthorization('api@example.com')
|
||||
->build()
|
||||
;
|
||||
|
||||
/** @var AddressInterface $billingAddress */
|
||||
$billingAddress = $fixtures['billing_address'];
|
||||
|
||||
$this->client->request(
|
||||
method: 'GET',
|
||||
uri: '/api/v2/admin/addresses/' . $billingAddress->getId(),
|
||||
server: $headers,
|
||||
);
|
||||
|
||||
$this->assertResponse(
|
||||
$this->client->getResponse(),
|
||||
'admin/order/get_billing_address_of_placed_order_response',
|
||||
Response::HTTP_OK,
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_updates_a_billing_address_of_placed_order(): void
|
||||
{
|
||||
$fixtures = $this->loadFixturesFromFiles([
|
||||
'authentication/api_administrator.yaml',
|
||||
'channel.yaml',
|
||||
'order/customer.yaml',
|
||||
'order/order.yaml',
|
||||
]);
|
||||
|
||||
|
||||
$headers = $this
|
||||
->headerBuilder()
|
||||
->withJsonLdAccept()
|
||||
|
|
@ -97,32 +131,34 @@ final class OrdersTest extends JsonApiTestCase
|
|||
uri: '/api/v2/admin/addresses/' . $billingAddress->getId(),
|
||||
server: $headers,
|
||||
content: json_encode([
|
||||
'firstName' => 'Adam',
|
||||
'lastName' => 'Handley',
|
||||
'company'=> 'FMŻ',
|
||||
'street' => 'Kościuszki 21',
|
||||
'countryCode' => 'FR',
|
||||
'city' => 'Bordeaux',
|
||||
'postcode' => '99-999',
|
||||
'phoneNumber' => '911213969',
|
||||
'firstName' => 'Updated: Adam',
|
||||
'lastName' => 'Updated: Handley',
|
||||
'company'=> 'Updated: FMŻ',
|
||||
'street' => 'Updated: Kościuszki 21',
|
||||
'countryCode' => 'Updated: FR',
|
||||
'city' => 'Updated: Bordeaux',
|
||||
'postcode' => 'Updated: 99-999',
|
||||
'phoneNumber' => 'Updated: 911213969',
|
||||
'provinceCode' => 'Updated: PL-WP',
|
||||
'provinceName' => 'Updated: wielkopolskie'
|
||||
]),
|
||||
);
|
||||
|
||||
$this->assertResponse(
|
||||
$this->client->getResponse(),
|
||||
'admin/order/get_order_billing_data_response',
|
||||
'admin/order/put_billing_address_of_placed_order_response',
|
||||
Response::HTTP_OK,
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_does_not_allow_to_update_customer_of_already_placed_order(): void
|
||||
public function it_prevents_customer_update_in_billing_address_of_placed_order(): void
|
||||
{
|
||||
$fixtures = $this->loadFixturesFromFiles([
|
||||
'authentication/api_administrator.yaml',
|
||||
'channel.yaml',
|
||||
'customer.yaml',
|
||||
'customer_order.yaml',
|
||||
'order/order.yaml',
|
||||
'order/customer.yaml',
|
||||
]);
|
||||
|
||||
$headers = $this
|
||||
|
|
@ -164,4 +200,133 @@ final class OrdersTest extends JsonApiTestCase
|
|||
json_decode($this->client->getResponse()->getContent())->customer
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_gets_a_shipping_address_of_placed_order(): void
|
||||
{
|
||||
$fixtures = $this->loadFixturesFromFiles([
|
||||
'authentication/api_administrator.yaml',
|
||||
'channel.yaml',
|
||||
'order/customer.yaml',
|
||||
'order/order.yaml',
|
||||
]);
|
||||
|
||||
$headers = $this
|
||||
->headerBuilder()
|
||||
->withJsonLdAccept()
|
||||
->withAdminUserAuthorization('api@example.com')
|
||||
->build()
|
||||
;
|
||||
|
||||
/** @var AddressInterface $shippingAddress */
|
||||
$shippingAddress = $fixtures['shipping_address'];
|
||||
|
||||
$this->client->request(
|
||||
method: 'GET',
|
||||
uri: '/api/v2/admin/addresses/' . $shippingAddress->getId(),
|
||||
server: $headers,
|
||||
);
|
||||
|
||||
$this->assertResponse(
|
||||
$this->client->getResponse(),
|
||||
'admin/order/get_shipping_address_of_placed_order_response',
|
||||
Response::HTTP_OK,
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_updated_a_shipping_address_of_placed_order(): void
|
||||
{
|
||||
$fixtures = $this->loadFixturesFromFiles([
|
||||
'authentication/api_administrator.yaml',
|
||||
'channel.yaml',
|
||||
'order/customer.yaml',
|
||||
'order/order.yaml',
|
||||
]);
|
||||
|
||||
$headers = $this
|
||||
->headerBuilder()
|
||||
->withJsonLdAccept()
|
||||
->withJsonLdContentType()
|
||||
->withAdminUserAuthorization('api@example.com')
|
||||
->build()
|
||||
;
|
||||
|
||||
/** @var AddressInterface $shippingAddress */
|
||||
$shippingAddress = $fixtures['shipping_address'];
|
||||
|
||||
$this->client->request(
|
||||
method: 'PUT',
|
||||
uri: '/api/v2/admin/addresses/' . $shippingAddress->getId(),
|
||||
server: $headers,
|
||||
content: json_encode([
|
||||
'firstName' => 'Updated: Julia',
|
||||
'lastName' => 'Updated: Kowalska',
|
||||
'company' => 'Updated: Błysk',
|
||||
'street' => 'Updated: Marszałkowska 10',
|
||||
'countryCode' => 'Updated: PL',
|
||||
'city' => 'Updated: Warszawa',
|
||||
'postcode' => 'Updated: 00-001',
|
||||
'phoneNumber' => 'Updated: 48222333444',
|
||||
'provinceCode' => 'Updated: PL-MA',
|
||||
'provinceName' => 'Updated: mazowieckie'
|
||||
]),
|
||||
);
|
||||
|
||||
$this->assertResponse(
|
||||
$this->client->getResponse(),
|
||||
'admin/order/put_shipping_address_of_placed_order_response',
|
||||
Response::HTTP_OK,
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_prevents_customer_update_in_shipping_address_of_placed_order(): void
|
||||
{
|
||||
$fixtures = $this->loadFixturesFromFiles([
|
||||
'authentication/api_administrator.yaml',
|
||||
'channel.yaml',
|
||||
'order/customer.yaml',
|
||||
'order/order.yaml',
|
||||
]);
|
||||
|
||||
$headers = $this
|
||||
->headerBuilder()
|
||||
->withJsonLdAccept()
|
||||
->withJsonLdContentType()
|
||||
->withAdminUserAuthorization('api@example.com')
|
||||
->build()
|
||||
;
|
||||
|
||||
/** @var AddressInterface $shippingAddress */
|
||||
$shippingAddress = $fixtures['shipping_address'];
|
||||
|
||||
/** @var CustomerInterface $customerTony */
|
||||
$customerTony = $fixtures['customer_tony'];
|
||||
|
||||
/** @var CustomerInterface $customerDave */
|
||||
$customerDave = $fixtures['customer_dave'];
|
||||
|
||||
$this->client->request(
|
||||
method: 'PUT',
|
||||
uri: '/api/v2/admin/addresses/' . $shippingAddress->getId(),
|
||||
server: $headers,
|
||||
content: json_encode([
|
||||
'customer' => '/api/v2/admin/customers/' . $customerDave->getId(),
|
||||
]),
|
||||
);
|
||||
|
||||
$this->assertResponseCode($this->client->getResponse(), Response::HTTP_OK);
|
||||
|
||||
$this->client->request(
|
||||
method: 'GET',
|
||||
uri: '/api/v2/admin/addresses/' . $shippingAddress->getId(),
|
||||
server: $headers,
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
'/api/v2/admin/customers/' . $customerTony->getId(),
|
||||
json_decode($this->client->getResponse()->getContent())->customer
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,13 +7,26 @@ Sylius\Component\Core\Model\Order:
|
|||
tokenValue: "token"
|
||||
customer: "@customer_tony"
|
||||
billingAddress: "@billing_address"
|
||||
shippingAddress: "@shipping_address"
|
||||
|
||||
Sylius\Component\Core\Model\Address:
|
||||
billing_address:
|
||||
customer: "@customer_tony"
|
||||
firstName: "Andrzej"
|
||||
lastName: "Legs"
|
||||
company: "Polmotors"
|
||||
company: "Polmotors office"
|
||||
street: "Moniuszki 16/20"
|
||||
countryCode: "PL"
|
||||
city: "Pabianice"
|
||||
postcode: "31-999"
|
||||
phoneNumber: "111999222"
|
||||
provinceCode: "PL-PL"
|
||||
provinceName: "kujawsko-pomorskie"
|
||||
shipping_address:
|
||||
customer: "@customer_tony"
|
||||
firstName: "Andrzej"
|
||||
lastName: "Legs"
|
||||
company: "Polmotors manufactory"
|
||||
street: "Moniuszki 16/20"
|
||||
countryCode: "PL"
|
||||
city: "Pabianice"
|
||||
|
|
|
|||
7
tests/Api/DataFixtures/ORM/order/customer.yaml
Normal file
7
tests/Api/DataFixtures/ORM/order/customer.yaml
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
Sylius\Component\Core\Model\Customer:
|
||||
customer_{tony, dave}:
|
||||
firstName: "<current()>"
|
||||
lastName: "Doe"
|
||||
email: "<current()>\\@doe.com"
|
||||
emailCanonical: "<current()>\\@doe.com"
|
||||
birthday: "<(new \\DateTime())>"
|
||||
38
tests/Api/DataFixtures/ORM/order/order.yaml
Normal file
38
tests/Api/DataFixtures/ORM/order/order.yaml
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
Sylius\Component\Core\Model\Order:
|
||||
order:
|
||||
channel: "@channel_web"
|
||||
currencyCode: "USD"
|
||||
localeCode: "en_US"
|
||||
state: "new"
|
||||
tokenValue: "token"
|
||||
customer: "@customer_tony"
|
||||
billingAddress: "@billing_address"
|
||||
shippingAddress: "@shipping_address"
|
||||
|
||||
Sylius\Component\Core\Model\Address:
|
||||
billing_address:
|
||||
customer: "@customer_tony"
|
||||
firstName: "Andrzej"
|
||||
lastName: "Legs"
|
||||
company: "Polmotors office"
|
||||
street: "Moniuszki 16/20"
|
||||
countryCode: "PL"
|
||||
city: "Pabianice"
|
||||
postcode: "31-999"
|
||||
phoneNumber: "111999222"
|
||||
provinceCode: "PL-PL"
|
||||
provinceName: "kujawsko-pomorskie"
|
||||
|
||||
shipping_address:
|
||||
customer: "@customer_tony"
|
||||
firstName: "Andrzej"
|
||||
lastName: "Legs"
|
||||
company: "Polmotors manufactory"
|
||||
street: "Moniuszki 16/20"
|
||||
countryCode: "PL"
|
||||
city: "Pabianice"
|
||||
postcode: "31-999"
|
||||
phoneNumber: "111999222"
|
||||
provinceCode: "PL-PL"
|
||||
provinceName: "kujawsko-pomorskie"
|
||||
|
||||
|
|
@ -4,14 +4,14 @@
|
|||
"@type": "Address",
|
||||
"customer": "\/api\/v2\/admin\/customers\/@integer@",
|
||||
"id": "@integer@",
|
||||
"firstName": "Adam",
|
||||
"lastName": "Handley",
|
||||
"company": "FMŻ",
|
||||
"street": "Kościuszki 21",
|
||||
"countryCode": "FR",
|
||||
"city": "Bordeaux",
|
||||
"postcode": "99-999",
|
||||
"phoneNumber": "911213969",
|
||||
"firstName": "Andrzej",
|
||||
"lastName": "Legs",
|
||||
"company": "Polmotors office",
|
||||
"street": "Moniuszki 16/20",
|
||||
"countryCode": "PL",
|
||||
"city": "Pabianice",
|
||||
"postcode": "31-999",
|
||||
"phoneNumber": "111999222",
|
||||
"provinceCode": "PL-PL",
|
||||
"provinceName": "kujawsko-pomorskie"
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"@id": "\/api\/v2\/admin\/addresses\/@integer@",
|
||||
"@context": "\/api\/v2\/contexts\/Address",
|
||||
"@type": "Address",
|
||||
"customer": "\/api\/v2\/admin\/customers\/@integer@",
|
||||
"id": "@integer@",
|
||||
"firstName": "Andrzej",
|
||||
"lastName": "Legs",
|
||||
"company": "Polmotors manufactory",
|
||||
"street": "Moniuszki 16/20",
|
||||
"countryCode": "PL",
|
||||
"city": "Pabianice",
|
||||
"postcode": "31-999",
|
||||
"phoneNumber": "111999222",
|
||||
"provinceCode": "PL-PL",
|
||||
"provinceName": "kujawsko-pomorskie"
|
||||
}
|
||||
|
|
@ -14,7 +14,20 @@
|
|||
"firstName": "Andrzej",
|
||||
"lastName": "Legs",
|
||||
"phoneNumber": "111999222",
|
||||
"company": "Polmotors",
|
||||
"company": "Polmotors office",
|
||||
"countryCode": "PL",
|
||||
"provinceName": "kujawsko-pomorskie",
|
||||
"street": "Moniuszki 16\/20",
|
||||
"city": "Pabianice",
|
||||
"postcode": "31-999"
|
||||
},
|
||||
"shippingAddress": {
|
||||
"@id": "\/api\/v2\/admin\/addresses\/@integer@",
|
||||
"@type": "Address",
|
||||
"firstName": "Andrzej",
|
||||
"lastName": "Legs",
|
||||
"phoneNumber": "111999222",
|
||||
"company": "Polmotors manufactory",
|
||||
"countryCode": "PL",
|
||||
"provinceName": "kujawsko-pomorskie",
|
||||
"street": "Moniuszki 16\/20",
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"@id": "\/api\/v2\/admin\/addresses\/@integer@",
|
||||
"@context": "\/api\/v2\/contexts\/Address",
|
||||
"@type": "Address",
|
||||
"customer": "\/api\/v2\/admin\/customers\/@integer@",
|
||||
"id": "@integer@",
|
||||
"firstName": "Updated: Adam",
|
||||
"lastName": "Updated: Handley",
|
||||
"company": "Updated: FMŻ",
|
||||
"street": "Updated: Kościuszki 21",
|
||||
"countryCode": "Updated: FR",
|
||||
"city": "Updated: Bordeaux",
|
||||
"postcode": "Updated: 99-999",
|
||||
"phoneNumber": "Updated: 911213969",
|
||||
"provinceCode": "Updated: PL-WP",
|
||||
"provinceName": "Updated: wielkopolskie"
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"@id": "\/api\/v2\/admin\/addresses\/@integer@",
|
||||
"@context": "\/api\/v2\/contexts\/Address",
|
||||
"@type": "Address",
|
||||
"customer": "\/api\/v2\/admin\/customers\/@integer@",
|
||||
"id": "@integer@",
|
||||
"firstName": "Updated: Julia",
|
||||
"lastName": "Updated: Kowalska",
|
||||
"company": "Updated: Błysk",
|
||||
"street": "Updated: Marszałkowska 10",
|
||||
"countryCode": "Updated: PL",
|
||||
"city": "Updated: Warszawa",
|
||||
"postcode": "Updated: 00-001",
|
||||
"phoneNumber": "Updated: 48222333444",
|
||||
"provinceCode": "Updated: PL-MA",
|
||||
"provinceName": "Updated: mazowieckie"
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue