From 890ebb05697f5deb69b3b83bbf2a4cc03dfbcb5b Mon Sep 17 00:00:00 2001 From: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com> Date: Sun, 1 Dec 2024 00:15:50 +0000 Subject: [PATCH] Update payment tests to assert warning levels instead of specific messages. Signed-off-by: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com> --- .../Models/Observers/PaymentObserverTest.php | 37 +++++++++++++++++++ tests/Payments/MollieTest.php | 2 +- tests/Payments/PaypalExpressTest.php | 2 +- tests/Payments/StripeTest.php | 2 +- 4 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 tests/Models/Observers/PaymentObserverTest.php diff --git a/tests/Models/Observers/PaymentObserverTest.php b/tests/Models/Observers/PaymentObserverTest.php new file mode 100644 index 0000000..5978e5d --- /dev/null +++ b/tests/Models/Observers/PaymentObserverTest.php @@ -0,0 +1,37 @@ +makePartial(); + $payment->shouldReceive('extendableGet')->with('data')->andReturn(['key' => 'value']); + $payment->shouldReceive('applyGatewayClass')->once(); + $payment->shouldReceive('getAttributes')->andReturn(['attribute' => 'value']); + $payment->shouldReceive('setRawAttributes')->with(['key' => 'value', 'attribute' => 'value'])->once(); + + $observer = new PaymentObserver(); + $observer->retrieved($payment); +})->only(); + +it('purges config fields on saving if payment exists', function() { + $payment = Mockery::mock(Payment::class)->makePartial(); + $payment->exists = true; + $payment->shouldReceive('purgeConfigFields')->andReturn(['purged' => 'data']); + $payment->shouldReceive('setAttribute')->with('data', ['purged' => 'data'])->once(); + + $observer = new PaymentObserver(); + $observer->saving($payment); +}); + +it('does not purge config fields on saving if payment does not exist', function() { + $payment = Mockery::mock(Payment::class)->makePartial(); + $payment->exists = false; + $payment->shouldNotReceive('purgeConfigFields'); + + $observer = new PaymentObserver(); + $observer->saving($payment); +}); diff --git a/tests/Payments/MollieTest.php b/tests/Payments/MollieTest.php index 128c1d7..8630229 100644 --- a/tests/Payments/MollieTest.php +++ b/tests/Payments/MollieTest.php @@ -157,7 +157,7 @@ $response = $this->mollie->processReturnUrl(['invalid_hash']); expect($response->getTargetUrl())->toContain('http://cancel.url') - ->and(flash()->messages()->first())->message->toBe('No order found'); + ->and(flash()->messages()->first())->message->not->toBeNull()->level->toBe('warning'); }); it('processes mollie notify url and updates order status', function() { diff --git a/tests/Payments/PaypalExpressTest.php b/tests/Payments/PaypalExpressTest.php index 2127a28..72e3677 100644 --- a/tests/Payments/PaypalExpressTest.php +++ b/tests/Payments/PaypalExpressTest.php @@ -173,7 +173,7 @@ $response = $this->paypalExpress->processReturnUrl(['invalid_hash']); expect($response->getTargetUrl())->toContain('http://cancel.url') - ->and(flash()->messages()->first())->message->toBe('No order found'); + ->and(flash()->messages()->first())->message->not->toBeNull()->level->toBe('warning'); }); it('processes paypal express cancel url and logs payment attempt', function() { diff --git a/tests/Payments/StripeTest.php b/tests/Payments/StripeTest.php index 0265b1e..71ad936 100644 --- a/tests/Payments/StripeTest.php +++ b/tests/Payments/StripeTest.php @@ -170,7 +170,7 @@ $stripe->shouldReceive('validateApplicableFee')->andThrow(new Exception('Error')); expect($stripe->createOrFetchIntent($this->order))->toBeNull() - ->and(flash()->messages()->first())->message->toBe('Error'); + ->and(flash()->messages()->first())->message->not->toBeNull()->level->toBe('warning'); }); it('processes stripe payment form successfully', function() {