-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[API][ShippingMethod] Add contract test for available shipping method…
…s endpoint
- Loading branch information
Showing
5 changed files
with
164 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
Sylius\Component\Core\Model\ShippingMethod: | ||
shipping_method_ups: | ||
code: 'UPS' | ||
enabled: true | ||
calculator: 'flat_rate' | ||
configuration: | ||
WEB: | ||
amount: 500 | ||
zone: '@zone_world' | ||
currentLocale: 'en_US' | ||
translations: ["@shipping_method_translation_ups"] | ||
channels: ["@channel_web"] | ||
shipping_method_dhl: | ||
code: 'DHL' | ||
enabled: true | ||
calculator: 'flat_rate' | ||
configuration: | ||
WEB: | ||
amount: 1000 | ||
zone: '@zone_world' | ||
currentLocale: 'en_US' | ||
translations: ["@shipping_method_translation_dhl"] | ||
channels: ["@channel_web"] | ||
|
||
Sylius\Component\Shipping\Model\ShippingMethodTranslation: | ||
shipping_method_translation_ups: | ||
name: 'UPS' | ||
locale: 'en_US' | ||
description: '<paragraph(2)>' | ||
translatable: '@shipping_method_ups' | ||
shipping_method_translation_dhl: | ||
name: 'DHL' | ||
locale: 'en_US' | ||
description: '<paragraph(2)>' | ||
translatable: '@shipping_method_dhl' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Sylius\Component\Addressing\Model\ZoneMember: | ||
zone_member_{US, FR, DE}: | ||
code: '<current()>' | ||
|
||
Sylius\Component\Addressing\Model\Zone: | ||
zone_world: | ||
code: 'WORLD' | ||
name: 'World' | ||
type: 'country' | ||
members: ['@zone_member_US', '@zone_member_FR', '@zone_member_DE'] |
44 changes: 44 additions & 0 deletions
44
tests/Api/Responses/Expected/shop/get_shipping_methods_response.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"@context": "\/api\/v2\/contexts\/ShippingMethod", | ||
"@id": "\/api\/v2\/shop\/orders\/nAWw2jewpA\/shipments\/@integer@\/methods", | ||
"@type": "hydra:Collection", | ||
"hydra:member": [ | ||
{ | ||
"@id": "\/api\/v2\/shop\/shipping-methods\/UPS", | ||
"@type": "ShippingMethod", | ||
"id": @integer@, | ||
"code": "UPS", | ||
"position": 0, | ||
"translations": { | ||
"en_US": { | ||
"@id": "\/api\/v2\/shop\/shipping-method-translations\/@integer@", | ||
"@type": "ShippingMethodTranslation", | ||
"id": @integer@, | ||
"name": "UPS", | ||
"description": @string@ | ||
} | ||
}, | ||
"name": "UPS", | ||
"price": 500 | ||
}, | ||
{ | ||
"@id": "\/api\/v2\/shop\/shipping-methods\/DHL", | ||
"@type": "ShippingMethod", | ||
"id": @integer@, | ||
"code": "DHL", | ||
"position": 1, | ||
"translations": { | ||
"en_US": { | ||
"@id": "\/api\/v2\/shop\/shipping-method-translations\/@integer@", | ||
"@type": "ShippingMethodTranslation", | ||
"id": @integer@, | ||
"name": "DHL", | ||
"description": @string@ | ||
} | ||
}, | ||
"name": "DHL", | ||
"price": 1000 | ||
} | ||
], | ||
"hydra:totalItems": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?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. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Tests\Api\Shop; | ||
|
||
use Sylius\Bundle\ApiBundle\Command\Cart\AddItemToCart; | ||
use Sylius\Bundle\ApiBundle\Command\Cart\PickupCart; | ||
use Sylius\Bundle\ApiBundle\Command\Checkout\AddressOrder; | ||
use Sylius\Component\Core\Model\Address; | ||
use Sylius\Tests\Api\JsonApiTestCase; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Messenger\MessageBusInterface; | ||
|
||
final class ShippingMethodsTest extends JsonApiTestCase | ||
{ | ||
/** @test */ | ||
public function it_gets_available_shipping_methods(): void | ||
{ | ||
$this->loadFixturesFromFiles(['cart.yaml', 'country.yaml', 'zone.yaml', 'shipping_method.yaml']); | ||
|
||
$tokenValue = 'nAWw2jewpA'; | ||
|
||
/** @var MessageBusInterface $commandBus */ | ||
$commandBus = $this->get('sylius.command_bus'); | ||
|
||
$pickupCartCommand = new PickupCart($tokenValue, 'en_US'); | ||
$pickupCartCommand->setChannelCode('WEB'); | ||
$commandBus->dispatch($pickupCartCommand); | ||
|
||
$addItemToCartCommand = new AddItemToCart('MUG_BLUE', 3); | ||
$addItemToCartCommand->setOrderTokenValue($tokenValue); | ||
$commandBus->dispatch($addItemToCartCommand); | ||
|
||
$address = new Address(); | ||
$address->setFirstName('John'); | ||
$address->setLastName('Doe'); | ||
$address->setCity('New York'); | ||
$address->setStreet('Avenue'); | ||
$address->setCountryCode('US'); | ||
$address->setPostcode('90000'); | ||
|
||
$addressOrderCommand = new AddressOrder('sylius@example.com', $address); | ||
$addressOrderCommand->setOrderTokenValue($tokenValue); | ||
$commandBus->dispatch($addressOrderCommand); | ||
|
||
$this->client->request('GET', '/api/v2/shop/orders/nAWw2jewpA', [], [], self::CONTENT_TYPE_HEADER); | ||
$orderResponse = json_decode($this->client->getResponse()->getContent(), true); | ||
|
||
$this->client->request( | ||
'GET', | ||
sprintf('/api/v2/shop/orders/nAWw2jewpA/shipments/%s/methods', $orderResponse['shipments'][0]['id']), | ||
[], | ||
[], | ||
self::CONTENT_TYPE_HEADER | ||
); | ||
$response = $this->client->getResponse(); | ||
|
||
$this->assertResponse($response, 'shop/get_shipping_methods_response', Response::HTTP_OK); | ||
} | ||
} |