Skip to content

Commit 0c55f9c

Browse files
authored
ENGCOM-4493: 420 test coverage get available payment methods guest #450
2 parents 706a4da + 7a70f5c commit 0c55f9c

File tree

1 file changed

+67
-15
lines changed

1 file changed

+67
-15
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailablePaymentMethodsTest.php

Lines changed: 67 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,8 @@ protected function setUp()
4949
*/
5050
public function testGetCartWithPaymentMethods()
5151
{
52-
$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address');
53-
54-
$query = <<<QUERY
55-
{
56-
cart(cart_id: "$maskedQuoteId") {
57-
available_payment_methods {
58-
code
59-
title
60-
}
61-
}
62-
}
63-
QUERY;
52+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_with_simple_product_without_address');
53+
$query = $this->getQuery($maskedQuoteId);
6454
$response = $this->graphQlQuery($query);
6555

6656
self::assertArrayHasKey('cart', $response);
@@ -73,16 +63,78 @@ public function testGetCartWithPaymentMethods()
7363
'No Payment Information Required',
7464
$response['cart']['available_payment_methods'][1]['title']
7565
);
66+
self::assertGreaterThan(
67+
0,
68+
count($response['cart']['available_payment_methods']),
69+
'There are no available payment methods for guest cart!'
70+
);
71+
}
72+
73+
/**
74+
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
75+
*/
76+
public function testGetPaymentMethodsFromCustomerCart()
77+
{
78+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_1');
79+
$query = $this->getQuery($maskedQuoteId);
80+
81+
$this->expectExceptionMessage(
82+
"The current user cannot perform operations on cart \"$maskedQuoteId\""
83+
);
84+
$this->graphQlQuery($query);
85+
}
86+
87+
/**
88+
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
89+
* @magentoApiDataFixture Magento/Payment/_files/disable_all_active_payment_methods.php
90+
*/
91+
public function testGetPaymentMethodsIfPaymentsAreNotSet()
92+
{
93+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_with_simple_product_without_address');
94+
$query = $this->getQuery($maskedQuoteId);
95+
$response = $this->graphQlQuery($query);
96+
97+
self::assertEquals(0, count($response['cart']['available_payment_methods']));
98+
}
99+
100+
/**
101+
* @expectedException \Exception
102+
* @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id"
103+
*/
104+
public function testGetPaymentMethodsOfNonExistentCart()
105+
{
106+
$maskedQuoteId = 'non_existent_masked_id';
107+
$query = $this->getQuery($maskedQuoteId);
108+
$this->graphQlQuery($query);
109+
}
110+
111+
/**
112+
* @param string $maskedQuoteId
113+
* @return string
114+
*/
115+
private function getQuery(
116+
string $maskedQuoteId
117+
): string {
118+
return <<<QUERY
119+
{
120+
cart(cart_id: "$maskedQuoteId") {
121+
available_payment_methods {
122+
code
123+
title
124+
}
125+
}
126+
}
127+
QUERY;
76128
}
77129

78130
/**
79-
* @param string $reversedQuoteId
131+
* @param string $reservedOrderId
80132
* @return string
81133
*/
82-
private function getMaskedQuoteIdByReversedQuoteId(string $reversedQuoteId): string
134+
private function getMaskedQuoteIdByReservedOrderId(string $reservedOrderId): string
83135
{
84136
$quote = $this->quoteFactory->create();
85-
$this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id');
137+
$this->quoteResource->load($quote, $reservedOrderId, 'reserved_order_id');
86138

87139
return $this->quoteIdToMaskedId->execute((int)$quote->getId());
88140
}

0 commit comments

Comments
 (0)