Skip to content

Commit 760bc1f

Browse files
committed
LYNX-259: Updated the deprecated tests
1 parent fda4e8c commit 760bc1f

File tree

5 files changed

+10
-216
lines changed

5 files changed

+10
-216
lines changed

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,7 @@ public function __construct(
5353
}
5454

5555
/**
56-
* Creates an empty cart for guest and returns a cart object
57-
*
58-
* @param Field $field
59-
* @param $context
60-
* @param ResolveInfo $info
61-
* @param array|null $value
62-
* @param array|null $args
63-
* @return array[]
64-
* @throws GraphQlAlreadyExistsException
65-
* @throws GraphQlInputException
66-
* @throws NoSuchEntityException
56+
* @inheritdoc
6757
*/
6858
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
6959
{
@@ -80,7 +70,9 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
8070
$cartId = $this->maskedQuoteIdToQuoteId->execute($maskedQuoteId);
8171
$cart = $this->cartRepository->get($cartId);
8272
} else {
83-
throw new GraphQlAlreadyExistsException(__('Use `Query.customerCart` for logged in customer.'));
73+
throw new GraphQlAlreadyExistsException(
74+
__('Use `Query.cart` or `Query.customerCart` for logged in customer.')
75+
);
8476
}
8577

8678
return [

app/code/Magento/QuoteGraphQl/etc/schema.graphqls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type Query {
88
}
99

1010
type Mutation {
11-
createEmptyCart(input: createEmptyCartInput): String @deprecated(reason: "Use `Mutation.createGuestCart`, or `Query.customerCart` for logged in customer")
11+
createEmptyCart(input: createEmptyCartInput): String @deprecated(reason: "Use `Mutation.createGuestCart` for guest and `Query.cart` or `Query.customerCart` for logged in customer")
1212
createGuestCart(input: CreateGuestCartInput): CreateGuestCartOutput @doc(description: "Create a new shopping cart") @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\CreateGuestCart")
1313
addSimpleProductsToCart(input: AddSimpleProductsToCartInput @doc(description: "An input object that defines which simple products to add to the cart.")): AddSimpleProductsToCartOutput @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\AddSimpleProductsToCart") @doc(description:"Add one or more simple products to the specified cart. We recommend using `addProductsToCart` instead.")
1414
addVirtualProductsToCart(input: AddVirtualProductsToCartInput @doc(description: "An input object that defines which virtual products to add to the cart.")): AddVirtualProductsToCartOutput @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\AddSimpleProductsToCart") @doc(description:"Add one or more virtual products to the specified cart. We recommend using `addProductsToCart` instead.")

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

Lines changed: 2 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -58,122 +58,13 @@ protected function setUp(): void
5858
/**
5959
* @magentoApiDataFixture Magento/Customer/_files/customer.php
6060
*/
61-
public function testCreateEmptyCart()
61+
public function testDeprecatedCreateEmptyCart()
6262
{
6363
$query = $this->getQuery();
6464
$response = $this->graphQlMutation($query, [], '', $this->getHeaderMapWithCustomerToken());
6565

6666
self::assertArrayHasKey('createEmptyCart', $response);
67-
self::assertNotEmpty($response['createEmptyCart']);
68-
69-
$guestCart = $this->guestCartRepository->get($response['createEmptyCart']);
70-
71-
self::assertNotNull($guestCart->getId());
72-
self::assertEquals(1, $guestCart->getCustomer()->getId());
73-
self::assertEquals('default', $guestCart->getStore()->getCode());
74-
}
75-
76-
/**
77-
* @magentoApiDataFixture Magento/Customer/_files/customer.php
78-
*/
79-
public function testCreateEmptyMultipleRequestsCart()
80-
{
81-
$query = $this->getQuery();
82-
$response = $this->graphQlMutation($query, [], '', $this->getHeaderMapWithCustomerToken());
83-
84-
self::assertArrayHasKey('createEmptyCart', $response);
85-
self::assertNotEmpty($response['createEmptyCart']);
86-
$maskedCartId = $response['createEmptyCart'];
87-
88-
$response = $this->graphQlMutation($query, [], '', $this->getHeaderMapWithCustomerToken());
89-
self::assertArrayHasKey('createEmptyCart', $response);
90-
self::assertNotEmpty($response['createEmptyCart']);
91-
92-
self::assertEquals($maskedCartId, $response['createEmptyCart']);
93-
}
94-
95-
/**
96-
* @magentoApiDataFixture Magento/Store/_files/second_store.php
97-
* @magentoApiDataFixture Magento/Customer/_files/customer.php
98-
*/
99-
public function testCreateEmptyCartWithNotDefaultStore()
100-
{
101-
$query = $this->getQuery();
102-
103-
$headerMap = $this->getHeaderMapWithCustomerToken();
104-
$headerMap['Store'] = 'fixture_second_store';
105-
$response = $this->graphQlMutation($query, [], '', $headerMap);
106-
107-
self::assertArrayHasKey('createEmptyCart', $response);
108-
self::assertNotEmpty($response['createEmptyCart']);
109-
110-
/* guestCartRepository is used for registered customer to get the cart hash */
111-
$guestCart = $this->guestCartRepository->get($response['createEmptyCart']);
112-
113-
self::assertNotNull($guestCart->getId());
114-
self::assertEquals(1, $guestCart->getCustomer()->getId());
115-
self::assertEquals('fixture_second_store', $guestCart->getStore()->getCode());
116-
}
117-
118-
/**
119-
* @magentoApiDataFixture Magento/Customer/_files/customer.php
120-
*/
121-
public function testCreateEmptyCartWithPredefinedCartId()
122-
{
123-
$predefinedCartId = '572cda51902b5b517c0e1a2b2fd004b4';
124-
125-
$query = <<<QUERY
126-
mutation {
127-
createEmptyCart (input: {cart_id: "{$predefinedCartId}"})
128-
}
129-
QUERY;
130-
$response = $this->graphQlMutation($query, [], '', $this->getHeaderMapWithCustomerToken());
131-
132-
self::assertArrayHasKey('createEmptyCart', $response);
133-
self::assertEquals($predefinedCartId, $response['createEmptyCart']);
134-
135-
$guestCart = $this->guestCartRepository->get($response['createEmptyCart']);
136-
self::assertNotNull($guestCart->getId());
137-
self::assertEquals(1, $guestCart->getCustomer()->getId());
138-
}
139-
140-
/**
141-
* @magentoApiDataFixture Magento/Customer/_files/customer.php
142-
*
143-
*/
144-
public function testCreateEmptyCartIfPredefinedCartIdAlreadyExists()
145-
{
146-
$this->expectException(\Exception::class);
147-
$this->expectExceptionMessage('Cart with ID "572cda51902b5b517c0e1a2b2fd004b4" already exists.');
148-
149-
$predefinedCartId = '572cda51902b5b517c0e1a2b2fd004b4';
150-
151-
$query = <<<QUERY
152-
mutation {
153-
createEmptyCart (input: {cart_id: "{$predefinedCartId}"})
154-
}
155-
QUERY;
156-
$this->graphQlMutation($query, [], '', $this->getHeaderMapWithCustomerToken());
157-
$this->graphQlMutation($query, [], '', $this->getHeaderMapWithCustomerToken());
158-
}
159-
160-
/**
161-
* @magentoApiDataFixture Magento/Customer/_files/customer.php
162-
*
163-
*/
164-
public function testCreateEmptyCartWithWrongPredefinedCartId()
165-
{
166-
$this->expectException(\Exception::class);
167-
$this->expectExceptionMessage('Cart ID length should to be 32 symbols.');
168-
169-
$predefinedCartId = '572';
170-
171-
$query = <<<QUERY
172-
mutation {
173-
createEmptyCart (input: {cart_id: "{$predefinedCartId}"})
174-
}
175-
QUERY;
176-
$this->graphQlMutation($query, [], '', $this->getHeaderMapWithCustomerToken());
67+
self::assertEmpty($response['createEmptyCart']);
17768
}
17869

17970
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected function setUp(): void
5454
public function testFailForLoggedInUser()
5555
{
5656
$this->expectException(\Exception::class);
57-
$this->expectExceptionMessage("Use `Query.customerCart` for logged in customer.");
57+
$this->expectExceptionMessage("Use `Query.cart` or `Query.customerCart` for logged in customer.");
5858

5959
$query = $this->getQuery();
6060
$this->graphQlMutation($query, [], '', $this->getHeaderMapWithCustomerToken());

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

Lines changed: 2 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -53,102 +53,13 @@ protected function setUp(): void
5353
$this->quoteIdMaskFactory = $objectManager->get(QuoteIdMaskFactory::class);
5454
}
5555

56-
public function testCreateEmptyCart()
56+
public function testDeprecatedCreateEmptyCart()
5757
{
5858
$query = $this->getQuery();
5959
$response = $this->graphQlMutation($query);
6060

6161
self::assertArrayHasKey('createEmptyCart', $response);
62-
self::assertNotEmpty($response['createEmptyCart']);
63-
64-
$guestCart = $this->guestCartRepository->get($response['createEmptyCart']);
65-
66-
self::assertNotNull($guestCart->getId());
67-
self::assertNull($guestCart->getCustomer()->getId());
68-
self::assertEquals('default', $guestCart->getStore()->getCode());
69-
self::assertEquals('1', $guestCart->getCustomerIsGuest());
70-
}
71-
72-
/**
73-
* @magentoApiDataFixture Magento/Store/_files/second_store.php
74-
*/
75-
public function testCreateEmptyCartWithNotDefaultStore()
76-
{
77-
$query = $this->getQuery();
78-
$headerMap = ['Store' => 'fixture_second_store'];
79-
$response = $this->graphQlMutation($query, [], '', $headerMap);
80-
81-
self::assertArrayHasKey('createEmptyCart', $response);
82-
self::assertNotEmpty($response['createEmptyCart']);
83-
84-
$guestCart = $this->guestCartRepository->get($response['createEmptyCart']);
85-
$this->maskedQuoteId = $response['createEmptyCart'];
86-
87-
self::assertNotNull($guestCart->getId());
88-
self::assertNull($guestCart->getCustomer()->getId());
89-
self::assertSame('fixture_second_store', $guestCart->getStore()->getCode());
90-
self::assertEquals('1', $guestCart->getCustomerIsGuest());
91-
}
92-
93-
/**
94-
* @magentoApiDataFixture Magento/Customer/_files/customer.php
95-
*/
96-
public function testCreateEmptyCartWithPredefinedCartId()
97-
{
98-
$predefinedCartId = '572cda51902b5b517c0e1a2b2fd004b4';
99-
100-
$query = <<<QUERY
101-
mutation {
102-
createEmptyCart (input: {cart_id: "{$predefinedCartId}"})
103-
}
104-
QUERY;
105-
$response = $this->graphQlMutation($query);
106-
107-
self::assertArrayHasKey('createEmptyCart', $response);
108-
self::assertEquals($predefinedCartId, $response['createEmptyCart']);
109-
110-
$guestCart = $this->guestCartRepository->get($response['createEmptyCart']);
111-
self::assertNotNull($guestCart->getId());
112-
self::assertNull($guestCart->getCustomer()->getId());
113-
}
114-
115-
/**
116-
* @magentoApiDataFixture Magento/Customer/_files/customer.php
117-
*
118-
*/
119-
public function testCreateEmptyCartIfPredefinedCartIdAlreadyExists()
120-
{
121-
$this->expectException(\Exception::class);
122-
$this->expectExceptionMessage('Cart with ID "572cda51902b5b517c0e1a2b2fd004b4" already exists.');
123-
124-
$predefinedCartId = '572cda51902b5b517c0e1a2b2fd004b4';
125-
126-
$query = <<<QUERY
127-
mutation {
128-
createEmptyCart (input: {cart_id: "{$predefinedCartId}"})
129-
}
130-
QUERY;
131-
$this->graphQlMutation($query);
132-
$this->graphQlMutation($query);
133-
}
134-
135-
/**
136-
* @magentoApiDataFixture Magento/Customer/_files/customer.php
137-
*
138-
*/
139-
public function testCreateEmptyCartWithWrongPredefinedCartId()
140-
{
141-
$this->expectException(\Exception::class);
142-
$this->expectExceptionMessage('Cart ID length should to be 32 symbols.');
143-
144-
$predefinedCartId = '572';
145-
146-
$query = <<<QUERY
147-
mutation {
148-
createEmptyCart (input: {cart_id: "{$predefinedCartId}"})
149-
}
150-
QUERY;
151-
$this->graphQlMutation($query);
62+
self::assertEmpty($response['createEmptyCart']);
15263
}
15364

15465
/**

0 commit comments

Comments
 (0)