codes.txt
This commit is contained in:
@@ -2,10 +2,14 @@
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Exceptions\CouponPoolExhaustedException;
|
||||
use App\Models\Coupon;
|
||||
use App\Models\PhoneVerification;
|
||||
use App\Services\CouponCodePool;
|
||||
use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Mockery;
|
||||
use Mockery\MockInterface;
|
||||
use Tests\TestCase;
|
||||
|
||||
class VerificationFlowTest extends TestCase
|
||||
@@ -82,15 +86,43 @@ class VerificationFlowTest extends TestCase
|
||||
->assertRedirect(route('verification.congratulations'))
|
||||
->assertCookie('device_registered');
|
||||
|
||||
$this->assertDatabaseHas(Coupon::class, [
|
||||
'phone' => self::UNMASKED_PHONE,
|
||||
]);
|
||||
$coupon = Coupon::query()->where('phone', self::UNMASKED_PHONE)->first();
|
||||
|
||||
$this->assertNotNull($coupon);
|
||||
$this->assertContains(
|
||||
$coupon->code,
|
||||
(new CouponCodePool)->allCodes(),
|
||||
);
|
||||
|
||||
$this->get(route('verification.congratulations'))
|
||||
->assertOk()
|
||||
->assertViewHas('code');
|
||||
}
|
||||
|
||||
public function test_index_shows_promotion_ended_when_pool_exhausted(): void
|
||||
{
|
||||
$this->mock(CouponCodePool::class, function (MockInterface $mock): void {
|
||||
$mock->shouldReceive('hasAvailable')->andReturn(false);
|
||||
});
|
||||
|
||||
$this->get(route('verification.index'))
|
||||
->assertOk()
|
||||
->assertViewIs('verification.promotion-ended')
|
||||
->assertSee(CouponPoolExhaustedException::MESSAGE);
|
||||
}
|
||||
|
||||
public function test_send_otp_rejects_when_pool_exhausted(): void
|
||||
{
|
||||
$this->mock(CouponCodePool::class, function (MockInterface $mock): void {
|
||||
$mock->shouldReceive('hasAvailable')->andReturn(false);
|
||||
});
|
||||
|
||||
$this->from(route('verification.index'))
|
||||
->post(route('verification.send'), ['phone' => self::PHONE])
|
||||
->assertRedirect(route('verification.index'))
|
||||
->assertSessionHasErrors(['phone' => CouponPoolExhaustedException::MESSAGE]);
|
||||
}
|
||||
|
||||
public function test_verify_otp_rejects_wrong_code(): void
|
||||
{
|
||||
PhoneVerification::factory()
|
||||
@@ -164,6 +196,13 @@ class VerificationFlowTest extends TestCase
|
||||
->assertStatus(429);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
Mockery::close();
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
private function extractOtpFromLastSms(): string
|
||||
{
|
||||
$recorded = Http::recorded()->all();
|
||||
@@ -172,7 +211,7 @@ class VerificationFlowTest extends TestCase
|
||||
|
||||
[$request] = $recorded[array_key_last($recorded)];
|
||||
|
||||
preg_match('/(\d{4})/', (string) $request->data()['code'], $matches);
|
||||
preg_match('/(\d{4})/', (string) $request->data()['message'], $matches);
|
||||
|
||||
$this->assertNotEmpty($matches[1]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user