2022-09-20 19:59:52 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use App\Models\User;
|
|
|
|
use Tests\TestCase;
|
2023-04-28 09:37:39 +00:00
|
|
|
use function Pest\Faker\faker;
|
2022-09-20 19:59:52 +00:00
|
|
|
|
|
|
|
it('can register', function () {
|
|
|
|
$this->postJson('/api/register', [
|
|
|
|
'name' => 'Test User',
|
|
|
|
'email' => 'test@test.app',
|
|
|
|
'hear_about_us' => 'google',
|
|
|
|
'password' => 'secret',
|
|
|
|
'password_confirmation' => 'secret',
|
2022-10-19 08:18:07 +00:00
|
|
|
'agree_terms' => true
|
2022-09-20 19:59:52 +00:00
|
|
|
])
|
|
|
|
->assertSuccessful()
|
|
|
|
->assertJsonStructure(['id', 'name', 'email']);
|
|
|
|
$this->assertDatabaseHas('users', [
|
|
|
|
'name' => 'Test User',
|
|
|
|
'email' => 'test@test.app'
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('cannot register with existing email', function () {
|
|
|
|
User::factory()->create(['email' => 'test@test.app']);
|
|
|
|
|
|
|
|
$this->postJson('/api/register', [
|
|
|
|
'name' => 'Test User',
|
|
|
|
'email' => 'test@test.app',
|
|
|
|
'password' => 'secret',
|
|
|
|
'password_confirmation' => 'secret',
|
|
|
|
])
|
|
|
|
->assertStatus(422)
|
|
|
|
->assertJsonValidationErrors(['email']);
|
|
|
|
});
|
2023-04-28 09:37:39 +00:00
|
|
|
|
|
|
|
it('cannot register with disposable email', function () {
|
|
|
|
// Select random email
|
|
|
|
$email = faker()->randomElement([
|
|
|
|
'dumliyupse@gufum.com',
|
|
|
|
'kcs79722@zslsz.com',
|
|
|
|
'pfizexwxtdifxupdhr@tpwlb.com',
|
|
|
|
'qvj86ypqfm@email.edu.pl'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->postJson('/api/register', [
|
|
|
|
'name' => 'Test disposable',
|
|
|
|
'email' => $email,
|
|
|
|
'hear_about_us' => 'google',
|
|
|
|
'password' => 'secret',
|
|
|
|
'password_confirmation' => 'secret',
|
|
|
|
'agree_terms' => true
|
|
|
|
])
|
|
|
|
->assertStatus(422)
|
|
|
|
->assertJsonValidationErrors(['email'])
|
|
|
|
->assertJson([
|
|
|
|
'message' => 'Disposable email addresses are not allowed.',
|
|
|
|
'errors' => [
|
|
|
|
'email' => [
|
|
|
|
'Disposable email addresses are not allowed.',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
});
|