Skip to content

Commit

Permalink
graphQl-812: test Add Variation From Another Configurable ProductToCart
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaliy Boyko committed Aug 28, 2019
1 parent 7cf99d1 commit 9a8cf3a
Showing 1 changed file with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,48 @@ public function testAddConfigurableProductToCart()
self::assertArrayHasKey('value_label', $option);
}

/**
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/configurable_products.php
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
*/
public function testAddVariationFromAnotherConfigurableProductToCart()
{
$searchResponse = $this->graphQlQuery($this->getFetchProductQuery('configurable_12345'));
$product = current($searchResponse['products']['items']);
$attributeId = (int) $product['configurable_options'][0]['attribute_id'];
$optionId = $product['configurable_options'][0]['values'][1]['value_index'];

$quantity = 2;
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1');
$parentSku = $product['sku'];

//'configurable' -> ['simple_10', 'simple_20']
//'configurable_12345' -> ['simple_30', 'simple_40']
//'simple_20' has same configurable option value index (super attribute) as 'simple_40'
//therefore 'simple_40' should be added to cart
$sku = 'simple_20';

$query = $this->getQuery(
$maskedQuoteId,
$parentSku,
$sku,
$quantity
);

$response = $this->graphQlMutation($query);

$cartItem = current($response['addConfigurableProductsToCart']['cart']['items']);
self::assertEquals($quantity, $cartItem['quantity']);
self::assertEquals($parentSku, $cartItem['product']['sku']);
self::assertArrayHasKey('configurable_options', $cartItem);

$option = current($cartItem['configurable_options']);
self::assertEquals($attributeId, $option['id']);
self::assertEquals($optionId, $option['value_id']);
self::assertArrayHasKey('option_label', $option);
self::assertArrayHasKey('value_label', $option);
}

/**
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable_sku.php
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
Expand Down

0 comments on commit 9a8cf3a

Please sign in to comment.