Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

Add API functional tests for ApplyCouponToCart functionality #558

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,91 +41,6 @@ protected function setUp()
$this->quoteIdToMaskedId = $objectManager->create(QuoteIdToMaskedQuoteIdInterface::class);
}

/**
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
* @magentoApiDataFixture Magento/SalesRule/_files/coupon_code_with_wildcard.php
*/
public function testApplyCouponToGuestCartWithItems()
{
$couponCode = '2?ds5!2d';

$this->quoteResource->load(
$this->quote,
'test_order_with_simple_product_without_address',
'reserved_order_id'
);
$maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId());
$query = $this->prepareAddCouponRequestQuery($maskedQuoteId, $couponCode);
$response = $this->graphQlQuery($query);

self::assertArrayHasKey('applyCouponToCart', $response);
self::assertEquals($couponCode, $response['applyCouponToCart']['cart']['applied_coupon']['code']);
}

/**
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
* @magentoApiDataFixture Magento/SalesRule/_files/coupon_code_with_wildcard.php
*/
public function testApplyCouponTwice()
{
$couponCode = '2?ds5!2d';

$this->quoteResource->load(
$this->quote,
'test_order_with_simple_product_without_address',
'reserved_order_id'
);
$maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId());
$query = $this->prepareAddCouponRequestQuery($maskedQuoteId, $couponCode);
$response = $this->graphQlQuery($query);

self::assertArrayHasKey("applyCouponToCart", $response);
self::assertEquals($couponCode, $response['applyCouponToCart']['cart']['applied_coupon']['code']);

self::expectExceptionMessage('A coupon is already applied to the cart. Please remove it to apply another');
$this->graphQlQuery($query);
}

/**
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
* @magentoApiDataFixture Magento/SalesRule/_files/coupon_code_with_wildcard.php
* @expectedException \Exception
* @expectedExceptionMessage Cart does not contain products.
*/
public function testApplyCouponToCartWithNoItems()
{
$couponCode = '2?ds5!2d';

$this->quoteResource->load($this->quote, 'test_order_1', 'reserved_order_id');
$maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId());
$query = $this->prepareAddCouponRequestQuery($maskedQuoteId, $couponCode);

$this->graphQlQuery($query);
}

/**
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
* @magentoApiDataFixture Magento/SalesRule/_files/coupon_code_with_wildcard.php
* @magentoApiDataFixture Magento/Customer/_files/customer.php
*/
public function testGuestCustomerAttemptToChangeCustomerCart()
{
$couponCode = '2?ds5!2d';

$this->quoteResource->load(
$this->quote,
'test_order_with_simple_product_without_address',
'reserved_order_id'
);
$maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId());
$this->quote->setCustomerId(1);
$this->quoteResource->save($this->quote);
$query = $this->prepareAddCouponRequestQuery($maskedQuoteId, $couponCode);

self::expectExceptionMessage('The current user cannot perform operations on cart "' . $maskedQuoteId . '"');
$this->graphQlQuery($query);
}

/**
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
* @magentoApiDataFixture Magento/SalesRule/_files/coupon_code_with_wildcard.php
Expand Down
Loading