opnform/tests/Feature/RegisterTest.php

65 lines
1.8 KiB
PHP
Raw Normal View History

2022-09-20 19:59:52 +00:00
<?php
use App\Models\User;
use Tests\TestCase;
use function Pest\Faker\faker;
2022-09-20 19:59:52 +00:00
it('can register', function () {
2024-01-14 19:52:14 +00:00
$this->postJson('/register', [
2022-09-20 19:59:52 +00:00
'name' => 'Test User',
'email' => 'test@test.app',
'hear_about_us' => 'google',
'password' => 'secret',
'password_confirmation' => 'secret',
'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']);
2024-01-14 19:52:14 +00:00
$this->postJson('/register', [
2022-09-20 19:59:52 +00:00
'name' => 'Test User',
'email' => 'test@test.app',
'password' => 'secret',
'password_confirmation' => 'secret',
])
->assertStatus(422)
->assertJsonValidationErrors(['email']);
});
it('cannot register with disposable email', function () {
// Select random email
$email = faker()->randomElement([
2024-01-14 19:52:14 +00:00
'dumliyupse@gufum.com',
'kcs79722@zslsz.com',
'pfizexwxtdifxupdhr@tpwlb.com',
'qvj86ypqfm@email.edu.pl'
]);
2024-01-14 19:52:14 +00:00
$this->postJson('/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.',
],
],
]);
2024-01-14 19:52:14 +00:00
});