Add form request validation tests for various client and admin requests
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Requests\Client\Auth;
|
||||
|
||||
use App\Http\Requests\Client\Auth\VerifyOtpRequest;
|
||||
use App\Models\OtpCode;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\Concerns\ValidatesFormRequests;
|
||||
use Tests\TestCase;
|
||||
|
||||
class VerifyOtpRequestTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase, ValidatesFormRequests;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
session(['login_phone' => '09120000000']);
|
||||
}
|
||||
|
||||
public function test_passes_with_valid_code_for_session_phone(): void
|
||||
{
|
||||
OtpCode::factory()->create(['phone' => '09120000000', 'code' => '1234']);
|
||||
|
||||
$this->assertPasses(VerifyOtpRequest::class, ['otp_code' => '1234']);
|
||||
}
|
||||
|
||||
public function test_fails_without_code(): void
|
||||
{
|
||||
$this->assertFailsOn('otp_code', VerifyOtpRequest::class, []);
|
||||
}
|
||||
|
||||
public function test_fails_when_code_is_not_four_digits(): void
|
||||
{
|
||||
OtpCode::factory()->create(['phone' => '09120000000', 'code' => '123']);
|
||||
|
||||
$this->assertFailsOn('otp_code', VerifyOtpRequest::class, ['otp_code' => '123']);
|
||||
$this->assertFailsOn('otp_code', VerifyOtpRequest::class, ['otp_code' => 'abcd']);
|
||||
}
|
||||
|
||||
public function test_fails_with_wrong_code(): void
|
||||
{
|
||||
OtpCode::factory()->create(['phone' => '09120000000', 'code' => '1234']);
|
||||
|
||||
$this->assertFailsOn('otp_code', VerifyOtpRequest::class, ['otp_code' => '0000']);
|
||||
}
|
||||
|
||||
public function test_fails_with_expired_code(): void
|
||||
{
|
||||
OtpCode::factory()->expired()->create(['phone' => '09120000000', 'code' => '1234']);
|
||||
|
||||
$this->assertFailsOn('otp_code', VerifyOtpRequest::class, ['otp_code' => '1234']);
|
||||
}
|
||||
|
||||
public function test_fails_when_code_belongs_to_another_phone(): void
|
||||
{
|
||||
OtpCode::factory()->create(['phone' => '09130000000', 'code' => '1234']);
|
||||
|
||||
$this->assertFailsOn('otp_code', VerifyOtpRequest::class, ['otp_code' => '1234']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user