-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #204 Test PayPal order creation requests (Zales0123)
This PR was merged into the 1.3 branch. Discussion ---------- From the very beginning of this plugin life, we knew it would be hard to test it. We should avoid testing what we don't own (PayPal API), as well as javascript libraries (like `PayPal.Buttons`). I think, that the proposed approach is a good compromise. It's almost impossible to test the whole checkout flow with UI Behats, so I decided I would just test each action separately, basing on mocked responses from PayPal API. It's for sure not everything, we should extend this test suite as much as possible, to feel secured with Sylius<>PayPal communication 🚀 Commits ------- c520d49 Test for PayPal order creation request 0d3c17d Test other PayPal orders creation actions 04c2ab6 Extract common data from fixture file
- Loading branch information
Showing
17 changed files
with
296 additions
and
38 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
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 |
---|---|---|
@@ -1,3 +1,25 @@ | ||
imports: | ||
- { resource: "../../../vendor/sylius/sylius/src/Sylius/Behat/Resources/config/services.xml" } | ||
- { resource: "../../Behat/Resources/services.xml" } | ||
|
||
services: | ||
Sylius\PayPalPlugin\Downloader\ReportDownloaderInterface: | ||
class: Tests\Sylius\PayPalPlugin\Service\DummyPayoutsReportDownloader | ||
|
||
Sylius\PayPalPlugin\Processor\PaymentCompleteProcessorInterface: | ||
class: Tests\Sylius\PayPalPlugin\Service\VoidPayPalPaymentCompleteProcessor | ||
|
||
Sylius\PayPalPlugin\Api\AuthorizeClientApiInterface: | ||
class: Tests\Sylius\PayPalPlugin\Service\DummyAuthorizeClientApi | ||
|
||
Sylius\PayPalPlugin\Api\OrderDetailsApiInterface: | ||
class: Tests\Sylius\PayPalPlugin\Service\DummyOrderDetailsApi | ||
|
||
Sylius\PayPalPlugin\Api\RefundPaymentApiInterface: | ||
class: Tests\Sylius\PayPalPlugin\Service\DummyRefundPaymentApi | ||
|
||
Sylius\PayPalPlugin\Provider\PayPalRefundDataProviderInterface: | ||
class: Tests\Sylius\PayPalPlugin\Service\DummyPayPalRefundDataProvider | ||
|
||
Sylius\PayPalPlugin\Api\CreateOrderApiInterface: | ||
class: Tests\Sylius\PayPalPlugin\Service\FakeCreateOrderApi |
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,30 @@ | ||
Sylius\Component\Core\Model\Order: | ||
new_cart: | ||
channel: "@channel_web" | ||
items: ["@sw_mug_item"] | ||
currencyCode: "USD" | ||
localeCode: "en_US" | ||
customer: "@customer_oliver" | ||
state: "cart" | ||
checkoutState: "shipping_selected" | ||
tokenValue: "TOKEN" | ||
payments: ["@paypal_payment"] | ||
|
||
Sylius\Component\Core\Model\OrderItem: | ||
sw_mug_item: | ||
units: ["@sw_mug_item_unit1", "@sw_mug_item_unit2"] | ||
variant: "@mug_sw" | ||
order: "@new_cart" | ||
|
||
Sylius\Component\Core\Model\OrderItemUnit: | ||
sw_mug_item_unit1: | ||
__construct: ["@sw_mug_item"] | ||
sw_mug_item_unit2: | ||
__construct: ["@sw_mug_item"] | ||
|
||
Sylius\Component\Core\Model\Payment: | ||
paypal_payment: | ||
method: "@paypal" | ||
currencyCode: "USD" | ||
amount: 40 | ||
state: "cart" |
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,30 @@ | ||
Sylius\Component\Core\Model\Order: | ||
new_order: | ||
channel: "@channel_web" | ||
items: ["@sw_mug_item"] | ||
currencyCode: "USD" | ||
localeCode: "en_US" | ||
customer: "@customer_oliver" | ||
state: "new" | ||
checkoutState: "completed" | ||
tokenValue: "TOKEN" | ||
payments: ["@paypal_payment"] | ||
|
||
Sylius\Component\Core\Model\OrderItem: | ||
sw_mug_item: | ||
units: ["@sw_mug_item_unit1", "@sw_mug_item_unit2"] | ||
variant: "@mug_sw" | ||
order: "@new_order" | ||
|
||
Sylius\Component\Core\Model\OrderItemUnit: | ||
sw_mug_item_unit1: | ||
__construct: ["@sw_mug_item"] | ||
sw_mug_item_unit2: | ||
__construct: ["@sw_mug_item"] | ||
|
||
Sylius\Component\Core\Model\Payment: | ||
paypal_payment: | ||
method: "@paypal" | ||
currencyCode: "USD" | ||
amount: 40 | ||
state: "new" |
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,111 @@ | ||
Sylius\Component\Core\Model\Product: | ||
mug: | ||
code: "MUG" | ||
channels: ["@channel_web"] | ||
currentLocale: "en_US" | ||
translations: | ||
en_US: "@mug_translation" | ||
|
||
Sylius\Component\Core\Model\ProductTranslation: | ||
mug_translation: | ||
slug: "mug" | ||
locale: "en_US" | ||
name: "Mug" | ||
description: "<paragraph(2)>" | ||
translatable: "@mug" | ||
|
||
Sylius\Component\Core\Model\ProductVariant: | ||
mug_sw: | ||
code: "MUG_SW" | ||
product: "@mug" | ||
currentLocale: "en_US" | ||
translations: | ||
en_US: "@sw_mug_translation" | ||
updatedAt: "<(new \\DateTime('2015-10-10'))>" | ||
channelPricings: | ||
WEB: "@sw_mug_web_channel_pricing" | ||
mug_lotr: | ||
code: "MUG_LOTR" | ||
product: "@mug" | ||
currentLocale: "en_US" | ||
translations: | ||
en_US: "@lotr_mug_translation" | ||
updatedAt: "<(new \\DateTime('2015-10-04'))>" | ||
channelPricings: | ||
WEB: "@lotr_mug_web_channel_pricing" | ||
|
||
Sylius\Component\Product\Model\ProductVariantTranslation: | ||
sw_mug_translation: | ||
locale: "en_US" | ||
name: "Star wars mug" | ||
translatable: "@mug_sw" | ||
lotr_mug_translation: | ||
locale: "en_US" | ||
name: "Lotr mug" | ||
translatable: "@mug_lotr" | ||
|
||
Sylius\Component\Core\Model\Channel: | ||
channel_web: | ||
code: "WEB" | ||
name: "Web Channel" | ||
hostname: "localhost" | ||
description: "Lorem ipsum" | ||
baseCurrency: "@currency" | ||
defaultLocale: "@locale" | ||
locales: ["@locale"] | ||
color: "black" | ||
enabled: true | ||
taxCalculationStrategy: "order_items_based" | ||
|
||
Sylius\Component\Currency\Model\Currency: | ||
currency: | ||
code: "USD" | ||
|
||
Sylius\Component\Locale\Model\Locale: | ||
locale: | ||
code: "en_US" | ||
|
||
Sylius\Component\Core\Model\Customer: | ||
customer_oliver: | ||
firstName: "Oliver" | ||
lastName: "Queen" | ||
email: "[email protected]" | ||
emailCanonical: "[email protected]" | ||
birthday: "<(new \\DateTime())>" | ||
|
||
Sylius\Component\Core\Model\ChannelPricing: | ||
sw_mug_web_channel_pricing: | ||
channelCode: "WEB" | ||
price: 20 | ||
lotr_mug_web_channel_pricing: | ||
channelCode: "WEB" | ||
price: 20 | ||
|
||
Sylius\Component\Core\Model\PaymentMethod: | ||
paypal: | ||
code: PAYPAL | ||
enabled: true | ||
gatewayConfig: "@paypal_config" | ||
currentLocale: en_US | ||
translations: | ||
- "@paypal_translation" | ||
channels: ["@channel_web"] | ||
|
||
Sylius\Bundle\PayumBundle\Model\GatewayConfig: | ||
paypal_config: | ||
gatewayName: "paypal" | ||
factoryName: "sylius.pay_pal" | ||
config: | ||
client_id: "CLIENT_ID" | ||
client_secret: "CLIENT_SECRET" | ||
merchant_id: "MERCHANT_ID" | ||
sylius_merchant_id: "SYLIUS_MERCHANT_ID" | ||
partner_attribution_id: "PARTNER_ATTRIBUTION_ID" | ||
use_authorize: true | ||
|
||
Sylius\Component\Payment\Model\PaymentMethodTranslation: | ||
paypal_translation: | ||
name: "PayPal" | ||
locale: "en_US" | ||
description: <paragraph(2)> | ||
translatable: "@paypal" |
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,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Sylius\PayPalPlugin\Functional; | ||
|
||
use ApiTestCase\JsonApiTestCase; | ||
|
||
final class CreatePayPalOrderActionTest extends JsonApiTestCase | ||
{ | ||
/** @test */ | ||
function it_creates_pay_pal_order_and_returns_its_data(): void | ||
{ | ||
$this->loadFixturesFromFiles(['resources/shop.yaml', 'resources/new_order.yaml']); | ||
|
||
$this->client->request('POST', '/en_US/create-pay-pal-order/TOKEN'); | ||
|
||
$response = $this->client->getResponse(); | ||
$content = (array) json_decode($response->getContent(), true); | ||
|
||
$this->assertSame($content['orderID'], 'PAYPAL_ORDER_ID'); | ||
$this->assertSame($content['status'], 'processing'); | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Sylius\PayPalPlugin\Functional; | ||
|
||
use ApiTestCase\JsonApiTestCase; | ||
|
||
final class CreatePayPalOrderFromCartActionTest extends JsonApiTestCase | ||
{ | ||
/** @test */ | ||
function it_creates_pay_pal_order_from_cart_and_returns_its_data(): void | ||
{ | ||
$order = $this->loadFixturesFromFiles(['resources/shop.yaml', 'resources/new_cart.yaml']); | ||
/** @var int $orderId */ | ||
$orderId = $order['new_cart']->getId(); | ||
|
||
$this->client->request('POST', '/en_US/create-pay-pal-order-from-cart/' . $orderId); | ||
|
||
$response = $this->client->getResponse(); | ||
$content = (array) json_decode($response->getContent(), true); | ||
|
||
$this->assertSame($content['id'], $orderId); | ||
$this->assertSame($content['orderID'], 'PAYPAL_ORDER_ID'); | ||
$this->assertSame($content['status'], 'cart'); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
tests/Functional/CreatePayPalOrderFromPaymentPageActionTest.php
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,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Sylius\PayPalPlugin\Functional; | ||
|
||
use ApiTestCase\JsonApiTestCase; | ||
|
||
final class CreatePayPalOrderFromPaymentPageActionTest extends JsonApiTestCase | ||
{ | ||
/** @test */ | ||
function it_creates_pay_pal_order_from_payment_page_and_returns_its_data(): void | ||
{ | ||
$order = $this->loadFixturesFromFiles(['resources/shop.yaml', 'resources/new_cart.yaml']); | ||
/** @var int $orderId */ | ||
$orderId = $order['new_cart']->getId(); | ||
|
||
$this->client->request('POST', '/en_US/pay-pal-order-payment-page/' . $orderId . '/create'); | ||
|
||
$response = $this->client->getResponse(); | ||
$content = (array) json_decode($response->getContent(), true); | ||
|
||
$this->assertSame($content['order_id'], 'PAYPAL_ORDER_ID'); | ||
} | ||
} |
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
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
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
Oops, something went wrong.