Skip to content

Commit 5b85e5d

Browse files
committed
GraphQL-571: [Checkout Coverage] Place order for guest
1 parent b307f7a commit 5b85e5d

File tree

5 files changed

+128
-68
lines changed

5 files changed

+128
-68
lines changed

app/code/Magento/QuoteGraphQl/Model/Resolver/SetGuestEmailOnCart.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
8282
return [
8383
'cart' => [
8484
'model' => $cart,
85-
'guest_email' => $guestEmail
8685
],
8786
];
8887
}

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,24 @@ public function testSetBillingAddressWithoutRequiredParameters(string $input, st
493493
$this->graphQlMutation($query);
494494
}
495495

496+
/**
497+
* @return array
498+
*/
499+
public function dataProviderSetWithoutRequiredParameters(): array
500+
{
501+
return [
502+
'missed_billing_address' => [
503+
'cart_id: "cart_id_value"',
504+
'Field SetBillingAddressOnCartInput.billing_address of required type BillingAddressInput!'
505+
. ' was not provided.',
506+
],
507+
'missed_cart_id' => [
508+
'billing_address: {}',
509+
'Required parameter "cart_id" is missing'
510+
]
511+
];
512+
}
513+
496514
/**
497515
* @magentoApiDataFixture Magento/Customer/_files/customer.php
498516
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
@@ -536,24 +554,6 @@ public function testSetNewBillingAddressWithRedundantStreetLine()
536554
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
537555
}
538556

539-
/**
540-
* @return array
541-
*/
542-
public function dataProviderSetWithoutRequiredParameters(): array
543-
{
544-
return [
545-
'missed_billing_address' => [
546-
'cart_id: "cart_id_value"',
547-
'Field SetBillingAddressOnCartInput.billing_address of required type BillingAddressInput!'
548-
. ' was not provided.',
549-
],
550-
'missed_cart_id' => [
551-
'billing_address: {}',
552-
'Required parameter "cart_id" is missing'
553-
]
554-
];
555-
}
556-
557557
/**
558558
* Verify the all the whitelisted fields for a New Address Object
559559
*

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetGuestEmailOnCartTest.php

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,36 @@ protected function setUp()
3535
}
3636

3737
/**
38-
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
38+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
39+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
40+
*
41+
* @expectedException \Exception
42+
* @expectedExceptionMessage The request is not allowed for logged in customers
3943
*/
4044
public function testSetGuestEmailOnCartForLoggedInCustomer()
4145
{
42-
$reservedOrderId = 'test_order_1';
46+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
47+
$email = '[email protected]';
48+
49+
$query = $this->getQuery($maskedQuoteId, $email);
50+
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
51+
}
52+
53+
/**
54+
* _security
55+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
56+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
57+
*
58+
* @expectedException \Exception
59+
* @expectedExceptionMessage The request is not allowed for logged in customers
60+
*/
61+
public function testSetGuestEmailOnGuestCart()
62+
{
63+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
4364
$email = '[email protected]';
44-
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedOrderId);
4565

46-
$query = $this->getSetGuestEmailOnCartMutation($maskedQuoteId, $email);
47-
$this->expectExceptionMessage('The request is not allowed for logged in customers');
48-
$this->graphQlQuery($query, [], '', $this->getHeaderMap());
66+
$query = $this->getQuery($maskedQuoteId, $email);
67+
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
4968
}
5069

