Skip to content

Commit

Permalink
Merge pull request #1167 from PrestaShopCorp/refacto/sdk-parameters-b…
Browse files Browse the repository at this point in the history
…ackend-usecases

Adding more ECM usecases
  • Loading branch information
btafforeau authored Nov 29, 2023
2 parents 98f831d + f881e6b commit aa198b3
Show file tree
Hide file tree
Showing 9 changed files with 926 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use PrestaShop\Module\PrestashopCheckout\PaymentSource\PaymentSource;
use PrestaShop\Module\PrestashopCheckout\PaymentSource\PaymentSourceUseCase;

class PaymentSourceTest extends TestCase
class BancontactPaymentSourceTest extends TestCase
{
/**
* @dataProvider invalidBancontactDataProvider
Expand All @@ -38,8 +38,6 @@ public function testInvalidBancontactPaymentSource($data)
)
]
);


}

public function invalidBancontactDataProvider()
Expand Down Expand Up @@ -80,7 +78,7 @@ public function invalidBancontactDataProvider()
'amount' => '39.99',
'buyerCountry' => 'BE',
'currency' => 'EUR',
'intent' => 'VALIDATE', // Invalid intent
'intent' => 'AUTHORIZE', // Invalid intent
'merchantCountry' => 'FR',
'pageType' => 'checkout'
],
Expand Down
108 changes: 108 additions & 0 deletions tests/Unit/PaymentSource/BlikPaymentSourceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php

namespace Tests\Unit\Amount;

use PHPUnit\Framework\TestCase;
use PrestaShop\Module\PrestashopCheckout\PaymentSource\EligibilityRule\AmountEligibilityRule;
use PrestaShop\Module\PrestashopCheckout\PaymentSource\EligibilityRule\CountryEligibilityRule;
use PrestaShop\Module\PrestashopCheckout\PaymentSource\EligibilityRule\CurrencyEligibilityRule;
use PrestaShop\Module\PrestashopCheckout\PaymentSource\EligibilityRule\ExcludedCountryEligibilityRule;
use PrestaShop\Module\PrestashopCheckout\PaymentSource\EligibilityRule\IntentEligibilityRule;
use PrestaShop\Module\PrestashopCheckout\PaymentSource\EligibilityRule\PageTypeEligibilityRule;
use PrestaShop\Module\PrestashopCheckout\PaymentSource\PaymentSource;
use PrestaShop\Module\PrestashopCheckout\PaymentSource\PaymentSourceUseCase;

class BlikPaymentSourceTest extends TestCase
{
/**
* @dataProvider invalidBlikDataProvider
*/
public function testInvalidBlikPaymentSource($data)
{
$paymentSource = new PaymentSource(
'blik',
'Blik',
[
new AmountEligibilityRule($data['amount'], '1'),
new CountryEligibilityRule($data['buyerCountry'], ['PL']),
new CurrencyEligibilityRule($data['currency'], ['PLN']),
new ExcludedCountryEligibilityRule($data['merchantCountry'], ['RU', 'JP', 'BR']),
],
[
new PaymentSourceUseCase(
'ECM',
[
new IntentEligibilityRule($data['intent'], ['CAPTURE']),
new PageTypeEligibilityRule($data['pageType'], ['checkout'])
]
)
]
);
}

public function invalidBlikDataProvider()
{
return [
[
[
'amount' => '0.99', // Invalid amount
'buyerCountry' => 'PL',
'currency' => 'PLN',
'intent' => 'CAPTURE',
'merchantCountry' => 'FR',
'pageType' => 'checkout'
],
],
[
[
'amount' => '39.99',
'buyerCountry' => 'FR', // Invalid buyer country
'currency' => 'PLN',
'intent' => 'CAPTURE',
'merchantCountry' => 'US',
'pageType' => 'checkout'
],
],
[
[
'amount' => '9.90',
'buyerCountry' => 'PL',
'currency' => 'USD', // Invalid currency
'intent' => 'CAPTURE',
'merchantCountry' => 'US',
'pageType' => 'checkout'
],
],
[
[
'amount' => '39.99',
'buyerCountry' => 'PL',
'currency' => 'PLN',
'intent' => 'AUTHORIZE', // Invalid intent
'merchantCountry' => 'FR',
'pageType' => 'checkout'
],
],
[
[
'amount' => '15',
'buyerCountry' => 'PL',
'currency' => 'PLN',
'intent' => 'CAPTURE',
'merchantCountry' => 'JP', // Invalid merchant country
'pageType' => 'checkout'
],
],
[
[
'amount' => '39.99',
'buyerCountry' => 'PL',
'currency' => 'PLN',
'intent' => 'CAPTURE',
'merchantCountry' => 'FR',
'pageType' => 'product' // Invalid pageType
],
]
];
}
}
108 changes: 108 additions & 0 deletions tests/Unit/PaymentSource/EpsPaymentSourceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php

