mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
Refresh checkout totals after validation if needed
Refreshing the totals the same way as WC does this.
This commit is contained in:
parent
c03b3d86b5
commit
3c557907f2
5 changed files with 47 additions and 11 deletions
|
@ -11,6 +11,7 @@ use WooCommerce\PayPalCommerce\Button\Exception\ValidationException;
|
|||
use WooCommerce\PayPalCommerce\Button\Validation\CheckoutFormValidator;
|
||||
use WooCommerce\PayPalCommerce\TestCase;
|
||||
use function Brain\Monkey\Functions\expect;
|
||||
use function Brain\Monkey\Functions\when;
|
||||
|
||||
class ValidateCheckoutEndpointTest extends TestCase
|
||||
{
|
||||
|
@ -21,6 +22,8 @@ class ValidateCheckoutEndpointTest extends TestCase
|
|||
private $logger;
|
||||
private $sut;
|
||||
|
||||
private $session = [];
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
@ -36,6 +39,10 @@ class ValidateCheckoutEndpointTest extends TestCase
|
|||
);
|
||||
|
||||
$this->requestData->expects('read_request')->andReturn(['form' => ['field1' => 'value']]);
|
||||
|
||||
when('WC')->alias(function () {
|
||||
return (object) ['session' => (object) $this->session];
|
||||
});
|
||||
}
|
||||
|
||||
public function testValid()
|
||||
|
@ -54,7 +61,21 @@ class ValidateCheckoutEndpointTest extends TestCase
|
|||
->andThrow($exception);
|
||||
|
||||
expect('wp_send_json_error')->once()
|
||||
->with(['message' => $exception->getMessage(), 'errors' => ['Invalid value']]);
|
||||
->with(['message' => $exception->getMessage(), 'errors' => ['Invalid value'], 'refresh' => false]);
|
||||
|
||||
$this->sut->handle_request();
|
||||
}
|
||||
|
||||
public function testInvalidAndRefresh()
|
||||
{
|
||||
$exception = new ValidationException(['Invalid value']);
|
||||
$this->formValidator->expects('validate')->once()
|
||||
->andThrow($exception);
|
||||
|
||||
$this->session['refresh_totals'] = true;
|
||||
|
||||
expect('wp_send_json_error')->once()
|
||||
->with(['message' => $exception->getMessage(), 'errors' => ['Invalid value'], 'refresh' => true]);
|
||||
|
||||
$this->sut->handle_request();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue