Added placeholder users; Better exception handling; Enhanced local setup

This commit is contained in:
Constantin Graf
2024-03-08 13:31:49 +01:00
parent 0ed5d14817
commit 77e7a63b83
38 changed files with 882 additions and 89 deletions

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Tests\Feature;
use App\Models\User;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Laravel\Fortify\Features;
@@ -38,10 +39,47 @@ class RegistrationTest extends TestCase
public function test_new_users_can_register(): void
{
if (! Features::enabled(Features::registration())) {
$this->markTestSkipped('Registration support is not enabled.');
}
$response = $this->post('/register', [
'name' => 'Test User',
'email' => 'test@example.com',
'password' => 'password',
'password_confirmation' => 'password',
'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature(),
]);
$this->assertAuthenticated();
$response->assertRedirect(RouteServiceProvider::HOME);
}
public function test_new_users_can_not_register_if_user_with_email_already_exists(): void
{
// Arrange
$user = User::factory()->create([
'email' => 'test@example.com',
]);
// Act
$response = $this->post('/register', [
'name' => 'Test User',
'email' => 'test@example.com',
'password' => 'password',
'password_confirmation' => 'password',
'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature(),
]);
$this->assertFalse($this->isAuthenticated(), 'The user is authenticated');
$response->assertInvalid(['email']);
}
public function test_new_users_can_register_if_placeholder_user_with_email_already_exists(): void
{
// Arrange
$user = User::factory()->create([
'email' => 'test@example.com',
'is_placeholder' => true,
]);
// Act
$response = $this->post('/register', [
'name' => 'Test User',
'email' => 'test@example.com',