61 lines
1.7 KiB
PHP
61 lines
1.7 KiB
PHP
<?php
|
|
|
|
use App\Mail\RegistrationVerificationMail;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\Support\Facades\Mail;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
it('shows registration notice with email after first step', function () {
|
|
Mail::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 () {
|
|
Mail::fake();
|
|
|
|
$this->post('/register', [
|
|
'email' => '[email protected]',
|
|
])->assertRedirect('/register/notice');
|
|
|
|
$this->from('/register/notice')->post('/register/resend-verification', [
|
|
'email' => '[email protected]',
|
|
])->assertRedirect('/register/notice')
|
|
->assertSessionHasErrors('email');
|
|
});
|
|
|
|
it('resends verification after cooldown expires', function () {
|
|
Mail::fake();
|
|
|
|
$this->post('/register', [
|
|
'email' => '[email protected]',
|
|
])->assertRedirect('/register/notice');
|
|
|
|
$key = 'register:resend:cooldown:' . sha1('[email protected]');
|
|
Cache::forget($key);
|
|
|
|
$this->post('/register/resend-verification', [
|
|
'email' => '[email protected]',
|
|
])->assertRedirect('/register/notice');
|
|
|
|
Mail::assertQueued(RegistrationVerificationMail::class, 2);
|
|
|
|
expect(User::query()->where('email', '[email protected]')->exists())->toBeTrue();
|
|
});
|