5170
/**
@@ -55,12 +74,12 @@ public function testSetGuestEmailOnCartForLoggedInCustomer()
5574
* @param string $email
5675
* @return string
5776
*/
58-
private function getSetGuestEmailOnCartMutation(string $maskedQuoteId, string $email): string
77+
private function getQuery(string $maskedQuoteId, string $email): string
5978
{
6079
return <<<QUERY
6180
mutation {
6281
setGuestEmailOnCart(input: {
63-
cart_id:"$maskedQuoteId"
82+
cart_id: "$maskedQuoteId"
6483
email: "$email"
6584
}) {
6685
cart {

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,24 @@ public function testSetBillingAddressWithoutRequiredParameters(string $input, st
313313
$this->graphQlMutation($query);
314314
}
315315

316+
/**
317+
* @return array
318+
*/
319+
public function dataProviderSetWithoutRequiredParameters(): array
320+
{
321+
return [
322+
'missed_billing_address' => [
323+
'cart_id: "cart_id_value"',
324+
'Field SetBillingAddressOnCartInput.billing_address of required type BillingAddressInput!'
325+
. ' was not provided.',
326+
],
327+
'missed_cart_id' => [
328+
'billing_address: {}',
329+
'Required parameter "cart_id" is missing'
330+
]
331+
];
332+
}
333+
316334
/**
317335
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
318336
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
@@ -356,24 +374,6 @@ public function testSetNewBillingAddressRedundantStreetLine()
356374
$this->graphQlMutation($query);
357375
}
358376

359-
/**
360-
* @return array
361-
*/
362-
public function dataProviderSetWithoutRequiredParameters(): array
363-
{
364-
return [
365-
'missed_billing_address' => [
366-
'cart_id: "cart_id_value"',
367-
'Field SetBillingAddressOnCartInput.billing_address of required type BillingAddressInput!'
368-
. ' was not provided.',
369-
],
370-
'missed_cart_id' => [
371-
'billing_address: {}',
372-
'Required parameter "cart_id" is missing'
373-
]
374-
];
375-
}
376-
377377
/**
378378
* Verify the all the whitelisted fields for a New Address Object
379379
*

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

Lines changed: 65 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,67 +28,109 @@ protected function setUp()
2828
}
2929

3030
/**
31-
* @magentoApiDataFixture Magento/Quote/_files/empty_quote.php
31+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
3232
*/
3333
public function testSetGuestEmailOnCart()
3434
{
35-
$reservedOrderId = 'reserved_order_id';
35+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
3636
$email = '[email protected]';
37-
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedOrderId);
3837

39-
$query = $this->getSetGuestEmailOnCartMutation($maskedQuoteId, $email);
40-
$response = $this->graphQlQuery($query);
38+
$query = $this->getQuery($maskedQuoteId, $email);
39+
$response = $this->graphQlMutation($query);
4140

4241
$this->assertArrayHasKey('setGuestEmailOnCart', $response);
4342
$this->assertArrayHasKey('cart', $response['setGuestEmailOnCart']);
4443
$this->assertEquals($email, $response['setGuestEmailOnCart']['cart']['guest_email']);
4544
}
4645

4746
/**
48-
* @magentoApiDataFixture Magento/Quote/_files/empty_quote.php
49-
* @dataProvider incorrectInputDataProvider
50-
* @param string|null $maskedQuoteId
47+
* _security
48+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
49+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
50+
*/
51+
public function testSetGuestEmailOnCustomerCart()
52+
{
53+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
54+
$email = '[email protected]';
55+
56+
$query = $this->getQuery($maskedQuoteId, $email);
57+
58+
$this->expectExceptionMessage(
59+
"The current user cannot perform operations on cart \"$maskedQuoteId\""
60+
);
61+
$this->graphQlMutation($query);
62+
}
63+
64+
/**
65+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
66+
*
67+
* @dataProvider incorrectEmailDataProvider
68+
* @param string $maskedQuoteId
5169
* @param string $email
5270
* @param string $exceptionMessage
5371
*/
54-
public function testSetGuestEmailOnCartWithIncorrectInputData(
55-
?string $maskedQuoteId,
72+
public function testSetGuestEmailOnCartWithIncorrectEmail(
73+
string $maskedQuoteId,
5674
string $email,
5775
string $exceptionMessage
5876
) {
59-
if (null === $maskedQuoteId) { // Generate ID in case if no provided by data provider
60-
$reservedOrderId = 'reserved_order_id';
61-
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedOrderId);
62-
}
77+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($maskedQuoteId);
6378

64-
$query = $this->getSetGuestEmailOnCartMutation($maskedQuoteId, $email);
79+
$query = $this->getQuery($maskedQuoteId, $email);
6580
$this->expectExceptionMessage($exceptionMessage);
66-
$this->graphQlQuery($query);
81+
$this->graphQlMutation($query);
6782
}
6883

69-
public function incorrectInputDataProvider(): array
84+
/**
85+
* @return array
86+
*/
87+
public function incorrectEmailDataProvider(): array
7088
{
7189
return [
72-
'wrong_email' => [null, 'some', 'Invalid email format'],
73-
'no_email' => [null, '', 'Required parameter "email" is missing'],
74-
'wrong_quote_id' => ['xxx', '[email protected]', 'Could not find a cart with ID "xxx"'],
75-
'no_quote_id' => ['', '[email protected]', 'Required parameter "cart_id" is missing']
90+
'wrong_email' => ['test_quote', 'some', 'Invalid email format'],
91+
'no_email' => ['test_quote', '', 'Required parameter "email" is missing'],
7692
];
7793
}
7894

95+
/**
96+
* @expectedException \Exception
97+
* @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id"
98+
*/
99+
public function testSetGuestEmailOnNonExistentCart()
100+
{
101+
$maskedQuoteId = 'non_existent_masked_id';
102+
$email = '[email protected]';
103+
104+
$query = $this->getQuery($maskedQuoteId, $email);
105+
$this->graphQlMutation($query);
106+
}
107+
108+
/**
109+
* @expectedException \Exception
110+
* @expectedExceptionMessage Required parameter "cart_id" is missing
111+
*/
112+
public function testSetGuestEmailWithEmptyCartId()
113+
{
114+
$maskedQuoteId = '';
115+
$email = '[email protected]';
116+
117+
$query = $this->getQuery($maskedQuoteId, $email);
118+
$this->graphQlMutation($query);
119+
}
120+
79121
/**
80122
* Returns GraphQl mutation query for setting email address for a guest
81123
*
82124
* @param string $maskedQuoteId
83125
* @param string $email
84126
* @return string
85127
*/
86-
private function getSetGuestEmailOnCartMutation(string $maskedQuoteId, string $email): string
128+
private function getQuery(string $maskedQuoteId, string $email): string
87129
{
88130
return <<<QUERY
89131
mutation {
90132
setGuestEmailOnCart(input: {
91-
cart_id:"$maskedQuoteId"
133+
cart_id: "$maskedQuoteId"
92134
email: "$email"
93135
}) {
94136
cart {

0 commit comments

Comments
 (0)