67 lines
2.0 KiB
PHP
67 lines
2.0 KiB
PHP
<?php
|
|
|
|
use App\Jobs\SendVerificationEmailJob;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Queue;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
it('shows registration notice with email after first step', function () {
|
|
Queue::fake();
|
|
|
|
$this->post('/register', [
|
|
'email' => '[email protected]',
|
|
])->assertRedirect('/register/notice');
|
|
|
|
$this->get('/register/notice')
|
|
->assertOk()
|
|
->assertSee('[email protected]')
|
|
->assertSee('Change email');
|
|
});
|
|
|
|
it('prefills register form email from query string', function () {
|
|
$this->get('/[email protected]')
|
|
->assertOk()
|
|
->assertSee('value="[email protected]"', false);
|
|
});
|
|
|
|
it('blocks resend while cooldown is active', function () {
|
|
Queue::fake();
|
|
|
|
$this->post('/register', [
|
|
'email' => '[email protected]',
|
|
])->assertRedirect('/register/notice');
|
|
|
|
$response = $this->from('/register/notice')->post('/register/resend-verification', [
|
|
'email' => '[email protected]',
|
|
]);
|
|
|
|
$response->assertRedirect('/register/notice');
|
|
$response->assertSessionHasNoErrors();
|
|
$response->assertSessionHas('status', 'If that email is valid, we sent a verification link.');
|
|
|
|
Queue::assertPushed(SendVerificationEmailJob::class, 1);
|
|
});
|
|
|
|
it('resends verification after cooldown expires', function () {
|
|
Queue::fake();
|
|
|
|
$this->post('/register', [
|
|
'email' => '[email protected]',
|
|
])->assertRedirect('/register/notice');
|
|
|
|
$user = User::query()->where('email', '[email protected]')->firstOrFail();
|
|
$user->forceFill([
|
|
'last_verification_sent_at' => now()->subMinutes(31),
|
|
])->save();
|
|
|
|
$this->post('/register/resend-verification', [
|
|
'email' => '[email protected]',
|
|
])->assertRedirect('/register/notice');
|
|
|
|
Queue::assertPushed(SendVerificationEmailJob::class, 2);
|
|
|
|
expect(User::query()->where('email', '[email protected]')->exists())->toBeTrue();
|
|
});
|