-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test for order creation with free transport/payment promo code
- Loading branch information
1 parent
095688a
commit 266a12d
Showing
4 changed files
with
85 additions
and
88 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 |
---|---|---|
|
@@ -36,21 +36,22 @@ class OrderWithPromoCodeTest extends GraphQlTestCase | |
*/ | ||
private PromoCodeDataFactory $promoCodeDataFactory; | ||
|
||
public function testCreateOrderWithPromoCode() | ||
private const array DEFAULT_ORDER_INPUT_VALUES = [ | ||
'firstName' => 'firstName', | ||
'lastName' => 'lastName', | ||
'email' => '[email protected]', | ||
'telephone' => '+53 123456789', | ||
'onCompanyBehalf' => false, | ||
'street' => '123 Fake Street', | ||
'city' => 'Springfield', | ||
'postcode' => '12345', | ||
'country' => 'CZ', | ||
'isDeliveryAddressDifferentFromBilling' => false, | ||
]; | ||
|
||
public function testCreateOrderWithPromoCode(): void | ||
{ | ||
$expectedOrderItems = $this->getExpectedOrderItems(); | ||
$expected = [ | ||
'data' => [ | ||
'CreateOrder' => [ | ||
'orderCreated' => true, | ||
'order' => [ | ||
'totalPrice' => $this->getSerializedOrderTotalPriceByExpectedOrderItems($expectedOrderItems), | ||
'items' => $expectedOrderItems, | ||
], | ||
'cart' => null, | ||
], | ||
], | ||
]; | ||
$cartUuid = $this->addProductToCart(); | ||
$this->addCzechPostTransportToCart($cartUuid); | ||
$this->addCashOnDeliveryPaymentToCart($cartUuid); | ||
|
@@ -59,7 +60,12 @@ public function testCreateOrderWithPromoCode() | |
|
||
$this->applyPromoCode($cartUuid, $validPromoCode->getCode()); | ||
|
||
$this->assertQueryWithExpectedArray($this->getMutation($cartUuid), $expected); | ||
$responseData = $this->createOrderAndGetResponseData($cartUuid); | ||
|
||
$this->assertTrue($responseData['orderCreated']); | ||
$this->assertSame(self::getSerializedOrderTotalPriceByExpectedOrderItems($expectedOrderItems), $responseData['order']['totalPrice']); | ||
$this->assertSame($expectedOrderItems, $responseData['order']['items']); | ||
$this->assertNull($responseData['cart']); | ||
} | ||
|
||
public function testCreateOrderWithInvalidPromoCode(): void | ||
|
@@ -77,21 +83,31 @@ public function testCreateOrderWithInvalidPromoCode(): void | |
|
||
$this->promoCodeFacade->edit($validPromoCode->getId(), $promoCodeData); | ||
|
||
$mutation = $this->getMutation($cartUuid); | ||
$response = $this->getResponseContentForQuery($mutation); | ||
|
||
$this->assertArrayHasKey('data', $response); | ||
$this->assertArrayHasKey('CreateOrder', $response['data']); | ||
$this->assertArrayHasKey('orderCreated', $response['data']['CreateOrder']); | ||
$this->assertFalse($response['data']['CreateOrder']['orderCreated']); | ||
$this->assertArrayHasKey('cart', $response['data']['CreateOrder']); | ||
$this->assertArrayHasKey('promoCode', $response['data']['CreateOrder']['cart']); | ||
$this->assertNull($response['data']['CreateOrder']['cart']['promoCode']); | ||
$this->assertArrayHasKey('modifications', $response['data']['CreateOrder']['cart']); | ||
$this->assertArrayHasKey('promoCodeModifications', $response['data']['CreateOrder']['cart']['modifications']); | ||
$this->assertArrayHasKey('noLongerApplicablePromoCode', $response['data']['CreateOrder']['cart']['modifications']['promoCodeModifications']); | ||
$this->assertCount(1, $response['data']['CreateOrder']['cart']['modifications']['promoCodeModifications']['noLongerApplicablePromoCode']); | ||
$this->assertEquals('test', $response['data']['CreateOrder']['cart']['modifications']['promoCodeModifications']['noLongerApplicablePromoCode'][0]); | ||
$responseData = $this->createOrderAndGetResponseData($cartUuid); | ||
|
||
$this->assertArrayHasKey('orderCreated', $responseData); | ||
$this->assertFalse($responseData['orderCreated']); | ||
$this->assertArrayHasKey('cart', $responseData); | ||
$this->assertArrayHasKey('promoCode', $responseData['cart']); | ||
$this->assertNull($responseData['cart']['promoCode']); | ||
$this->assertArrayHasKey('modifications', $responseData['cart']); | ||
$this->assertArrayHasKey('promoCodeModifications', $responseData['cart']['modifications']); | ||
$this->assertArrayHasKey('noLongerApplicablePromoCode', $responseData['cart']['modifications']['promoCodeModifications']); | ||
$this->assertCount(1, $responseData['cart']['modifications']['promoCodeModifications']['noLongerApplicablePromoCode']); | ||
$this->assertEquals('test', $responseData['cart']['modifications']['promoCodeModifications']['noLongerApplicablePromoCode'][0]); | ||
} | ||
|
||
public function testOrderWithFreeTransportAndPaymentPromoCode(): void | ||
{ | ||
$cartUuid = $this->addProductToCart(); | ||
$freeTransportAndPaymentPromoCode = $this->getReferenceForDomain(PromoCodeDataFixture::PROMO_CODE_FOR_FREE_TRANSPORT_PAYMENT, 1, PromoCode::class); | ||
$this->addCzechPostTransportToCart($cartUuid); | ||
$this->addCashOnDeliveryPaymentToCart($cartUuid); | ||
$this->applyPromoCode($cartUuid, $freeTransportAndPaymentPromoCode->getCode()); | ||
|
||
$responseData = $this->createOrderAndGetResponseData($cartUuid); | ||
|
||
$this->assertTransportAndPaymentItemsAreFree($responseData); | ||
} | ||
|
||
/** | ||
|
@@ -155,67 +171,16 @@ protected function getExpectedOrderItems(): array | |
|
||
/** | ||
* @param string $cartUuid | ||
* @return string | ||
* @return array | ||
*/ | ||
private function getMutation(string $cartUuid): string | ||
private function createOrderAndGetResponseData(string $cartUuid): array | ||
{ | ||
return 'mutation { | ||
CreateOrder( | ||
input: { | ||
cartUuid: "' . $cartUuid . '" | ||
firstName: "firstName" | ||
lastName: "lastName" | ||
email: "[email protected]" | ||
telephone: "+53 123456789" | ||
onCompanyBehalf: false | ||
street: "123 Fake Street" | ||
city: "Springfield" | ||
postcode: "12345" | ||
country: "CZ" | ||
isDeliveryAddressDifferentFromBilling: false | ||
} | ||
) { | ||
orderCreated | ||
order { | ||
totalPrice { | ||
priceWithVat | ||
priceWithoutVat | ||
vatAmount | ||
} | ||
items { | ||
name | ||
unitPrice { | ||
priceWithVat | ||
priceWithoutVat | ||
vatAmount | ||
} | ||
totalPrice { | ||
priceWithVat | ||
priceWithoutVat | ||
vatAmount | ||
} | ||
quantity | ||
vatRate | ||
unit | ||
type | ||
product { | ||
uuid | ||
} | ||
} | ||
} | ||
cart { | ||
promoCode { | ||
code | ||
type | ||
} | ||
modifications { | ||
promoCodeModifications { | ||
noLongerApplicablePromoCode | ||
} | ||
} | ||
} | ||
} | ||
}'; | ||
$response = $this->getResponseContentForGql(__DIR__ . '/graphql/CreateMinimalOrderMutation.graphql', [ | ||
'cartUuid' => $cartUuid, | ||
...self::DEFAULT_ORDER_INPUT_VALUES, | ||
]); | ||
|
||
return $this->getResponseDataForGraphQlType($response, 'CreateOrder'); | ||
} | ||
|
||
/** | ||
|
@@ -260,4 +225,20 @@ private function addProductToCart(): string | |
|
||
return $response['data']['AddToCart']['cart']['uuid']; | ||
} | ||
|
||
/** | ||
* @param array $responseData | ||
*/ | ||
private function assertTransportAndPaymentItemsAreFree(array $responseData): void | ||
{ | ||
foreach ($responseData['order']['items'] as $item) { | ||
if ($item['type'] === OrderItemTypeEnum::TYPE_TRANSPORT || $item['type'] === OrderItemTypeEnum::TYPE_PAYMENT) { | ||
$this->assertSame( | ||
$this->getFormattedMoneyAmountConvertedToDomainDefaultCurrency('0'), | ||
$item['totalPrice']['priceWithVat'], | ||
sprintf('Total price of %s should be zero', $item['type']), | ||
); | ||
} | ||
} | ||
} | ||
} |
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