Skip to content

Commit

Permalink
Fix review coments
Browse files Browse the repository at this point in the history
  • Loading branch information
wip44850 committed Dec 14, 2023
1 parent a8eec06 commit afd51ce
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 19 deletions.
2 changes: 1 addition & 1 deletion app/code/Magento/QuoteGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ interface CartItemInterface @typeResolver(class: "Magento\\QuoteGraphQl\\Model\\
id: String! @deprecated(reason: "Use `uid` instead.")
uid: ID! @doc(description: "The unique ID for a `CartItemInterface` object.")
quantity: Float! @doc(description: "The quantity of this item in the cart.")
is_available: Boolean! @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\CheckProductStockAvailability") @doc(description: "If qty is more than stock display status as unavailable else available.")
is_available: Boolean! @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\CheckProductStockAvailability") @doc(description: "True if requested quantity is less than available stock, false otherwise.")
prices: CartItemPrices @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\CartItemPrices") @doc(description: "Contains details about the price of the item, including taxes and discounts.")
product: ProductInterface! @doc(description: "Details about an item in the cart.")
errors: [CartItemError!] @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\CartItemErrors") @doc(description: "An array of errors encountered while loading the cart item")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,24 +86,47 @@ public function testStockStatusUnavailableSimpleProduct(): void
$response = $this->graphQlMutation($query);
$responseDataObject = new DataObject($response);

self::assertEquals(false, $responseDataObject->getData('cart/items/0/is_available'));
self::assertFalse(
$responseDataObject->getData('cart/items/0/is_available')
);
}

#[
DataFixture(ProductFixture::class, ['sku' => self::SKU, 'price' => 100.00], as: 'product'),
DataFixture(ProductFixture::class, ['price' => 100.00], as: 'product'),
DataFixture(GuestCartFixture::class, as: 'cart'),
DataFixture(AddProductToCart::class, ['cart_id' => '$cart.id$', 'product_id' => '$product.id$', 'qty' => 100]),
DataFixture(QuoteMaskFixture::class, ['cart_id' => '$cart.id$'], 'quoteIdMask')
]
public function testStockStatusUnavailableAddSimpleProduct(): void
public function testStockStatusAvailableSimpleProduct(): void
{
$maskedQuoteId = $this->fixtures->get('quoteIdMask')->getMaskedId();
$query = $this->mutationAddSimpleProduct($maskedQuoteId, self::SKU, 1);
$query = $this->getQuery($maskedQuoteId);
$response = $this->graphQlMutation($query);
$responseDataObject = new DataObject($response);

self::assertEquals(
false,
self::assertTrue(
$responseDataObject->getData('cart/items/0/is_available')
);
}

#[
DataFixture(ProductFixture::class, ['sku' => self::SKU, 'price' => 100.00], as: 'product'),
DataFixture(GuestCartFixture::class, as: 'cart'),
DataFixture(AddProductToCart::class, ['cart_id' => '$cart.id$', 'product_id' => '$product.id$', 'qty' => 99]),
DataFixture(QuoteMaskFixture::class, ['cart_id' => '$cart.id$'], 'quoteIdMask')
]
public function testStockStatusAddSimpleProduct(): void
{
$maskedQuoteId = $this->fixtures->get('quoteIdMask')->getMaskedId();
$query = $this->mutationAddSimpleProduct($maskedQuoteId, self::SKU, 1);
$response = $this->graphQlMutation($query);
$responseDataObject = new DataObject($response);
self::assertTrue(
$responseDataObject->getData('addProductsToCart/cart/items/0/is_available')
);
$response = $this->graphQlMutation($query);
$responseDataObject = new DataObject($response);
self::assertFalse(
$responseDataObject->getData('addProductsToCart/cart/items/0/is_available')
);
}
Expand Down Expand Up @@ -144,8 +167,7 @@ public function testStockStatusUnavailableBundleProduct(): void
$response = $this->graphQlMutation($query);
$responseDataObject = new DataObject($response);

self::assertEquals(
false,
self::assertFalse(
$responseDataObject->getData('cart/items/0/is_available')
);
}
Expand Down Expand Up @@ -173,12 +195,12 @@ public function testStockStatusUnavailableBundleProduct(): void
'cart_id' => '$cart.id$',
'product_id' => '$bundleProduct.id$',
'selections' => [['$product.id$']],
'qty' => 100
'qty' => 99
],
),
DataFixture(QuoteMaskFixture::class, ['cart_id' => '$cart.id$'], 'quoteIdMask')
]
public function testStockStatusUnavailableAddBundleProduct(): void
public function testStockStatusAddBundleProduct(): void
{
$product = $this->productRepository->get(self::PARENT_SKU_BUNDLE);

Expand All @@ -198,9 +220,14 @@ public function testStockStatusUnavailableAddBundleProduct(): void
$query = $this->mutationAddBundleProduct($maskedQuoteId, self::PARENT_SKU_BUNDLE, $bundleOptionIdV2);
$response = $this->graphQlMutation($query);
$responseDataObject = new DataObject($response);
self::assertTrue(
$responseDataObject->getData('addProductsToCart/cart/items/0/is_available')
);

self::assertEquals(
false,
$response = $this->graphQlMutation($query);
$responseDataObject = new DataObject($response);

self::assertFalse(
$responseDataObject->getData('addProductsToCart/cart/items/0/is_available')
);
}
Expand Down Expand Up @@ -233,8 +260,7 @@ public function testStockStatusUnavailableConfigurableProduct(): void
$response = $this->graphQlMutation($query);
$responseDataObject = new DataObject($response);

self::assertEquals(
false,
self::assertFalse(
$responseDataObject->getData('cart/items/0/is_available')
);
}
Expand All @@ -259,15 +285,18 @@ public function testStockStatusUnavailableConfigurableProduct(): void
],
)
]
public function testStockStatusUnavailableAddConfigurableProduct(): void
public function testStockStatusAddConfigurableProduct(): void
{
$maskedQuoteId = $this->fixtures->get('quoteIdMask')->getMaskedId();
$query = $this->mutationAddConfigurableProduct($maskedQuoteId, self::SKU, self::PARENT_SKU_CONFIGURABLE);
$response = $this->graphQlMutation($query);
$responseDataObject = new DataObject($response);

self::assertEquals(
false,
self::assertTrue(
$responseDataObject->getData('addProductsToCart/cart/items/1/is_available')
);
$response = $this->graphQlMutation($query);
$responseDataObject = new DataObject($response);
self::assertFalse(
$responseDataObject->getData('addProductsToCart/cart/items/0/is_available')
);
}
Expand Down Expand Up @@ -369,6 +398,10 @@ private function mutationAddConfigurableProduct(
}
}
}
user_errors {
code
message
}
}
}
QUERY;
Expand Down

0 comments on commit afd51ce

Please sign in to comment.