opnform-host-nginx/tests/Feature/RegisterTest.php

63 lines
1.7 KiB
PHP
Raw Normal View History

2022-09-20 21:59:52 +02:00
<?php
use App\Models\User;
2024-02-23 11:54:12 +01:00
2022-09-20 21:59:52 +02:00
it('can register', function () {
2024-01-14 20:52:14 +01:00
$this->postJson('/register', [
2022-09-20 21:59:52 +02:00
'name' => 'Test User',
'email' => 'test@test.app',
'hear_about_us' => 'google',
'password' => 'secret',
'password_confirmation' => 'secret',
2024-02-23 11:54:12 +01:00
'agree_terms' => true,
2022-09-20 21:59:52 +02:00
])
->assertSuccessful()
->assertJsonStructure(['id', 'name', 'email']);
$this->assertDatabaseHas('users', [
'name' => 'Test User',
2024-02-23 11:54:12 +01:00
'email' => 'test@test.app',
2022-09-20 21:59:52 +02:00
]);
});
it('cannot register with existing email', function () {
User::factory()->create(['email' => 'test@test.app']);
2024-01-14 20:52:14 +01:00
$this->postJson('/register', [
2022-09-20 21:59:52 +02: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 = [
2024-01-14 20:52:14 +01:00
'dumliyupse@gufum.com',
'kcs79722@zslsz.com',
'pfizexwxtdifxupdhr@tpwlb.com',
2024-02-23 11:54:12 +01:00
'qvj86ypqfm@email.edu.pl',
][rand(0, 3)];
2024-01-14 20:52:14 +01:00
$this->postJson('/register', [
2024-02-23 11:54:12 +01:00
'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 20:52:14 +01:00
});