minor #15865 [API][Shop] Minor clean up of address contract tests (GSadee)

This PR was merged into the 1.13 branch.

Discussion
----------

| Q               | A                                                            |
|-----------------|--------------------------------------------------------------|
| Branch?         | 1.13|
| Bug fix?        | no                                                      |
| New feature?    | no                                                      |
| BC breaks?      | no                                                      |
| Deprecations?   | no<!-- don't forget to update the UPGRADE-*.md file --> |
| Related tickets | |
| License         | MIT                                                          |

<!--
 - Bug fixes must be submitted against the 1.12 branch
 - Features and deprecations must be submitted against the 1.13 branch
 - Make sure that the correct base branch is set

 To be sure you are not breaking any Backward Compatibilities, check the documentation:
 https://docs.sylius.com/en/latest/book/organization/backward-compatibility-promise.html
-->


Commits
-------
  [API][Shop] Minor clean up of address contract tests
  [API][Admin] Fix address contract tests
This commit is contained in:
Karol 2024-02-23 08:21:24 +01:00 committed by GitHub
commit 38ecc8b2e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 125 additions and 145 deletions

View file

@ -9,8 +9,6 @@ Sylius\Component\Core\Model\Address:
city: "New York"
postcode: "00000"
phoneNumber: "123456789"
provinceCode: "999"
provinceName: "east"
Sylius\Component\Core\Model\ShopUser:
shop_user_{tony}:

View file

@ -9,8 +9,8 @@
"phoneNumber": "123456789",
"company": "CocaCola",
"countryCode": "US",
"provinceCode": "999",
"provinceName": "east",
"provinceCode": null,
"provinceName": null,
"street": "Green Avenue",
"city": "New York",
"postcode": "00000"

View file

@ -16,8 +16,8 @@
"city": "New York",
"postcode": "00000",
"countryCode": "US",
"provinceCode": "999",
"provinceName": "east"
"provinceCode": null,
"provinceName": null
},
"logged_at": @date@
}

View file

@ -1,16 +0,0 @@
{
"@context": "\/api\/v2\/contexts\/Address",
"@id": "\/api\/v2\/shop\/addresses\/@integer@",
"@type": "Address",
"id": "@integer@",
"firstName":"TEST",
"lastName":"TEST",
"phoneNumber":"666111333",
"company":"Potato Corp.",
"countryCode":"US",
"provinceCode":"US-MI",
"provinceName":null,
"street":"Top secret",
"city":"Nebraska",
"postcode":"12343"
}

View file

@ -1,16 +0,0 @@
{
"@context": "\/api\/v2\/contexts\/Address",
"@id": "\/api\/v2\/shop\/addresses\/@integer@",
"@type": "Address",
"id": "@integer@",
"firstName":"TEST",
"lastName":"TEST",
"phoneNumber":"666111333",
"company":"Potato Corp.",
"countryCode":"DE",
"provinceCode":null,
"provinceName":"Munich",
"street":"Top secret",
"city":"Nebraska",
"postcode":"12343"
}

View file

@ -1,16 +0,0 @@
{
"@context": "\/api\/v2\/contexts\/Address",
"@id": "\/api\/v2\/shop\/addresses\/@integer@",
"@type": "Address",
"id": "@integer@",
"firstName":"TEST",
"lastName":"TEST",
"phoneNumber":"666111333",
"company":"Potato Corp.",
"countryCode":"DE",
"provinceCode":null,
"provinceName":null,
"street":"Top secret",
"city":"Nebraska",
"postcode":"12343"
}

View file

@ -8,8 +8,8 @@
"phoneNumber": "123456789",
"company": "CocaCola",
"countryCode": "US",
"provinceCode": "999",
"provinceName": "east",
"provinceCode": null,
"provinceName": null,
"street": "Green Avenue",
"city": "New York",
"postcode": "00000"

View file

@ -12,8 +12,8 @@
"phoneNumber": "123456789",
"company": "CocaCola",
"countryCode": "US",
"provinceCode": "999",
"provinceName": "east",
"provinceCode": null,
"provinceName": null,
"street": "Green Avenue",
"city": "New York",
"postcode": "00000"

View file

@ -0,0 +1,16 @@
{
"@context": "\/api\/v2\/contexts\/Address",
"@id": "\/api\/v2\/shop\/addresses\/@integer@",
"@type": "Address",
"id": "@integer@",
"firstName": "TEST",
"lastName": "TEST",
"phoneNumber": "666111333",
"company": "Potato Corp.",
"countryCode": "US",
"provinceCode": "US-MI",
"provinceName": null,
"street": "Top secret",
"city": "Nebraska",
"postcode": "12343"
}

