fix(purchase): unify expired checkout errors
This commit is contained in:
56
tests/Unit/Purchase/PurchaseStateGuardTest.php
Normal file
56
tests/Unit/Purchase/PurchaseStateGuardTest.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Purchase;
|
||||
|
||||
use App\Domains\Purchase\Exceptions\PurchaseExpiredException;
|
||||
use App\Domains\Purchase\Models\Purchase;
|
||||
use App\Domains\Purchase\Services\PurchaseStateGuard;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PurchaseStateGuardTest extends TestCase
|
||||
{
|
||||
private PurchaseStateGuard $guard;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->guard = new PurchaseStateGuard;
|
||||
}
|
||||
|
||||
public function test_it_rejects_a_purchase_with_expired_status(): void
|
||||
{
|
||||
$purchase = (new Purchase)->forceFill([
|
||||
'status' => Purchase::STATUS_EXPIRED,
|
||||
'expires_at' => null,
|
||||
]);
|
||||
|
||||
$this->expectException(PurchaseExpiredException::class);
|
||||
|
||||
$this->guard->assertNotExpired($purchase);
|
||||
}
|
||||
|
||||
public function test_it_rejects_an_active_purchase_when_its_deadline_has_passed(): void
|
||||
{
|
||||
$purchase = (new Purchase)->forceFill([
|
||||
'status' => Purchase::STATUS_PENDING_PAYMENT,
|
||||
'expires_at' => now()->subMinute(),
|
||||
]);
|
||||
|
||||
$this->expectException(PurchaseExpiredException::class);
|
||||
|
||||
$this->guard->assertNotExpired($purchase);
|
||||
}
|
||||
|
||||
public function test_it_does_not_treat_a_paid_purchase_as_expired_by_time(): void
|
||||
{
|
||||
$purchase = (new Purchase)->forceFill([
|
||||
'status' => Purchase::STATUS_PAID,
|
||||
'expires_at' => now()->subMinute(),
|
||||
]);
|
||||
|
||||
$this->guard->assertNotExpired($purchase);
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user