namespace Tests\Unit\Amount;

use PHPUnit\Framework\TestCase;
use PrestaShop\Module\PrestashopCheckout\PaymentSource\EligibilityRule\AmountEligibilityRule;
use PrestaShop\Module\PrestashopCheckout\PaymentSource\EligibilityRule\CountryEligibilityRule;
use PrestaShop\Module\PrestashopCheckout\PaymentSource\EligibilityRule\CurrencyEligibilityRule;
use PrestaShop\Module\PrestashopCheckout\PaymentSource\EligibilityRule\ExcludedCountryEligibilityRule;
use PrestaShop\Module\PrestashopCheckout\PaymentSource\EligibilityRule\IntentEligibilityRule;
use PrestaShop\Module\PrestashopCheckout\PaymentSource\EligibilityRule\PageTypeEligibilityRule;
use PrestaShop\Module\PrestashopCheckout\PaymentSource\PaymentSource;
use PrestaShop\Module\PrestashopCheckout\PaymentSource\PaymentSourceUseCase;

class EpsPaymentSourceTest extends TestCase
{
/**
* @dataProvider invalidEpsDataProvider
*/
public function testInvalidEpsPaymentSource($data)
{
$paymentSource = new PaymentSource(
'eps',
'Eps',
[
new AmountEligibilityRule($data['amount'], '1'),
new CountryEligibilityRule($data['buyerCountry'], ['AT']),
new CurrencyEligibilityRule($data['currency'], ['EUR']),
new ExcludedCountryEligibilityRule($data['merchantCountry'], ['RU', 'JP', 'BR']),
],
[
new PaymentSourceUseCase(
'ECM',
[
new IntentEligibilityRule($data['intent'], ['CAPTURE']),
new PageTypeEligibilityRule($data['pageType'], ['checkout'])
]
)
]
);
}

public function invalidEpsDataProvider()
{
return [
[
[
'amount' => '0.99', // Invalid amount
'buyerCountry' => 'AT',
'currency' => 'EUR',
'intent' => 'CAPTURE',
'merchantCountry' => 'FR',
'pageType' => 'checkout'
],
],
[
[
'amount' => '39.99',
'buyerCountry' => 'FR', // Invalid buyer country
'currency' => 'EUR',
'intent' => 'CAPTURE',
'merchantCountry' => 'US',
'pageType' => 'checkout'
],
],
[
[
'amount' => '9.90',
'buyerCountry' => 'AT',
'currency' => 'USD', // Invalid currency
'intent' => 'CAPTURE',
'merchantCountry' => 'US',
'pageType' => 'checkout'
],
],
[
[
'amount' => '39.99',
'buyerCountry' => 'AT',
'currency' => 'EUR',
'intent' => 'AUTHORIZE', // Invalid intent
'merchantCountry' => 'FR',
'pageType' => 'checkout'
],
],
[
[
'amount' => '15',
'buyerCountry' => 'AT',
'currency' => 'EUR',
'intent' => 'CAPTURE',
'merchantCountry' => 'JP', // Invalid merchant country
'pageType' => 'checkout'
],
],
[
[
'amount' => '39.99',
'buyerCountry' => 'AT',
'currency' => 'EUR',
'intent' => 'CAPTURE',
'merchantCountry' => 'FR',
'pageType' => 'product' // Invalid pageType
],
]
];
}
}
108 changes: 108 additions & 0 deletions tests/Unit/PaymentSource/GiropayPaymentSourceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php