View file

@ -0,0 +1,16 @@
{
"@context": "\/api\/v2\/contexts\/Address",
"@id": "\/api\/v2\/shop\/addresses\/@integer@",
"@type": "Address",
"id": "@integer@",
"firstName": "TEST",
"lastName": "TEST",
"phoneNumber": "666111333",
"company": "Potato Corp.",
"countryCode": "DE",
"provinceCode": null,
"provinceName": "Munich",
"street": "Top secret",
"city": "Nebraska",
"postcode": "12343"
}

View file

@ -0,0 +1,16 @@
{
"@context": "\/api\/v2\/contexts\/Address",
"@id": "\/api\/v2\/shop\/addresses\/@integer@",
"@type": "Address",
"id": "@integer@",
"firstName": "TEST",
"lastName": "TEST",
"phoneNumber": "666111333",
"company": "Potato Corp.",
"countryCode": "DE",
"provinceCode": null,
"provinceName": null,
"street": "Top secret",
"city": "Nebraska",
"postcode": "12343"
}

View file

@ -8,8 +8,8 @@
"phoneNumber": "123456789",
"company": "Stark Industries",
"countryCode": "US",
"provinceCode": "999",
"provinceName": "east",
"provinceCode": "US-WY",
"provinceName": null,
"street": "10880 Malibu Point",
"city": "Malibu",
"postcode": "90265"

View file

@ -1,66 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Sylius\Tests\Api\Shop;
use Sylius\Component\Core\Model\AddressInterface;
use Sylius\Component\Core\Model\CustomerInterface;
use Sylius\Tests\Api\JsonApiTestCase;
use Sylius\Tests\Api\Utils\ShopUserLoginTrait;
use Symfony\Component\HttpFoundation\Response;
final class AddressesGetTest extends JsonApiTestCase
{
use ShopUserLoginTrait;
/** @test */
public function it_denies_access_to_get_address_list_for_not_authenticated_user(): void
{
$this->loadFixturesFromFiles(['authentication/customer.yaml']);
$this->client->request(method: 'GET', uri: '/api/v2/shop/addresses', server: self::CONTENT_TYPE_HEADER);
$response = $this->client->getResponse();
$this->assertSame(Response::HTTP_UNAUTHORIZED, $response->getStatusCode());
}
/** @test */
public function it_returns_address_list_of_an_authorized_user(): void
{
$fixtures = $this->loadFixturesFromFiles(['address_with_customer.yaml']);
/** @var CustomerInterface $customer */
$customer = $fixtures['customer_tony'];
$header = array_merge($this->logInShopUser($customer->getEmailCanonical()), self::CONTENT_TYPE_HEADER);
$this->client->request(method: 'GET', uri: '/api/v2/shop/addresses', server: $header);
$this->assertResponse($this->client->getResponse(), 'shop/address/get_addresses_response');
}
/** @test */
public function it_returns_an_address_of_the_authorized_user(): void
{
$fixtures = $this->loadFixturesFromFiles(['address_with_customer.yaml']);
/** @var CustomerInterface $customer */
$customer = $fixtures['customer_tony'];
/** @var AddressInterface $address */
$address = $fixtures['address'];
$header = array_merge($this->logInShopUser($customer->getEmailCanonical()), self::CONTENT_TYPE_HEADER);
$this->client->request(method: 'GET', uri: '/api/v2/shop/addresses/' . $address->getId(), server: $header);
$this->assertResponse($this->client->getResponse(), 'shop/address/get_an_address_response');
}
}

View file

