mirror of
https://github.com/wp-graphql/wp-graphql-woocommerce.git
synced 2026-08-14 12:53:44 +02:00
Merge branch 'release/v0.6.0' into feature/some-node-interfaces-support
This commit is contained in:
@@ -181,15 +181,21 @@ class CartMutationsTest extends \Codeception\TestCase\WPTestCase {
|
||||
'clientMutationId' => 'someId',
|
||||
'productId' => $ids['product'],
|
||||
'quantity' => 3,
|
||||
'variationId' => $ids['variations'][0],
|
||||
'variationId' => $ids['variations'][0],
|
||||
'variation' => array(
|
||||
array(
|
||||
'attributeName' => 'color',
|
||||
'attributeValue' => 'red',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
// Retrieve cart item key.
|
||||
$this->assertArrayHasKey('data', $actual );
|
||||
$this->assertArrayHasKey('addToCart', $actual['data'] );
|
||||
$this->assertArrayHasKey('cartItem', $actual['data']['addToCart'] );
|
||||
$this->assertArrayHasKey('key', $actual['data']['addToCart']['cartItem'] );
|
||||
$this->assertArrayHasKey( 'data', $actual );
|
||||
$this->assertArrayHasKey( 'addToCart', $actual['data'] );
|
||||
$this->assertArrayHasKey( 'cartItem', $actual['data']['addToCart'] );
|
||||
$this->assertArrayHasKey( 'key', $actual['data']['addToCart']['cartItem'] );
|
||||
$key = $actual['data']['addToCart']['cartItem']['key'];
|
||||
|
||||
// Get newly created cart item data.
|
||||
@@ -322,7 +328,13 @@ class CartMutationsTest extends \Codeception\TestCase\WPTestCase {
|
||||
'clientMutationId' => 'someId',
|
||||
'productId' => $ids['product'],
|
||||
'quantity' => 2,
|
||||
'variationId' => $ids['variations'][0],
|
||||
'variationId' => $ids['variations'][0],
|
||||
'variation' => array(
|
||||
array(
|
||||
'attributeName' => 'color',
|
||||
'attributeValue' => 'red',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
@@ -364,6 +376,12 @@ class CartMutationsTest extends \Codeception\TestCase\WPTestCase {
|
||||
'productId' => $ids['product'],
|
||||
'quantity' => 2,
|
||||
'variationId' => $ids['variations'][0],
|
||||
'variation' => array(
|
||||
array(
|
||||
'attributeName' => 'color',
|
||||
'attributeValue' => 'red',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
@@ -380,6 +398,12 @@ class CartMutationsTest extends \Codeception\TestCase\WPTestCase {
|
||||
'productId' => $ids['product'],
|
||||
'quantity' => 3,
|
||||
'variationId' => $ids['variations'][1],
|
||||
'variation' => array(
|
||||
array(
|
||||
'attributeName' => 'color',
|
||||
'attributeValue' => 'red',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
@@ -422,6 +446,12 @@ class CartMutationsTest extends \Codeception\TestCase\WPTestCase {
|
||||
'productId' => $ids['product'],
|
||||
'quantity' => 2,
|
||||
'variationId' => $ids['variations'][0],
|
||||
'variation' => array(
|
||||
array(
|
||||
'attributeName' => 'color',
|
||||
'attributeValue' => 'red',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
@@ -438,6 +468,12 @@ class CartMutationsTest extends \Codeception\TestCase\WPTestCase {
|
||||
'productId' => $ids['product'],
|
||||
'quantity' => 3,
|
||||
'variationId' => $ids['variations'][1],
|
||||
'variation' => array(
|
||||
array(
|
||||
'attributeName' => 'color',
|
||||
'attributeValue' => 'red',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
@@ -479,6 +515,12 @@ class CartMutationsTest extends \Codeception\TestCase\WPTestCase {
|
||||
'productId' => $ids['product'],
|
||||
'quantity' => 2,
|
||||
'variationId' => $ids['variations'][0],
|
||||
'variation' => array(
|
||||
array(
|
||||
'attributeName' => 'color',
|
||||
'attributeValue' => 'red',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
@@ -527,6 +569,12 @@ class CartMutationsTest extends \Codeception\TestCase\WPTestCase {
|
||||
'productId' => $ids['product'],
|
||||
'quantity' => 2,
|
||||
'variationId' => $ids['variations'][0],
|
||||
'variation' => array(
|
||||
array(
|
||||
'attributeName' => 'color',
|
||||
'attributeValue' => 'red',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
@@ -543,6 +591,12 @@ class CartMutationsTest extends \Codeception\TestCase\WPTestCase {
|
||||
'productId' => $ids['product'],
|
||||
'quantity' => 1,
|
||||
'variationId' => $ids['variations'][1],
|
||||
'variation' => array(
|
||||
array(
|
||||
'attributeName' => 'color',
|
||||
'attributeValue' => 'red',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
@@ -589,7 +643,12 @@ class CartMutationsTest extends \Codeception\TestCase\WPTestCase {
|
||||
|
||||
// Add items to carts.
|
||||
$cart_item = $cart->get_cart_item(
|
||||
$cart->add_to_cart( $ids['product'], 2, $ids['variations'][0] )
|
||||
$cart->add_to_cart(
|
||||
$ids['product'],
|
||||
2,
|
||||
$ids['variations'][0],
|
||||
array( 'attribute_pa_color' => 'red' )
|
||||
)
|
||||
);
|
||||
|
||||
$mutation = '
|
||||
@@ -1008,14 +1067,28 @@ class CartMutationsTest extends \Codeception\TestCase\WPTestCase {
|
||||
|
||||
public function testAddToCartMutationErrors() {
|
||||
// Create products.
|
||||
$product_id = $this->product->create_simple(
|
||||
$product_id = $this->product->create_simple(
|
||||
array(
|
||||
'manage_stock' => true,
|
||||
'stock_quantity' => 1,
|
||||
)
|
||||
);
|
||||
$variation_ids = $this->variation->create( $this->product->create_variable() );
|
||||
|
||||
$failed = $this->addToCart(
|
||||
\WC()->session->set( 'wc_notices', null );
|
||||
$missing_attributes = $this->addToCart(
|
||||
array(
|
||||
'clientMutationId' => 'someId',
|
||||
'productId' => $product_id,
|
||||
'quantity' => 5,
|
||||
'variationId' => $variation_ids['variations'][0],
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertArrayHasKey( 'errors', $missing_attributes );
|
||||
|
||||
\WC()->session->set( 'wc_notices', null );
|
||||
$not_enough_stock = $this->addToCart(
|
||||
array(
|
||||
'clientMutationId' => 'someId',
|
||||
'productId' => $product_id,
|
||||
@@ -1023,6 +1096,6 @@ class CartMutationsTest extends \Codeception\TestCase\WPTestCase {
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertArrayHasKey( 'errors', $failed );
|
||||
$this->assertArrayHasKey( 'errors', $not_enough_stock );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,8 @@ class CartQueriesTest extends \Codeception\TestCase\WPTestCase {
|
||||
$key = $cart->add_to_cart(
|
||||
$variations['product'],
|
||||
3,
|
||||
$variations['variations'][0]
|
||||
$variations['variations'][0],
|
||||
array( 'attribute_pa_color' => 'red' )
|
||||
);
|
||||
|
||||
$query = '
|
||||
|
||||
@@ -307,7 +307,12 @@ class CheckoutMutationTest extends \Codeception\TestCase\WPTestCase {
|
||||
|
||||
WC()->cart->add_to_cart( $product_ids[0], 3 );
|
||||
WC()->cart->add_to_cart( $product_ids[1], 6 );
|
||||
WC()->cart->add_to_cart( $product_ids[2], 2, $variable['variations'][0] );
|
||||
WC()->cart->add_to_cart(
|
||||
$product_ids[2],
|
||||
2,
|
||||
$variable['variations'][0],
|
||||
array( 'attribute_pa_color' => 'red' )
|
||||
);
|
||||
WC()->cart->apply_coupon( $coupon->get_code() );
|
||||
|
||||
$input = array(
|
||||
@@ -515,7 +520,12 @@ class CheckoutMutationTest extends \Codeception\TestCase\WPTestCase {
|
||||
);
|
||||
WC()->cart->add_to_cart( $product_ids[0], 3 );
|
||||
WC()->cart->add_to_cart( $product_ids[1], 6 );
|
||||
WC()->cart->add_to_cart( $product_ids[2], 2, $variable['variations'][0] );
|
||||
WC()->cart->add_to_cart(
|
||||
$product_ids[2],
|
||||
2,
|
||||
$variable['variations'][0],
|
||||
array( 'attribute_pa_color' => 'red' )
|
||||
);
|
||||
WC()->cart->apply_coupon( $coupon->get_code() );
|
||||
|
||||
$input = array(
|
||||
@@ -708,7 +718,12 @@ class CheckoutMutationTest extends \Codeception\TestCase\WPTestCase {
|
||||
);
|
||||
WC()->cart->add_to_cart( $product_ids[0], 3 );
|
||||
WC()->cart->add_to_cart( $product_ids[1], 6 );
|
||||
WC()->cart->add_to_cart( $product_ids[2], 2, $variable['variations'][0] );
|
||||
WC()->cart->add_to_cart(
|
||||
$product_ids[2],
|
||||
2,
|
||||
$variable['variations'][0],
|
||||
array( 'attribute_pa_color' => 'red' )
|
||||
);
|
||||
WC()->cart->apply_coupon( $coupon->get_code() );
|
||||
|
||||
$input = array(
|
||||
@@ -1296,5 +1311,52 @@ class CheckoutMutationTest extends \Codeception\TestCase\WPTestCase {
|
||||
);
|
||||
|
||||
$this->assertEquals( $expected, $actual );
|
||||
}
|
||||
}
|
||||
|
||||
public function testCheckoutMutationCartItemValidation() {
|
||||
add_filter( 'woocommerce_hold_stock_for_checkout', '__return_false' );
|
||||
|
||||
$product_id = $this->product->create_simple(
|
||||
array(
|
||||
'manage_stock' => true,
|
||||
'stock_quantity' => 3,
|
||||
)
|
||||
);
|
||||
|
||||
$key = WC()->cart->add_to_cart( $product_id, 3 );
|
||||
WC()->cart->set_quantity( $key, 5 );
|
||||
|
||||
/**
|
||||
* Assertion One
|
||||
*
|
||||
* Ensure that checkout failed when stock is too low.
|
||||
*/
|
||||
$input = array(
|
||||
'clientMutationId' => 'someId',
|
||||
'paymentMethod' => 'bacs',
|
||||
'shippingMethod' => array( 'flat rate' ),
|
||||
'billing' => array(
|
||||
'firstName' => 'May',
|
||||
'lastName' => 'Parker',
|
||||
'company' => 'Harris Teeter',
|
||||
'address1' => '20 Ingram St',
|
||||
'city' => 'New York City',
|
||||
'state' => 'NY',
|
||||
'postcode' => '12345',
|
||||
'country' => 'US',
|
||||
'email' => 'superfreak500@gmail.com',
|
||||
'phone' => '555-555-1234',
|
||||
),
|
||||
'account' => array(
|
||||
'username' => 'test_user_1',
|
||||
'password' => 'test_pass'
|
||||
)
|
||||
);
|
||||
$failed = $this->checkout( $input );
|
||||
|
||||
// use --debug flag to view.
|
||||
codecept_debug( $failed );
|
||||
|
||||
$this->assertArrayHasKey( 'errors', $failed );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ class MetaDataQueriesTest extends \Codeception\TestCase\WPTestCase {
|
||||
'product_id' => $this->variation_ids['product'],
|
||||
'quantity' => 2,
|
||||
'variation_id' => $this->variation_ids['variations'][0],
|
||||
'variation' => array(),
|
||||
'variation' => array( 'attribute_pa_color' => 'red' ),
|
||||
'cart_item_data' => $cart_meta_data
|
||||
)
|
||||
)[0];
|
||||
|
||||
@@ -28,8 +28,8 @@ class TaxRateQueriesTest extends \Codeception\TestCase\WPTestCase {
|
||||
$id = Relay::toGlobalId( 'tax_rate', $this->rate );
|
||||
|
||||
$query = '
|
||||
query taxRateQuery( $id: ID, $rateId: Int ) {
|
||||
taxRate( id: $id, rateId: $rateId ) {
|
||||
query taxRateQuery( $id: ID, $idType: TaxRateIdTypeEnum ) {
|
||||
taxRate( id: $id, idType: $idType ) {
|
||||
id
|
||||
databaseId
|
||||
country
|
||||
@@ -66,7 +66,10 @@ class TaxRateQueriesTest extends \Codeception\TestCase\WPTestCase {
|
||||
*
|
||||
* tests query, "rateId" query arg, and results
|
||||
*/
|
||||
$variables = array( 'rateId' => $this->rate );
|
||||
$variables = array(
|
||||
'id' => $this->rate,
|
||||
'idType' => 'DATABASE_ID',
|
||||
);
|
||||
$actual = do_graphql_request( $query, 'taxRateQuery', $variables );
|
||||
$expected = array( 'data' => array( 'taxRate' => $this->helper->print_query( $this->rate ) ) );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user