namespace Tests\Unit\Amount;

use PHPUnit\Framework\TestCase;
use PrestaShop\Module\PrestashopCheckout\PaymentSource\EligibilityRule\AmountEligibilityRule;
use PrestaShop\Module\PrestashopCheckout\PaymentSource\EligibilityRule\CountryEligibilityRule;
use PrestaShop\Module\PrestashopCheckout\PaymentSource\EligibilityRule\CurrencyEligibilityRule;
use PrestaShop\Module\PrestashopCheckout\PaymentSource\EligibilityRule\ExcludedCountryEligibilityRule;
use PrestaShop\Module\PrestashopCheckout\PaymentSource\EligibilityRule\IntentEligibilityRule;
use PrestaShop\Module\PrestashopCheckout\PaymentSource\EligibilityRule\PageTypeEligibilityRule;
use PrestaShop\Module\PrestashopCheckout\PaymentSource\PaymentSource;
use PrestaShop\Module\PrestashopCheckout\PaymentSource\PaymentSourceUseCase;

class GiropayPaymentSourceTest extends TestCase
{
/**
* @dataProvider invalidGiropayDataProvider
*/
public function testInvalidGiropayPaymentSource($data)
{
$paymentSource = new PaymentSource(
'giropay',
'Giropay',
[
new AmountEligibilityRule($data['amount'], '1'),
new CountryEligibilityRule($data['buyerCountry'], ['DE']),
new CurrencyEligibilityRule($data['currency'], ['EUR']),
new ExcludedCountryEligibilityRule($data['merchantCountry'], ['RU', 'JP', 'BR']),
],
[
new PaymentSourceUseCase(
'ECM',
[
new IntentEligibilityRule($data['intent'], ['CAPTURE']),
new PageTypeEligibilityRule($data['pageType'], ['checkout'])
]
)
]
);
}

public function invalidGiropayDataProvider()
{
return [
[
[
'amount' => '0.99', // Invalid amount
'buyerCountry' => 'DE',
'currency' => 'EUR',
'intent' => 'CAPTURE',
'merchantCountry' => 'FR',
'pageType' => 'checkout'
],
],
[
[
'amount' => '39.99',
'buyerCountry' => 'FR', // Invalid buyer country
'currency' => 'EUR',
'intent' => 'CAPTURE',
'merchantCountry' => 'US',
'pageType' => 'checkout'
],
],
[
[
'amount' => '9.90',
'buyerCountry' => 'DE',
'currency' => 'USD', // Invalid currency
'intent' => 'CAPTURE',
'merchantCountry' => 'US',
'pageType' => 'checkout'
],
],
[
[
'amount' => '39.99',
'buyerCountry' => 'DE',
'currency' => 'EUR',
'intent' => 'AUTHORIZE', // Invalid intent
'merchantCountry' => 'FR',
'pageType' => 'checkout'
],
],
[
[
'amount' => '15',
'buyerCountry' => 'DE',
'currency' => 'EUR',
'intent' => 'CAPTURE',
'merchantCountry' => 'JP', // Invalid merchant country
'pageType' => 'checkout'
],
],
[
[
'amount' => '39.99',
'buyerCountry' => 'DE',
'currency' => 'EUR',
'intent' => 'CAPTURE',
'merchantCountry' => 'FR',
'pageType' => 'product' // Invalid pageType
],
]
];
}
}
Loading

0 comments on commit aa198b3

Please sign in to comment.