@ -21,12 +21,61 @@ use Sylius\Tests\Api\JsonApiTestCase;
use Sylius\Tests\Api\Utils\ShopUserLoginTrait;
use Symfony\Component\HttpFoundation\Response;
final class AddressesPostTest extends JsonApiTestCase
final class AddressesTest extends JsonApiTestCase
{
use ShopUserLoginTrait;
/** @test */
public function it_denies_access_to_a_create_an_address_for_not_authenticated_user(): void
public function it_denies_access_to_get_addresses_for_not_authenticated_user(): void
{
$this->loadFixturesFromFiles(['authentication/customer.yaml']);
$this->client->request(method: 'GET', uri: '/api/v2/shop/addresses', server: self::CONTENT_TYPE_HEADER);
$response = $this->client->getResponse();
$this->assertSame(Response::HTTP_UNAUTHORIZED, $response->getStatusCode());
}
/** @test */
public function it_gets_addresses(): void
{
$fixtures = $this->loadFixturesFromFiles(['address_with_customer.yaml']);
/** @var CustomerInterface $customer */
$customer = $fixtures['customer_tony'];
$header = array_merge($this->logInShopUser($customer->getEmailCanonical()), self::CONTENT_TYPE_HEADER);
$this->client->request(method: 'GET', uri: '/api/v2/shop/addresses', server: $header);
$this->assertResponse(
$this->client->getResponse(),
'shop/address/get_addresses_response',
Response::HTTP_OK,
);
}
/** @test */
public function it_gets_an_address(): void
{
$fixtures = $this->loadFixturesFromFiles(['address_with_customer.yaml']);
/** @var CustomerInterface $customer */
$customer = $fixtures['customer_tony'];
/** @var AddressInterface $address */
$address = $fixtures['address'];
$header = array_merge($this->logInShopUser($customer->getEmailCanonical()), self::CONTENT_TYPE_HEADER);
$this->client->request(method: 'GET', uri: '/api/v2/shop/addresses/' . $address->getId(), server: $header);
$this->assertResponse(
$this->client->getResponse(),
'shop/address/get_address_response',
Response::HTTP_OK,
);
}
/** @test */
public function it_denies_access_to_create_an_address_for_not_authenticated_user(): void
{
$fixtures = $this->loadFixturesFromFiles(['authentication/customer.yaml', 'country.yaml']);
/** @var CountryInterface $country */
@ -46,7 +95,7 @@ final class AddressesPostTest extends JsonApiTestCase
}
/** @test */
public function it_creates_new_address_for_logged_customer_with_country_with_provinces(): void
public function it_creates_a_new_address_with_country_and_province_code(): void
{
$fixtures = $this->loadFixturesFromFiles(['authentication/customer.yaml', 'country.yaml']);
/** @var CustomerInterface $customer */
@ -67,17 +116,15 @@ final class AddressesPostTest extends JsonApiTestCase
content: json_encode($bodyRequest, \JSON_THROW_ON_ERROR),
);
$response = $this->client->getResponse();
$this->assertResponse(
$response,
'shop/address/create_address_with_province_code_response',
$this->client->getResponse(),
'shop/address/post_address_with_province_code_response',
Response::HTTP_CREATED,
);
}
/** @test */
public function it_creates_new_address_for_logged_customer_without_province(): void
public function it_creates_a_new_address_with_country_and_province_name(): void
{
$fixtures = $this->loadFixturesFromFiles(['authentication/customer.yaml', 'country.yaml']);
/** @var CustomerInterface $customer */
@ -96,17 +143,15 @@ final class AddressesPostTest extends JsonApiTestCase
content: json_encode($bodyRequest, \JSON_THROW_ON_ERROR),
);
$response = $this->client->getResponse();
$this->assertResponse(
$response,
'shop/address/create_address_with_province_name_response',
$this->client->getResponse(),
'shop/address/post_address_with_province_name_response',
Response::HTTP_CREATED,
);
}
/** @test */
public function it_creates_new_address_for_logged_customer_with_country_with_custom_provinces(): void
public function it_creates_a_new_address_with_country_without_province_data(): void
{
$fixtures = $this->loadFixturesFromFiles(['authentication/customer.yaml', 'country.yaml']);
/** @var CustomerInterface $customer */
@ -125,17 +170,15 @@ final class AddressesPostTest extends JsonApiTestCase
content: json_encode($bodyRequest, \JSON_THROW_ON_ERROR),
);
$response = $this->client->getResponse();
$this->assertResponse(
$response,
'shop/address/create_address_without_province_response',
$this->client->getResponse(),
'shop/address/post_address_without_province_response',
Response::HTTP_CREATED,
);
}
/** @test */
public function it_updates_an_address_of_the_authorized_user(): void
public function it_updates_an_address(): void
{
$fixtures = $this->loadFixturesFromFiles(['address_with_customer.yaml']);
/** @var CustomerInterface $customer */
@ -154,6 +197,7 @@ final class AddressesPostTest extends JsonApiTestCase
'lastName' => 'Stark',
'company' => 'Stark Industries',
'countryCode' => 'US',
'provinceCode' => 'US-WY',
'street' => '10880 Malibu Point',
'city' => 'Malibu',
'postcode' => '90265',
@ -161,7 +205,11 @@ final class AddressesPostTest extends JsonApiTestCase
]),
);
$this->assertResponse($this->client->getResponse(), 'shop/address/update_an_address_response');
$this->assertResponse(
$this->client->getResponse(),
'shop/address/put_address_response',
Response::HTTP_OK,
);
}
private function createBodyRequest(