Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
test that cart is recalcing
Browse files Browse the repository at this point in the history
  • Loading branch information
senadir committed Oct 27, 2022
1 parent 43a3e8d commit 8889854
Showing 1 changed file with 57 additions and 1 deletion.
58 changes: 57 additions & 1 deletion tests/php/StoreApi/Routes/CartExtensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,50 @@
namespace Automattic\WooCommerce\Blocks\Tests\StoreApi\Routes;

use Automattic\WooCommerce\Blocks\Tests\StoreApi\Routes\ControllerTestCase;
use Automattic\WooCommerce\Blocks\Tests\Helpers\FixtureData;

/**
* Cart Controller Tests.
*/
class CartExtensions extends ControllerTestCase {

/**
* Setup test products data. Called before every test.
*/
public function setUp() {
parent::setUp();

$fixtures = new FixtureData();

$this->product = $fixtures->get_simple_product(
array(
'name' => 'Test Product 1',
'regular_price' => 10,
)
);

wc_empty_cart();

wc()->cart->add_to_cart( $this->product->get_id(), 1 );

woocommerce_store_api_register_update_callback(
array(
'namespace' => 'valid-test-plugin',
'callback' => function() {
add_action(
'woocommerce_cart_calculate_fees',
function() {
wc()->cart->add_fee( 'Surcharge', 10, true, 'standard' );
}
);
},
)
);
}
/**
* Test getting cart with invalid namespace.
*/
public function test_post() {
public function test_invalid_namespace() {
$request = new \WP_REST_Request( 'POST', '/wc/store/v1/cart/extensions' );
$request->set_header( 'Nonce', wp_create_nonce( 'wc_store_api' ) );
$request->set_body_params(
Expand All @@ -28,4 +62,26 @@ public function test_post() {
400
);
}

/**
* Test getting cart with invalid namespace.
*/
public function test_cart_being_updated() {
$request = new \WP_REST_Request( 'POST', '/wc/store/v1/cart/extensions' );
$request->set_header( 'Nonce', wp_create_nonce( 'wc_store_api' ) );
$request->set_body_params(
array(
'namespace' => 'valid-test-plugin',
)
);
$this->assertAPIResponse(
$request,
200,
array(
'totals' => array(
'total_fees' => '1000',
),
)
);
}
}

0 comments on commit 8889854

Please sign in to comment.