Skip to content

Commit

Permalink
Add test for 0.00 total cart
Browse files Browse the repository at this point in the history
  • Loading branch information
arti0090 committed Oct 29, 2024
1 parent 115d257 commit fc09278
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{% set payment = order.lastCartPayment() %}

{# >>> SyliusTpayPlugin customization #}
{% if payment is not null %}
{% set payment_type = cw_tpay_get_gateway_config_value(payment.method.gatewayConfig, 'type') %}
{% else %}
{% if payment is null %}
{% set payment_type = null %}
{% else %}
{% set payment_type = cw_tpay_get_gateway_config_value(payment.method.gatewayConfig, 'type') %}
{% endif %}

{% if payment_type in ['apple_pay', 'google_pay'] %}
Expand Down
39 changes: 39 additions & 0 deletions tests/E2E/Checkout/FreePaymentCheckoutTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace E2E\Checkout;

use Tests\CommerceWeavers\SyliusTpayPlugin\E2E\E2ETestCase;
use Tests\CommerceWeavers\SyliusTpayPlugin\E2E\Helper\Account\LoginShopUserTrait;
use Tests\CommerceWeavers\SyliusTpayPlugin\E2E\Helper\Order\CartTrait;
use Tests\CommerceWeavers\SyliusTpayPlugin\E2E\Helper\Order\TpayTrait;

final class FreePaymentCheckoutTest extends E2ETestCase
{
use CartTrait;
use TpayTrait;
use LoginShopUserTrait;

private const FORM_ID = 'sylius_checkout_complete';

protected function setUp(): void
{
parent::setUp();

$this->loadFixtures(['addressed_free_cart.yaml']);

$this->loginShopUser('[email protected]', 'sylius');
// the cart is already addressed, so we go straight to selecting a shipping method
$this->showSelectingShippingMethodStep();
$this->processWithDefaultShippingMethod();
}

public function test_it_completes_the_checkout_if_order_total_is_0(): void
{
// total is 0.00 so we do not choose payment method and go straight to complete
$this->placeOrder();

$this->assertPageTitleContains('Thank you!');
}
}
109 changes: 109 additions & 0 deletions tests/E2E/Resources/fixtures/addressed_free_cart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
include:
- common/channel.yaml
- common/country.yaml
- common/customer.yaml
- common/payment_method.yaml
- common/shipping_category.yaml
- free_shipping_method.yaml
- common/tax_category.yaml

Sylius\Component\Core\Model\Product:
product:
fallbackLocale: en_US
currentLocale: en
code: 'MUG_SW'
translations:
- '@product_translation'

Sylius\Component\Core\Model\ProductTranslation:
product_translation:
name: 'Mug'
slug: 'mug'
locale: 'en_US'
translatable: '@product'

Sylius\Component\Product\Model\ProductVariantTranslation:
product_variant_translation:
name: 'Mug'
locale: en_US
translatable: '@product_variant'

Sylius\Component\Core\Model\ProductVariant:
product_variant:
code: 'MUG'
version: 1
product: '@product'
fallbackLocale: en_US
currentLocale: en
position: 1
optionValues: ['@product_option_value_color_blue']
channelPricings:
channel_web: '@product_variant_channel_web_pricing'
translations:
- '@product_variant_translation'
enabled: true
tracked: true
onHold: 0
onHand: 10
weight: 100.50
width: 100.50
height: 100.50
depth: 100.50
taxCategory: '@tax_category_default'
shippingCategory: '@shipping_category_default'
shippingRequired: true

Sylius\Component\Core\Model\ChannelPricing:
product_variant_channel_web_pricing:
channelCode: 'WEB'
price: 00

Sylius\Component\Product\Model\ProductOption:
product_option_color:
code: 'COLOR'
currentLocale: 'en_US'
translations:
- '@product_option_translation_en_EN'

Sylius\Component\Product\Model\ProductOptionTranslation:
product_option_translation_en_EN:
locale: 'en_US'
name: 'Color'
translatable: '@product_option_color'

Sylius\Component\Product\Model\ProductOptionValue:
product_option_value_color_blue:
code: 'COLOR_BLUE'
currentLocale: 'en_US'
fallbackLocale: 'en_US'
option: '@product_option_color'
translations:
- '@product_option_value_translation_blue'

Sylius\Component\Product\Model\ProductOptionValueTranslation:
product_option_value_translation_blue:
locale: 'en_US'
value: 'Blue'
translatable: '@product_option_value_color_blue'

App\Entity\Order:
addressed_cart:
channel: '@channel_web'
currencyCode: 'USD'
localeCode: 'en_US'
customer: '@customer_tony'
state: 'cart'
checkoutState: 'addressed'
createdByGuest: false
shippingAddress: '@address_tony'
billingAddress: '@address_tony'
__calls:
- addItem: ["@order_item"]

Sylius\Component\Core\Model\OrderItem:
order_item:
variant: '@product_variant'

Sylius\Component\Core\Model\OrderItemUnit:
order_item_unit:
__construct: ['@order_item']
32 changes: 32 additions & 0 deletions tests/E2E/Resources/fixtures/free_shipping_method.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Sylius\Component\Core\Model\ShippingMethod:
shipping_method_free:
code: 'FREE'
enabled: true
calculator: 'flat_rate'
configuration:
WEB:
amount: 00
MOBILE:
amount: 00
zone: '@zone_world'
currentLocale: 'en_US'
translations: ["@shipping_method_translation_free"]
channels: ["@channel_web"]

Sylius\Component\Shipping\Model\ShippingMethodTranslation:
shipping_method_translation_free:
name: 'FREE'
locale: 'en_US'
description: '<paragraph(2)>'
translatable: '@shipping_method_free'

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']
1 change: 0 additions & 1 deletion tests/Unit/ContextProvider/BankListContextProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,4 @@ private function createTestObject(): BankListContextProvider
{
return new BankListContextProvider($this->bankListProvider->reveal());
}

}

0 comments on commit fc09278

Please sign in to comment.