Skip to content

Commit

Permalink
Update payment tests to assert warning levels instead of specific mes…
Browse files Browse the repository at this point in the history
…sages.

Signed-off-by: Sam Poyigi <[email protected]>
  • Loading branch information
sampoyigi committed Dec 1, 2024
1 parent 9371af5 commit 890ebb0
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
37 changes: 37 additions & 0 deletions tests/Models/Observers/PaymentObserverTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Igniter\PayRegister\Tests\Models\Observers;

use Igniter\PayRegister\Models\Observers\PaymentObserver;
use Igniter\PayRegister\Models\Payment;
use Mockery;

it('applies gateway class and merges data attributes on retrieved', function() {
$payment = Mockery::mock(Payment::class)->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);
});
2 changes: 1 addition & 1 deletion tests/Payments/MollieTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion tests/Payments/PaypalExpressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion tests/Payments/StripeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 890ebb0

Please sign in to comment.