diff --git a/UPGRADE.md b/UPGRADE.md index 60e2bed87..d1f11ac2e 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -28,6 +28,7 @@ | Old Route | New route | |:-----------------------------------------|:------------------------------------| | `{channelCode}/address-book/*` | `address-book/*` | + | `{channelCode}/carts/*` | `carts/*` | | `{channelCode}/checkout/*` | `checkout/*` | | `{channelCode}/me` | `me` | | `{channelCode}/orders/*` | `orders/*` | @@ -42,7 +43,9 @@ | `{channelCode}/taxons/*` | `taxons/*` | * The channel code has been added as a second argument to `AddProductReviewByCodeRequest`, -`AddProductReviewBySlugRequest`, `ResendVerificationTokenRequest` and `RegisterCustomerRequest` classes. +`AddProductReviewBySlugRequest`, `ResendVerificationTokenRequest` and `RegisterCustomerRequest` classes. + +* The argument in constructor of `PickupCartRequest` class has been changed from `Request $request `to `string channelCode`. # UPGRADE FROM 1.0.0-beta.17 to 1.0.0-beta.18 diff --git a/doc/swagger.yml b/doc/swagger.yml index 50d0ecf90..acdd0203f 100644 --- a/doc/swagger.yml +++ b/doc/swagger.yml @@ -67,9 +67,7 @@ parameters: type: "string" paths: - /{channelCode}/carts: - parameters: - - $ref: "#/parameters/ChannelCode" + /carts: post: tags: - "cart" @@ -85,9 +83,9 @@ paths: description: "Invalid input" schema: $ref: "#/definitions/GeneralError" - /{channelCode}/carts/{token}: + + /carts/{token}: parameters: - - $ref: "#/parameters/ChannelCode" - $ref: "#/parameters/CartToken" get: tags: @@ -117,9 +115,9 @@ paths: description: "Invalid input (E.g. token has not been found)" schema: $ref: "#/definitions/GeneralError" - /{channelCode}/carts/{token}/items: + + /carts/{token}/items: parameters: - - $ref: "#/parameters/ChannelCode" - $ref: "#/parameters/CartToken" post: tags: @@ -143,9 +141,9 @@ paths: description: "Invalid input, validation failed." schema: $ref: "#/definitions/GeneralError" - /{channelCode}/carts/{token}/multiple-items: + + /carts/{token}/multiple-items: parameters: - - $ref: "#/parameters/ChannelCode" - $ref: "#/parameters/CartToken" post: tags: @@ -169,9 +167,9 @@ paths: description: "Invalid input, validation failed." schema: $ref: "#/definitions/GeneralError" - /{channelCode}/carts/{token}/items/{identifier}: + + /carts/{token}/items/{identifier}: parameters: - - $ref: "#/parameters/ChannelCode" - $ref: "#/parameters/CartToken" - name: "identifier" in: "path" @@ -209,9 +207,9 @@ paths: description: "Invalid input (E.g. token has not been found)" schema: $ref: "#/definitions/GeneralError" - /{channelCode}/carts/{token}/estimated-shipping-cost: + + /carts/{token}/estimated-shipping-cost: parameters: - - $ref: "#/parameters/ChannelCode" - $ref: "#/parameters/CartToken" get: tags: @@ -239,9 +237,8 @@ paths: schema: $ref: "#/definitions/GeneralError" - /{channelCode}/carts/{token}/coupon: + /carts/{token}/coupon: parameters: - - $ref: "#/parameters/ChannelCode" - $ref: "#/parameters/CartToken" put: tags: diff --git a/spec/Normalizer/RequestCartTokenNormalizerSpec.php b/spec/Normalizer/RequestCartTokenNormalizerSpec.php index 6af94ab2d..54279ad81 100644 --- a/spec/Normalizer/RequestCartTokenNormalizerSpec.php +++ b/spec/Normalizer/RequestCartTokenNormalizerSpec.php @@ -6,6 +6,8 @@ use PhpSpec\ObjectBehavior; use Prophecy\Argument; +use Sylius\Component\Channel\Context\ChannelContextInterface; +use Sylius\Component\Core\Model\ChannelInterface; use Sylius\ShopApiPlugin\Command\Cart\PickupCart; use Sylius\ShopApiPlugin\Normalizer\RequestCartTokenNormalizerInterface; use Sylius\ShopApiPlugin\Request\Cart\PickupCartRequest; @@ -18,9 +20,9 @@ final class RequestCartTokenNormalizerSpec extends ObjectBehavior { - function let(ValidatorInterface $validator, MessageBusInterface $bus): void + function let(ValidatorInterface $validator, MessageBusInterface $bus, ChannelContextInterface $channelContext): void { - $this->beConstructedWith($validator, $bus); + $this->beConstructedWith($validator, $bus, $channelContext); } function it_implements_request_cart_token_normalizer_interface(): void @@ -29,45 +31,35 @@ function it_implements_request_cart_token_normalizer_interface(): void } function it_returns_passed_request_if_cart_token_was_set( - Request $request, - ValidatorInterface $validator, - MessageBusInterface $bus - ): void { - $request->attributes = new ParameterBag([ - 'token' => 'sample_cart_token', - 'channelCode' => 'en_GB', - ]); - - $validator->validate(Argument::any())->shouldNotBeCalled(); - $bus->dispatch(Argument::any())->shouldNotBeCalled(); - - $this->doNotAllowNullCartToken($request)->shouldReturn($request); - } - - function it_throws_exception_when_pickup_cart_request_is_not_valid( - Request $request, ValidatorInterface $validator, MessageBusInterface $bus, - ConstraintViolationListInterface $constraintViolationList + ChannelContextInterface $channelContext, + ChannelInterface $channel, + Request $request ): void { - $request->attributes = new ParameterBag(['channelCode' => 'non_existing_channel']); + $channelContext->getChannel()->willReturn($channel); + $channel->getCode()->willReturn('WEB_GB'); - $constraintViolationList->count()->willReturn(1); - - $validator->validate(Argument::type(PickupCartRequest::class))->willReturn($constraintViolationList); + $request->attributes = new ParameterBag(['token' => 'sample_cart_token']); + $validator->validate(Argument::any())->shouldNotBeCalled(); $bus->dispatch(Argument::any())->shouldNotBeCalled(); - $this->shouldThrow(\InvalidArgumentException::class)->during('doNotAllowNullCartToken', [$request]); + $this->doNotAllowNullCartToken($request)->shouldReturn($request); } function it_picks_up_new_cart_and_sets_its_token_on_request_if_token_was_not_passed( - Request $request, ValidatorInterface $validator, MessageBusInterface $bus, + ChannelContextInterface $channelContext, + ChannelInterface $channel, + Request $request, ConstraintViolationListInterface $constraintViolationList ): void { - $request->attributes = new ParameterBag(['channelCode' => 'en_GB']); + $channelContext->getChannel()->willReturn($channel); + $channel->getCode()->willReturn('WEB_GB'); + + $request->attributes = new ParameterBag(); $constraintViolationList->count()->willReturn(0); @@ -75,7 +67,7 @@ function it_picks_up_new_cart_and_sets_its_token_on_request_if_token_was_not_pas $bus ->dispatch(Argument::that(function (PickupCart $command): bool { - return !empty($command->orderToken()) && $command->channelCode() === 'en_GB'; + return !empty($command->orderToken()) && $command->channelCode() === 'WEB_GB'; })) ->willReturn(new Envelope(new \stdClass())) ->shouldBeCalled() diff --git a/src/Controller/Cart/PickupCartAction.php b/src/Controller/Cart/PickupCartAction.php index ee3d8f5c1..19c4d7e7f 100644 --- a/src/Controller/Cart/PickupCartAction.php +++ b/src/Controller/Cart/PickupCartAction.php @@ -6,6 +6,7 @@ use FOS\RestBundle\View\View; use FOS\RestBundle\View\ViewHandlerInterface; +use Sylius\Component\Channel\Context\ChannelContextInterface; use Sylius\ShopApiPlugin\Factory\ValidationErrorViewFactoryInterface; use Sylius\ShopApiPlugin\Request\Cart\PickupCartRequest; use Sylius\ShopApiPlugin\ViewRepository\Cart\CartViewRepositoryInterface; @@ -32,23 +33,30 @@ final class PickupCartAction /** @var CartViewRepositoryInterface */ private $cartQuery; + /** @var ChannelContextInterface */ + private $channelContext; + public function __construct( ViewHandlerInterface $viewHandler, MessageBusInterface $bus, ValidatorInterface $validator, ValidationErrorViewFactoryInterface $validationErrorViewFactory, - CartViewRepositoryInterface $cartQuery + CartViewRepositoryInterface $cartQuery, + ChannelContextInterface $channelContext ) { $this->viewHandler = $viewHandler; $this->bus = $bus; $this->validator = $validator; $this->validationErrorViewFactory = $validationErrorViewFactory; $this->cartQuery = $cartQuery; + $this->channelContext = $channelContext; } public function __invoke(Request $request): Response { - $pickupRequest = new PickupCartRequest($request); + $channel = $this->channelContext->getChannel(); + + $pickupRequest = new PickupCartRequest($channel->getCode()); $validationResults = $this->validator->validate($pickupRequest); diff --git a/src/Normalizer/RequestCartTokenNormalizer.php b/src/Normalizer/RequestCartTokenNormalizer.php index 2046a277b..c195ce1e8 100644 --- a/src/Normalizer/RequestCartTokenNormalizer.php +++ b/src/Normalizer/RequestCartTokenNormalizer.php @@ -4,6 +4,7 @@ namespace Sylius\ShopApiPlugin\Normalizer; +use Sylius\Component\Channel\Context\ChannelContextInterface; use Sylius\ShopApiPlugin\Request\Cart\PickupCartRequest; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Messenger\MessageBusInterface; @@ -17,10 +18,17 @@ final class RequestCartTokenNormalizer implements RequestCartTokenNormalizerInte /** @var MessageBusInterface */ private $bus; - public function __construct(ValidatorInterface $validator, MessageBusInterface $bus) - { + /** @var ChannelContextInterface */ + private $channelContext; + + public function __construct( + ValidatorInterface $validator, + MessageBusInterface $bus, + ChannelContextInterface $channelContext + ) { $this->validator = $validator; $this->bus = $bus; + $this->channelContext = $channelContext; } public function doNotAllowNullCartToken(Request $request): Request @@ -29,7 +37,8 @@ public function doNotAllowNullCartToken(Request $request): Request return $request; } - $pickupRequest = new PickupCartRequest($request); + $channel = $this->channelContext->getChannel(); + $pickupRequest = new PickupCartRequest($channel->getCode()); $validationResults = $this->validator->validate($pickupRequest); diff --git a/src/Request/Cart/PickupCartRequest.php b/src/Request/Cart/PickupCartRequest.php index d531ac49f..f2cf1998e 100644 --- a/src/Request/Cart/PickupCartRequest.php +++ b/src/Request/Cart/PickupCartRequest.php @@ -6,7 +6,6 @@ use Ramsey\Uuid\Uuid; use Sylius\ShopApiPlugin\Command\Cart\PickupCart; -use Symfony\Component\HttpFoundation\Request; class PickupCartRequest { @@ -14,16 +13,16 @@ class PickupCartRequest protected $token; /** @var string */ - protected $channel; + protected $channelCode; - public function __construct(Request $request) + public function __construct(string $channelCode) { $this->token = Uuid::uuid4()->toString(); - $this->channel = $request->attributes->get('channelCode'); + $this->channelCode = $channelCode; } public function getCommand(): PickupCart { - return new PickupCart($this->token, $this->channel); + return new PickupCart($this->token, $this->channelCode); } } diff --git a/src/Resources/config/routing.yml b/src/Resources/config/routing.yml index b6729b1ec..64c97eee0 100644 --- a/src/Resources/config/routing.yml +++ b/src/Resources/config/routing.yml @@ -1,6 +1,6 @@ sylius_shop_api_cart: resource: "@ShopApiPlugin/Resources/config/routing/cart.yml" - prefix: /shop-api/{channelCode} + prefix: /shop-api sylius_shop_api_product_by_slug: resource: "@ShopApiPlugin/Resources/config/routing/productBySlug.yml" diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index 6878ed5a1..43953a561 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -69,6 +69,7 @@ > + diff --git a/src/Resources/config/services/actions/cart.xml b/src/Resources/config/services/actions/cart.xml index 9c1a7c9d3..6dd1e5159 100644 --- a/src/Resources/config/services/actions/cart.xml +++ b/src/Resources/config/services/actions/cart.xml @@ -37,6 +37,7 @@ + - + diff --git a/tests/Controller/Cart/CartAddCouponShopApiTest.php b/tests/Controller/Cart/CartAddCouponShopApiTest.php index 8ebb2cf34..e09a187da 100644 --- a/tests/Controller/Cart/CartAddCouponShopApiTest.php +++ b/tests/Controller/Cart/CartAddCouponShopApiTest.php @@ -33,7 +33,7 @@ public function it_allows_to_add_promotion_coupon_to_the_cart(): void } EOT; - $this->client->request('PUT', sprintf('/shop-api/WEB_GB/carts/%s/coupon', $token), [], [], self::CONTENT_TYPE_HEADER, $data); + $this->client->request('PUT', sprintf('/shop-api/carts/%s/coupon', $token), [], [], self::CONTENT_TYPE_HEADER, $data); $response = $this->client->getResponse(); @@ -54,7 +54,7 @@ public function it_does_not_allow_to_add_promotion_if_coupon_is_not_specified(): $bus->dispatch(new PickupCart($token, 'WEB_GB')); $bus->dispatch(new PutSimpleItemToCart($token, 'LOGAN_MUG_CODE', 5)); - $this->client->request('PUT', sprintf('/shop-api/WEB_GB/carts/%s/coupon', $token), [], [], self::CONTENT_TYPE_HEADER); + $this->client->request('PUT', sprintf('/shop-api/carts/%s/coupon', $token), [], [], self::CONTENT_TYPE_HEADER); $response = $this->client->getResponse(); @@ -75,7 +75,7 @@ public function it_does_not_allow_to_add_promotion_code_if_cart_does_not_exists( } EOT; - $this->client->request('PUT', '/shop-api/WEB_GB/carts/WRONGTOKEN/coupon', [], [], self::CONTENT_TYPE_HEADER, $data); + $this->client->request('PUT', '/shop-api/carts/WRONGTOKEN/coupon', [], [], self::CONTENT_TYPE_HEADER, $data); $response = $this->client->getResponse(); @@ -103,7 +103,7 @@ public function it_does_not_allow_to_add_promotion_code_if_promotion_code_does_n } EOT; - $this->client->request('PUT', sprintf('/shop-api/WEB_GB/carts/%s/coupon', $token), [], [], self::CONTENT_TYPE_HEADER, $data); + $this->client->request('PUT', sprintf('/shop-api/carts/%s/coupon', $token), [], [], self::CONTENT_TYPE_HEADER, $data); $response = $this->client->getResponse(); @@ -131,7 +131,7 @@ public function it_does_not_allow_to_add_promotion_code_if_code_is_invalid(): vo } EOT; - $this->client->request('PUT', sprintf('/shop-api/WEB_GB/carts/%s/coupon', $token), [], [], self::CONTENT_TYPE_HEADER, $data); + $this->client->request('PUT', sprintf('/shop-api/carts/%s/coupon', $token), [], [], self::CONTENT_TYPE_HEADER, $data); $response = $this->client->getResponse(); @@ -159,37 +159,10 @@ public function it_does_not_allow_to_add_promotion_code_if_related_promotion_is_ } EOT; - $this->client->request('PUT', sprintf('/shop-api/WEB_GB/carts/%s/coupon', $token), [], [], self::CONTENT_TYPE_HEADER, $data); + $this->client->request('PUT', sprintf('/shop-api/carts/%s/coupon', $token), [], [], self::CONTENT_TYPE_HEADER, $data); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/validation_coupon_not_valid_response', Response::HTTP_BAD_REQUEST); } - - /** - * @test - */ - public function it_does_not_allow_to_add_promotion_code_in_non_existent_channel(): void - { - $this->loadFixturesFromFiles(['channel.yml', 'shop.yml', 'coupon_based_promotion.yml']); - - $token = 'SDAOSLEFNWU35H3QLI5325'; - - /** @var MessageBusInterface $bus */ - $bus = $this->get('sylius_shop_api_plugin.command_bus'); - $bus->dispatch(new PickupCart($token, 'WEB_GB')); - $bus->dispatch(new PutSimpleItemToCart($token, 'LOGAN_MUG_CODE', 5)); - - $data = -<<client->request('PUT', sprintf('/shop-api/SPACE_KLINGON/carts/%s/coupon', $token), [], [], self::CONTENT_TYPE_HEADER, $data); - $response = $this->client->getResponse(); - - $this->assertResponse($response, 'channel_has_not_been_found_response', Response::HTTP_NOT_FOUND); - } } diff --git a/tests/Controller/Cart/CartChangeItemQuantityApiTest.php b/tests/Controller/Cart/CartChangeItemQuantityApiTest.php index 568c1fa35..7c9afefce 100644 --- a/tests/Controller/Cart/CartChangeItemQuantityApiTest.php +++ b/tests/Controller/Cart/CartChangeItemQuantityApiTest.php @@ -27,7 +27,7 @@ public function it_does_not_allow_to_change_quantity_if_cart_does_not_exists(): "quantity": 5 } EOT; - $this->client->request('PUT', '/shop-api/WEB_GB/carts/SDAOSLEFNWU35H3QLI5325/items/1', [], [], self::CONTENT_TYPE_HEADER, $data); + $this->client->request('PUT', '/shop-api/carts/SDAOSLEFNWU35H3QLI5325/items/1', [], [], self::CONTENT_TYPE_HEADER, $data); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/validation_cart_and_cart_item_not_exist_response', Response::HTTP_BAD_REQUEST); @@ -53,7 +53,7 @@ public function it_changes_item_quantity(): void "quantity": 5 } EOT; - $this->client->request('PUT', '/shop-api/WEB_GB/carts/SDAOSLEFNWU35H3QLI5325/items/' . $this->getFirstOrderItemId($token), [], [], self::CONTENT_TYPE_HEADER, $data); + $this->client->request('PUT', '/shop-api/carts/SDAOSLEFNWU35H3QLI5325/items/' . $this->getFirstOrderItemId($token), [], [], self::CONTENT_TYPE_HEADER, $data); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/filled_cart_with_simple_product_summary_response', Response::HTTP_OK); @@ -79,7 +79,7 @@ public function it_does_not_allow_to_set_quantity_lower_than_one(): void "quantity": 0 } EOT; - $this->client->request('PUT', '/shop-api/WEB_GB/carts/SDAOSLEFNWU35H3QLI5325/items/' . $this->getFirstOrderItemId($token), [], [], self::CONTENT_TYPE_HEADER, $data); + $this->client->request('PUT', '/shop-api/carts/SDAOSLEFNWU35H3QLI5325/items/' . $this->getFirstOrderItemId($token), [], [], self::CONTENT_TYPE_HEADER, $data); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/validation_quantity_lower_than_one_response', Response::HTTP_BAD_REQUEST); @@ -99,7 +99,7 @@ public function it_does_not_allow_to_change_quantity_without_quantity_defined(): $bus->dispatch(new PickupCart($token, 'WEB_GB')); $bus->dispatch(new PutSimpleItemToCart($token, 'LOGAN_MUG_CODE', 3)); - $this->client->request('PUT', '/shop-api/WEB_GB/carts/SDAOSLEFNWU35H3QLI5325/items/' . $this->getFirstOrderItemId($token), [], [], self::CONTENT_TYPE_HEADER); + $this->client->request('PUT', '/shop-api/carts/SDAOSLEFNWU35H3QLI5325/items/' . $this->getFirstOrderItemId($token), [], [], self::CONTENT_TYPE_HEADER); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/validation_quantity_lower_than_one_response', Response::HTTP_BAD_REQUEST); @@ -124,37 +124,12 @@ public function it_does_not_allow_to_change_quantity_if_cart_item_does_not_exist "quantity": 5 } EOT; - $this->client->request('PUT', '/shop-api/WEB_GB/carts/SDAOSLEFNWU35H3QLI5325/items/420', [], [], self::CONTENT_TYPE_HEADER, $data); + $this->client->request('PUT', '/shop-api/carts/SDAOSLEFNWU35H3QLI5325/items/420', [], [], self::CONTENT_TYPE_HEADER, $data); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/validation_cart_item_not_exists_response', Response::HTTP_BAD_REQUEST); } - /** - * @test - */ - public function it_does_not_allow_to_change_item_quantity_in_non_existent_channel(): void - { - $this->loadFixturesFromFiles(['channel.yml', 'shop.yml']); - - $token = 'SDAOSLEFNWU35H3QLI5325'; - - /** @var MessageBusInterface $bus */ - $bus = $this->get('sylius_shop_api_plugin.command_bus'); - $bus->dispatch(new PickupCart($token, 'WEB_GB')); - - $data = -<<client->request('PUT', '/shop-api/SPACE_KLINGON/carts/SDAOSLEFNWU35H3QLI5325/items/420', [], [], self::CONTENT_TYPE_HEADER, $data); - $response = $this->client->getResponse(); - - $this->assertResponse($response, 'channel_has_not_been_found_response', Response::HTTP_NOT_FOUND); - } - private function getFirstOrderItemId(string $orderToken): string { /** @var OrderRepositoryInterface $orderRepository */ diff --git a/tests/Controller/Cart/CartDropCartApiTest.php b/tests/Controller/Cart/CartDropCartApiTest.php index faa31039c..d0d0aa556 100644 --- a/tests/Controller/Cart/CartDropCartApiTest.php +++ b/tests/Controller/Cart/CartDropCartApiTest.php @@ -25,12 +25,12 @@ public function it_returns_not_found_exception_if_cart_has_not_been_found(): voi { $this->loadFixturesFromFiles(['channel.yml', 'shop.yml']); - $this->client->request('DELETE', '/shop-api/WEB_GB/carts/SDAOSLEFNWU35H3QLI5325', [], [], self::CONTENT_TYPE_HEADER); + $this->client->request('DELETE', '/shop-api/carts/SDAOSLEFNWU35H3QLI5325', [], [], self::CONTENT_TYPE_HEADER); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/validation_cart_not_exists_response', Response::HTTP_BAD_REQUEST); - $this->client->request('DELETE', '/shop-api/WEB_GB/carts/SDAOSLEFNWU35H3QLI5325?locale=de_DE', [], [], self::CONTENT_TYPE_HEADER); + $this->client->request('DELETE', '/shop-api/carts/SDAOSLEFNWU35H3QLI5325?locale=de_DE', [], [], self::CONTENT_TYPE_HEADER); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/validation_cart_not_exists_in_german_response', Response::HTTP_BAD_REQUEST); @@ -50,7 +50,7 @@ public function it_deletes_a_cart(): void $bus->dispatch(new PickupCart($token, 'WEB_GB')); $bus->dispatch(new PutSimpleItemToCart($token, 'LOGAN_MUG_CODE', 5)); - $this->client->request('DELETE', '/shop-api/WEB_GB/carts/' . $token, [], [], self::CONTENT_TYPE_HEADER); + $this->client->request('DELETE', '/shop-api/carts/' . $token, [], [], self::CONTENT_TYPE_HEADER); $response = $this->client->getResponse(); $this->assertResponseCode($response, Response::HTTP_NO_CONTENT); @@ -97,29 +97,9 @@ public function it_returns_not_found_exception_if_order_is_in_different_state_th $bus->dispatch(new CompleteOrder($token, 'sylius@example.com')); - $this->client->request('DELETE', '/shop-api/WEB_GB/carts/' . $order->getTokenValue(), [], [], self::CONTENT_TYPE_HEADER); + $this->client->request('DELETE', '/shop-api/carts/' . $order->getTokenValue(), [], [], self::CONTENT_TYPE_HEADER); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/validation_cart_not_exists_response', Response::HTTP_BAD_REQUEST); } - - /** - * @test - */ - public function it_does_not_allow_to_delete_cart_in_non_existent_channel(): void - { - $this->loadFixturesFromFiles(['channel.yml', 'shop.yml']); - - $token = 'SDAOSLEFNWU35H3QLI5325'; - - /** @var MessageBusInterface $bus */ - $bus = $this->get('sylius_shop_api_plugin.command_bus'); - $bus->dispatch(new PickupCart($token, 'WEB_GB')); - $bus->dispatch(new PutSimpleItemToCart($token, 'LOGAN_MUG_CODE', 5)); - - $this->client->request('DELETE', '/shop-api/SPACE_KLINGON/carts/' . $token, [], [], self::CONTENT_TYPE_HEADER); - $response = $this->client->getResponse(); - - $this->assertResponse($response, 'channel_has_not_been_found_response', Response::HTTP_NOT_FOUND); - } } diff --git a/tests/Controller/Cart/CartEstimateShippingTest.php b/tests/Controller/Cart/CartEstimateShippingTest.php index 6ec73a704..dbf028b3b 100644 --- a/tests/Controller/Cart/CartEstimateShippingTest.php +++ b/tests/Controller/Cart/CartEstimateShippingTest.php @@ -19,7 +19,7 @@ public function it_returns_not_found_exception_if_cart_has_not_been_found(): voi { $this->loadFixturesFromFiles(['shop.yml', 'country.yml']); - $this->client->request('GET', '/shop-api/WEB_GB/carts/SDAOSLEFNWU35H3QLI5325/estimated-shipping-cost', [], [], self::CONTENT_TYPE_HEADER); + $this->client->request('GET', '/shop-api/carts/SDAOSLEFNWU35H3QLI5325/estimated-shipping-cost', [], [], self::CONTENT_TYPE_HEADER); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/cart_and_country_does_not_exist_response', Response::HTTP_BAD_REQUEST); @@ -39,7 +39,7 @@ public function it_calculates_estimated_shipping_cost_based_on_country(): void $bus->dispatch(new PickupCart($token, 'WEB_GB')); $bus->dispatch(new PutSimpleItemToCart($token, 'LOGAN_MUG_CODE', 5)); - $this->client->request('GET', sprintf('/shop-api/WEB_GB/carts/%s/estimated-shipping-cost?countryCode=GB', $token), [], [], self::CONTENT_TYPE_HEADER); + $this->client->request('GET', sprintf('/shop-api/carts/%s/estimated-shipping-cost?countryCode=GB', $token), [], [], self::CONTENT_TYPE_HEADER); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/estimated_shipping_cost_bases_on_country_response', Response::HTTP_OK); @@ -59,22 +59,9 @@ public function it_calculates_estimated_shipping_cost_based_on_country_and_provi $bus->dispatch(new PickupCart($token, 'WEB_GB')); $bus->dispatch(new PutSimpleItemToCart($token, 'LOGAN_MUG_CODE', 5)); - $this->client->request('GET', sprintf('/shop-api/WEB_GB/carts/%s/estimated-shipping-cost?countryCode=GB&provinceCode=GB-SCT', $token), [], [], self::CONTENT_TYPE_HEADER); + $this->client->request('GET', sprintf('/shop-api/carts/%s/estimated-shipping-cost?countryCode=GB&provinceCode=GB-SCT', $token), [], [], self::CONTENT_TYPE_HEADER); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/estimated_shipping_cost_bases_on_country_and_province_response', Response::HTTP_OK); } - - /** - * @test - */ - public function it_does_not_allow_to_estimate_shipping_in_non_existent_channel(): void - { - $this->loadFixturesFromFiles(['shop.yml', 'country.yml']); - - $this->client->request('GET', '/shop-api/SPACE_KLINGON/carts/SDAOSLEFNWU35H3QLI5325/estimated-shipping-cost', [], [], self::CONTENT_TYPE_HEADER); - $response = $this->client->getResponse(); - - $this->assertResponse($response, 'channel_has_not_been_found_response', Response::HTTP_NOT_FOUND); - } } diff --git a/tests/Controller/Cart/CartPickupApiTest.php b/tests/Controller/Cart/CartPickupApiTest.php index c27ffad3a..ec9730e0a 100644 --- a/tests/Controller/Cart/CartPickupApiTest.php +++ b/tests/Controller/Cart/CartPickupApiTest.php @@ -20,7 +20,7 @@ public function it_creates_a_new_cart(): void { $this->loadFixturesFromFiles(['shop.yml']); - $this->client->request('POST', '/shop-api/WEB_GB/carts', [], [], self::CONTENT_TYPE_HEADER); + $this->client->request('POST', '/shop-api/carts', [], [], self::CONTENT_TYPE_HEADER); $response = $this->client->getResponse(); @@ -41,7 +41,7 @@ public function it_only_creates_one_cart_if_user_is_logged_in(): void $this->logInUser('oliver@queen.com', '123password'); - $this->client->request('POST', '/shop-api/WEB_GB/carts', [], [], static::CONTENT_TYPE_HEADER); + $this->client->request('POST', '/shop-api/carts', [], [], static::CONTENT_TYPE_HEADER); $response = $this->client->getResponse(); $this->assertResponseCode($response, Response::HTTP_CREATED); @@ -51,20 +51,4 @@ public function it_only_creates_one_cart_if_user_is_logged_in(): void $this->assertCount(1, $orders, 'Only one cart should be created'); } - - /** - * @test - */ - public function it_does_not_allow_to_create_a_new_cart_in_non_existent_channel(): void - { - $this->loadFixturesFromFiles(['shop.yml']); - - $this->client->request( - 'POST', '/shop-api/SPACE_KLINGON/carts', [], [], self::CONTENT_TYPE_HEADER - ); - - $response = $this->client->getResponse(); - - $this->assertResponse($response, 'channel_has_not_been_found_response', Response::HTTP_NOT_FOUND); - } } diff --git a/tests/Controller/Cart/CartPutItemToCartApiTest.php b/tests/Controller/Cart/CartPutItemToCartApiTest.php index ba158b68e..a3c6ce4df 100644 --- a/tests/Controller/Cart/CartPutItemToCartApiTest.php +++ b/tests/Controller/Cart/CartPutItemToCartApiTest.php @@ -38,7 +38,7 @@ public function it_adds_a_product_to_the_cart(): void "quantity": 3 } EOT; - $this->client->request('POST', sprintf('/shop-api/WEB_GB/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); + $this->client->request('POST', sprintf('/shop-api/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/add_simple_product_to_cart_response', Response::HTTP_CREATED); @@ -64,8 +64,8 @@ public function it_increases_quantity_of_existing_item_if_the_same_product_is_ad "quantity": 1 } EOT; - $this->client->request('POST', sprintf('/shop-api/WEB_GB/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); - $this->client->request('POST', sprintf('/shop-api/WEB_GB/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); + $this->client->request('POST', sprintf('/shop-api/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); + $this->client->request('POST', sprintf('/shop-api/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/add_simple_product_multiple_times_to_cart_response', Response::HTTP_CREATED); @@ -91,7 +91,7 @@ public function it_validates_if_product_is_simple_during_add_simple_product(): v "quantity": 3 } EOT; - $this->client->request('POST', sprintf('/shop-api/WEB_GB/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); + $this->client->request('POST', sprintf('/shop-api/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/validation_product_not_simple_response', Response::HTTP_BAD_REQUEST); @@ -117,7 +117,7 @@ public function it_validates_if_quantity_is_larger_than_0_during_add_simple_prod "quantity": 0 } EOT; - $this->client->request('POST', sprintf('/shop-api/WEB_GB/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); + $this->client->request('POST', sprintf('/shop-api/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/validation_quantity_lower_than_one_response', Response::HTTP_BAD_REQUEST); @@ -143,7 +143,7 @@ public function it_converts_quantity_as_an_integer_and_adds_simple_product(): vo "quantity": "3" } EOT; - $this->client->request('POST', sprintf('/shop-api/WEB_GB/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); + $this->client->request('POST', sprintf('/shop-api/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/add_simple_product_to_cart_response', Response::HTTP_CREATED); @@ -168,7 +168,7 @@ public function it_validates_if_product_code_is_defined_during_add_simple_produc "quantity": 3 } EOT; - $this->client->request('POST', sprintf('/shop-api/WEB_GB/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); + $this->client->request('POST', sprintf('/shop-api/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/validation_product_not_defined_response', Response::HTTP_BAD_REQUEST); @@ -194,7 +194,7 @@ public function it_validates_if_product_exists_during_add_simple_product(): void "quantity": 3 } EOT; - $this->client->request('POST', sprintf('/shop-api/WEB_GB/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); + $this->client->request('POST', sprintf('/shop-api/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/validation_product_not_exists_response', Response::HTTP_BAD_REQUEST); @@ -216,7 +216,7 @@ public function it_does_not_allow_to_add_product_if_cart_does_not_exists_during_ "quantity": 3 } EOT; - $this->client->request('POST', sprintf('/shop-api/WEB_GB/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); + $this->client->request('POST', sprintf('/shop-api/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/validation_cart_not_exists_response', Response::HTTP_BAD_REQUEST); @@ -270,7 +270,7 @@ public function it_does_not_allow_to_add_product_if_order_has_been_placed(): voi "quantity": 3 } EOT; - $this->client->request('POST', sprintf('/shop-api/WEB_GB/carts/%s/items', $order->getTokenValue()), [], [], self::CONTENT_TYPE_HEADER, $data); + $this->client->request('POST', sprintf('/shop-api/carts/%s/items', $order->getTokenValue()), [], [], self::CONTENT_TYPE_HEADER, $data); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/validation_cart_not_exists_response', Response::HTTP_BAD_REQUEST); @@ -297,7 +297,7 @@ public function it_adds_a_product_variant_to_the_cart(): void "quantity": 3 } EOT; - $this->client->request('POST', sprintf('/shop-api/WEB_GB/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); + $this->client->request('POST', sprintf('/shop-api/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/add_product_variant_to_cart_response', Response::HTTP_CREATED); @@ -324,8 +324,8 @@ public function it_increases_quantity_of_existing_item_if_the_same_variant_is_ad "quantity": 3 } EOT; - $this->client->request('POST', sprintf('/shop-api/WEB_GB/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); - $this->client->request('POST', sprintf('/shop-api/WEB_GB/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); + $this->client->request('POST', sprintf('/shop-api/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); + $this->client->request('POST', sprintf('/shop-api/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/add_product_variant_multiple_times_to_cart_response', Response::HTTP_CREATED); @@ -352,7 +352,7 @@ public function it_validates_if_quantity_is_larger_than_0_during_add_variant_bas "quantity": 0 } EOT; - $this->client->request('POST', sprintf('/shop-api/WEB_GB/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); + $this->client->request('POST', sprintf('/shop-api/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/validation_quantity_lower_than_one_response', Response::HTTP_BAD_REQUEST); @@ -379,7 +379,7 @@ public function it_converts_quantity_as_an_integer_and_adds_variant_based_config "quantity": "3" } EOT; - $this->client->request('POST', sprintf('/shop-api/WEB_GB/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); + $this->client->request('POST', sprintf('/shop-api/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/add_product_variant_to_cart_response', Response::HTTP_CREATED); @@ -405,7 +405,7 @@ public function it_validates_if_product_code_is_defined_during_add_variant_based "quantity": 3 } EOT; - $this->client->request('POST', sprintf('/shop-api/WEB_GB/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); + $this->client->request('POST', sprintf('/shop-api/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/validation_product_not_defined_response', Response::HTTP_BAD_REQUEST); @@ -432,7 +432,7 @@ public function it_validates_if_product_exists_during_add_variant_based_configur "quantity": 3 } EOT; - $this->client->request('POST', sprintf('/shop-api/WEB_GB/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); + $this->client->request('POST', sprintf('/shop-api/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/validation_product_not_exists_response', Response::HTTP_BAD_REQUEST); @@ -459,7 +459,7 @@ public function it_validates_if_product_is_configurable_during_add_variant_based "quantity": 3 } EOT; - $this->client->request('POST', sprintf('/shop-api/WEB_GB/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); + $this->client->request('POST', sprintf('/shop-api/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/validation_product_not_configurable_response', Response::HTTP_BAD_REQUEST); @@ -486,7 +486,7 @@ public function it_validates_if_product_variant_exist_during_add_variant_based_c "quantity": 3 } EOT; - $this->client->request('POST', sprintf('/shop-api/WEB_GB/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); + $this->client->request('POST', sprintf('/shop-api/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/validation_product_variant_not_exists_response', Response::HTTP_BAD_REQUEST); @@ -512,7 +512,7 @@ public function it_throws_an_exception_if_product_variant_has_not_been_found(): "quantity": 3 } EOT; - $this->client->request('POST', '/shop-api/WEB_GB/carts/SDAOSLEFNWU35H3QLI5325/items', [], [], self::CONTENT_TYPE_HEADER, $data); + $this->client->request('POST', '/shop-api/carts/SDAOSLEFNWU35H3QLI5325/items', [], [], self::CONTENT_TYPE_HEADER, $data); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/product_variant_has_not_been_found_response', Response::HTTP_NOT_FOUND); @@ -542,7 +542,7 @@ public function it_adds_a_product_variant_based_on_options_to_the_cart(): void "quantity": 3 } EOT; - $this->client->request('POST', '/shop-api/WEB_GB/carts/SDAOSLEFNWU35H3QLI5325/items', [], [], self::CONTENT_TYPE_HEADER, $data); + $this->client->request('POST', '/shop-api/carts/SDAOSLEFNWU35H3QLI5325/items', [], [], self::CONTENT_TYPE_HEADER, $data); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/add_product_variant_based_on_options_to_cart_response', Response::HTTP_CREATED); @@ -572,39 +572,13 @@ public function it_increases_quantity_of_existing_item_while_adding_the_same_pro "quantity": 3 } EOT; - $this->client->request('POST', sprintf('/shop-api/WEB_GB/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); - $this->client->request('POST', sprintf('/shop-api/WEB_GB/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); + $this->client->request('POST', sprintf('/shop-api/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); + $this->client->request('POST', sprintf('/shop-api/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/add_product_variant_based_on_options_multiple_times_to_cart_response', Response::HTTP_CREATED); } - /** - * @test - */ - public function it_does_not_allow_to_put_item_to_cart_in_non_existent_channel(): void - { - $this->loadFixturesFromFiles(['shop.yml']); - - $token = 'SDAOSLEFNWU35H3QLI5325'; - - /** @var MessageBusInterface $bus */ - $bus = $this->get('sylius_shop_api_plugin.command_bus'); - $bus->dispatch(new PickupCart($token, 'WEB_GB')); - - $data = -<<client->request('POST', sprintf('/shop-api/SPACE_KLINGON/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); - $response = $this->client->getResponse(); - - $this->assertResponse($response, 'channel_has_not_been_found_response', Response::HTTP_NOT_FOUND); - } - /** * @test */ @@ -619,7 +593,7 @@ public function it_creates_new_cart_when_token_is_not_passed(): void "quantity": 3 } EOT; - $this->client->request('POST', '/shop-api/WEB_GB/carts/new/items', [], [], self::CONTENT_TYPE_HEADER, $data); + $this->client->request('POST', '/shop-api/carts/new/items', [], [], self::CONTENT_TYPE_HEADER, $data); $response = $this->client->getResponse(); diff --git a/tests/Controller/Cart/CartPutItemsToCartApiTest.php b/tests/Controller/Cart/CartPutItemsToCartApiTest.php index 1eb5ca26c..d2d16eec6 100644 --- a/tests/Controller/Cart/CartPutItemsToCartApiTest.php +++ b/tests/Controller/Cart/CartPutItemsToCartApiTest.php @@ -48,7 +48,7 @@ public function it_adds_a_product_to_the_cart(): void ] } EOT; - $this->client->request('POST', sprintf('/shop-api/WEB_GB/carts/%s/multiple-items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); + $this->client->request('POST', sprintf('/shop-api/carts/%s/multiple-items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/add_multiple_products_to_cart_response', Response::HTTP_CREATED); @@ -90,8 +90,8 @@ public function it_does_nothing_if_any_of_requested_products_is_not_valid(): voi ] } EOT; - $this->client->request('POST', sprintf('/shop-api/WEB_GB/carts/%s/multiple-items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); - $this->client->request('GET', sprintf('/shop-api/WEB_GB/carts/%s', $token), [], [], self::CONTENT_TYPE_HEADER, $data); + $this->client->request('POST', sprintf('/shop-api/carts/%s/multiple-items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); + $this->client->request('GET', sprintf('/shop-api/carts/%s', $token), [], [], self::CONTENT_TYPE_HEADER, $data); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/empty_response', Response::HTTP_OK); @@ -132,51 +132,12 @@ public function it_shows_validation_error_for_proper_product(): void ] } EOT; - $this->client->request('POST', sprintf('/shop-api/WEB_GB/carts/%s/multiple-items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); + $this->client->request('POST', sprintf('/shop-api/carts/%s/multiple-items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/add_multiple_products_to_cart_validation_error_response', Response::HTTP_BAD_REQUEST); } - /** - * @test - */ - public function it_does_not_allow_to_put_items_to_cart_in_non_existent_channel(): void - { - $this->loadFixturesFromFiles(['shop.yml']); - - $token = 'SDAOSLEFNWU35H3QLI5325'; - - /** @var MessageBusInterface $bus */ - $bus = $this->get('sylius_shop_api_plugin.command_bus'); - $bus->dispatch(new PickupCart($token, 'WEB_GB')); - - $data = -<<client->request('POST', sprintf('/shop-api/SPACE_KLINGON/carts/%s/multiple-items', $token), [], [], self::CONTENT_TYPE_HEADER, $data); - $response = $this->client->getResponse(); - - $this->assertResponse($response, 'channel_has_not_been_found_response', Response::HTTP_NOT_FOUND); - } - /** * @test */ @@ -208,7 +169,7 @@ public function it_creates_new_cart_when_token_is_not_passed(): void ] } EOT; - $this->client->request('POST', '/shop-api/WEB_GB/carts/new/multiple-items', [], [], self::CONTENT_TYPE_HEADER, $data); + $this->client->request('POST', '/shop-api/carts/new/multiple-items', [], [], self::CONTENT_TYPE_HEADER, $data); $response = $this->client->getResponse(); diff --git a/tests/Controller/Cart/CartRemoveCouponShopApiTest.php b/tests/Controller/Cart/CartRemoveCouponShopApiTest.php index df3c528dd..9a2f491c4 100644 --- a/tests/Controller/Cart/CartRemoveCouponShopApiTest.php +++ b/tests/Controller/Cart/CartRemoveCouponShopApiTest.php @@ -28,7 +28,7 @@ public function it_allows_to_remove_a_promotion_coupon_from_the_cart(): void $bus->dispatch(new PutSimpleItemToCart($token, 'LOGAN_MUG_CODE', 5)); $bus->dispatch(new AddCoupon($token, 'BANANAS')); - $this->client->request('DELETE', sprintf('/shop-api/WEB_GB/carts/%s/coupon', $token), [], [], self::CONTENT_TYPE_HEADER, null); + $this->client->request('DELETE', sprintf('/shop-api/carts/%s/coupon', $token), [], [], self::CONTENT_TYPE_HEADER, null); $response = $this->client->getResponse(); @@ -49,7 +49,7 @@ public function it_allows_to_remove_a_promotion_coupon_from_the_cart_even_if_it_ $bus->dispatch(new PickupCart($token, 'WEB_GB')); $bus->dispatch(new PutSimpleItemToCart($token, 'LOGAN_MUG_CODE', 5)); - $this->client->request('DELETE', sprintf('/shop-api/WEB_GB/carts/%s/coupon', $token), [], [], self::CONTENT_TYPE_HEADER, null); + $this->client->request('DELETE', sprintf('/shop-api/carts/%s/coupon', $token), [], [], self::CONTENT_TYPE_HEADER, null); $response = $this->client->getResponse(); @@ -63,24 +63,10 @@ public function it_does_not_allow_to_add_promotion_code_if_cart_does_not_exists( { $this->loadFixturesFromFiles(['shop.yml']); - $this->client->request('DELETE', '/shop-api/WEB_GB/carts/WRONGTOKEN/coupon', [], [], self::CONTENT_TYPE_HEADER, null); + $this->client->request('DELETE', '/shop-api/carts/WRONGTOKEN/coupon', [], [], self::CONTENT_TYPE_HEADER, null); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/validation_cart_not_exists_response', Response::HTTP_BAD_REQUEST); } - - /** - * @test - */ - public function it_does_not_allow_to_add_promotion_code_in_non_existent_channel(): void - { - $this->loadFixturesFromFiles(['shop.yml']); - - $this->client->request('DELETE', '/shop-api/SPACE_KLINGON/carts/WRONGTOKEN/coupon', [], [], self::CONTENT_TYPE_HEADER, null); - - $response = $this->client->getResponse(); - - $this->assertResponse($response, 'channel_has_not_been_found_response', Response::HTTP_NOT_FOUND); - } } diff --git a/tests/Controller/Cart/CartRemoveItemFromCartApiTest.php b/tests/Controller/Cart/CartRemoveItemFromCartApiTest.php index 6f52e247c..269fa481b 100644 --- a/tests/Controller/Cart/CartRemoveItemFromCartApiTest.php +++ b/tests/Controller/Cart/CartRemoveItemFromCartApiTest.php @@ -37,7 +37,7 @@ public function it_deletes_item(): void /** @var OrderItemInterface $orderItem */ $orderItem = $order->getItems()->first(); - $this->client->request('DELETE', '/shop-api/WEB_GB/carts/SDAOSLEFNWU35H3QLI5325/items/' . $orderItem->getId(), [], [], self::CONTENT_TYPE_HEADER); + $this->client->request('DELETE', '/shop-api/carts/SDAOSLEFNWU35H3QLI5325/items/' . $orderItem->getId(), [], [], self::CONTENT_TYPE_HEADER); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/cart_after_deleting_an_item', Response::HTTP_OK); @@ -56,31 +56,12 @@ public function it_returns_not_found_exception_if_cart_item_has_not_been_found() $bus = $this->get('sylius_shop_api_plugin.command_bus'); $bus->dispatch(new PickupCart($token, 'WEB_GB')); - $this->client->request('DELETE', '/shop-api/WEB_GB/carts/SDAOSLEFNWU35H3QLI5325/items/420', [], [], self::CONTENT_TYPE_HEADER); + $this->client->request('DELETE', '/shop-api/carts/SDAOSLEFNWU35H3QLI5325/items/420', [], [], self::CONTENT_TYPE_HEADER); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/cart_item_has_not_been_found_response', Response::HTTP_BAD_REQUEST); } - /** - * @test - */ - public function it_does_not_allow_to_remove_item_from_cart_in_non_existent_channel(): void - { - $this->loadFixturesFromFiles(['shop.yml']); - - $token = 'SDAOSLEFNWU35H3QLI5325'; - - /** @var MessageBusInterface $bus */ - $bus = $this->get('sylius_shop_api_plugin.command_bus'); - $bus->dispatch(new PickupCart($token, 'WEB_GB')); - - $this->client->request('DELETE', '/shop-api/SPACE_KLINGON/carts/SDAOSLEFNWU35H3QLI5325/items/420', [], [], self::CONTENT_TYPE_HEADER); - $response = $this->client->getResponse(); - - $this->assertResponse($response, 'channel_has_not_been_found_response', Response::HTTP_NOT_FOUND); - } - /** * @test */ @@ -104,7 +85,7 @@ public function it_reprocesses_the_order_after_deleting_an_item(): void /** @var OrderItemInterface $orderItem */ $orderItem = $order->getItems()->last(); - $this->client->request('DELETE', '/shop-api/WEB_GB/carts/SDAOSLEFNWU35H3QLI5325/items/' . $orderItem->getId(), [], [], self::CONTENT_TYPE_HEADER); + $this->client->request('DELETE', '/shop-api/carts/SDAOSLEFNWU35H3QLI5325/items/' . $orderItem->getId(), [], [], self::CONTENT_TYPE_HEADER); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/reprocessed_cart_after_deleting_an_item', Response::HTTP_OK); diff --git a/tests/Controller/Cart/CartSummarizeApiTest.php b/tests/Controller/Cart/CartSummarizeApiTest.php index 8bc5fdb7c..7beacaa20 100644 --- a/tests/Controller/Cart/CartSummarizeApiTest.php +++ b/tests/Controller/Cart/CartSummarizeApiTest.php @@ -31,7 +31,7 @@ public function it_shows_summary_of_an_empty_cart(): void $bus = $this->get('sylius_shop_api_plugin.command_bus'); $bus->dispatch(new PickupCart($token, 'WEB_GB')); - $this->client->request('GET', '/shop-api/WEB_GB/carts/' . $token, [], [], self::CONTENT_TYPE_HEADER); + $this->client->request('GET', '/shop-api/carts/' . $token, [], [], self::CONTENT_TYPE_HEADER); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/empty_response', Response::HTTP_OK); @@ -44,7 +44,7 @@ public function it_returns_not_found_exception_if_cart_has_not_been_found(): voi { $this->loadFixturesFromFiles(['shop.yml']); - $this->client->request('GET', '/shop-api/WEB_GB/carts/SDAOSLEFNWU35H3QLI5325', [], [], self::CONTENT_TYPE_HEADER); + $this->client->request('GET', '/shop-api/carts/SDAOSLEFNWU35H3QLI5325', [], [], self::CONTENT_TYPE_HEADER); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/cart_has_not_been_found_response', Response::HTTP_NOT_FOUND); @@ -63,25 +63,12 @@ public function it_returns_not_found_exception_if_order_is_not_in_state_cart(): $this->placeOrderForCustomerWithEmail($email, $token); - $this->client->request('GET', '/shop-api/WEB_GB/carts/' . $token, [], [], self::CONTENT_TYPE_HEADER); + $this->client->request('GET', '/shop-api/carts/' . $token, [], [], self::CONTENT_TYPE_HEADER); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/cart_has_not_been_found_response', Response::HTTP_NOT_FOUND); } - /** - * @test - */ - public function it_does_not_allow_to_summarize_cart_in_non_existent_channel(): void - { - $this->loadFixturesFromFiles(['shop.yml']); - - $this->client->request('GET', '/shop-api/SPACE_KLINGON/carts/SDAOSLEFNWU35H3QLI5325', [], [], self::CONTENT_TYPE_HEADER); - $response = $this->client->getResponse(); - - $this->assertResponse($response, 'channel_has_not_been_found_response', Response::HTTP_NOT_FOUND); - } - /** * @test */ @@ -96,7 +83,7 @@ public function it_shows_summary_of_a_cart_filled_with_a_simple_product(): void $bus->dispatch(new PickupCart($token, 'WEB_GB')); $bus->dispatch(new PutSimpleItemToCart($token, 'LOGAN_MUG_CODE', 5)); - $this->client->request('GET', '/shop-api/WEB_GB/carts/' . $token, [], [], self::CONTENT_TYPE_HEADER); + $this->client->request('GET', '/shop-api/carts/' . $token, [], [], self::CONTENT_TYPE_HEADER); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/filled_cart_with_simple_product_summary_response', Response::HTTP_OK); @@ -116,7 +103,7 @@ public function it_shows_summary_of_a_cart_filled_with_a_simple_product_in_diffe $bus->dispatch(new PickupCart($token, 'WEB_DE')); $bus->dispatch(new PutSimpleItemToCart($token, 'LOGAN_MUG_CODE', 5)); - $this->client->request('GET', sprintf('/shop-api/WEB_GB/carts/%s', $token), [], [], self::CONTENT_TYPE_HEADER); + $this->client->request('GET', sprintf('/shop-api/carts/%s', $token), [], [], self::CONTENT_TYPE_HEADER); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/german_filled_cart_with_simple_product_summary_response', Response::HTTP_OK); @@ -155,10 +142,10 @@ public function it_shows_summary_of_a_cart_filled_with_a_product_with_variant(): "quantity": 3 } EOT; - $this->client->request('POST', sprintf('/shop-api/WEB_GB/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $regularVariant); - $this->client->request('POST', sprintf('/shop-api/WEB_GB/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $variantWithOptions); + $this->client->request('POST', sprintf('/shop-api/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $regularVariant); + $this->client->request('POST', sprintf('/shop-api/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $variantWithOptions); - $this->client->request('GET', sprintf('/shop-api/WEB_GB/carts/%s', $token), [], [], self::CONTENT_TYPE_HEADER); + $this->client->request('GET', sprintf('/shop-api/carts/%s', $token), [], [], self::CONTENT_TYPE_HEADER); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/filled_cart_with_product_variant_summary_response', Response::HTTP_OK); @@ -189,9 +176,9 @@ public function it_shows_summary_of_a_cart_filled_with_a_product_with_variant_in } EOT; - $this->client->request('POST', sprintf('/shop-api/WEB_GB/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $variantWithOptions); + $this->client->request('POST', sprintf('/shop-api/carts/%s/items', $token), [], [], self::CONTENT_TYPE_HEADER, $variantWithOptions); - $this->client->request('GET', sprintf('/shop-api/WEB_GB/carts/%s', $token), [], [], self::CONTENT_TYPE_HEADER); + $this->client->request('GET', sprintf('/shop-api/carts/%s', $token), [], [], self::CONTENT_TYPE_HEADER); $response = $this->client->getResponse(); $this->assertResponse($response, 'cart/german_filled_cart_with_product_variant_summary_response', Response::HTTP_OK); diff --git a/tests/Controller/Checkout/CheckoutSummarizeApiTest.php b/tests/Controller/Checkout/CheckoutSummarizeApiTest.php index eff86cbea..b32bb4859 100644 --- a/tests/Controller/Checkout/CheckoutSummarizeApiTest.php +++ b/tests/Controller/Checkout/CheckoutSummarizeApiTest.php @@ -211,7 +211,7 @@ public function it_modifies_shipping_cost_when_changing_item_quantity(): void "quantity": 2 } EOT; - $this->client->request('PUT', sprintf('/shop-api/WEB_GB/carts/%s/items/%d', $token, $orderItem->getId()), [], [], static::CONTENT_TYPE_HEADER, $data); + $this->client->request('PUT', sprintf('/shop-api/carts/%s/items/%d', $token, $orderItem->getId()), [], [], static::CONTENT_TYPE_HEADER, $data); $response = $this->client->getResponse(); $this->assertResponse($response, 'checkout/modified_cart_with_chosen_shipment_with_per_item_rate_response', Response::HTTP_OK); diff --git a/tests/Request/PickupCartRequestTest.php b/tests/Request/PickupCartRequestTest.php index d5b1ba8f7..4bd9a4359 100644 --- a/tests/Request/PickupCartRequestTest.php +++ b/tests/Request/PickupCartRequestTest.php @@ -6,14 +6,13 @@ use PHPUnit\Framework\TestCase; use Sylius\ShopApiPlugin\Request\Cart\PickupCartRequest; -use Symfony\Component\HttpFoundation\Request; final class PickupCartRequestTest extends TestCase { /** @test */ public function it_creates_pickup_cart_command(): void { - $pickupCartRequest = new PickupCartRequest(new Request([], [], ['channelCode' => 'WEB_GB'])); + $pickupCartRequest = new PickupCartRequest('WEB_GB'); $pickupCartCommand = $pickupCartRequest->getCommand();