postJson('/web-api/register', [ 'name' => 'Admin One', 'email' => 'admin@example.com', 'password' => 'password123', 'password_confirmation' => 'password123', ]); $response->assertOk()->assertJson(['bootstrap' => true]); $user = User::where('email', 'admin@example.com')->firstOrFail(); $this->assertTrue($user->hasRole('admin')); $this->assertNotNull($user->approved_at); $this->assertAuthenticatedAs($user); } public function test_second_user_registration_is_pending_and_not_logged_in(): void { $this->postJson('/web-api/register', [ 'name' => 'Admin One', 'email' => 'admin@example.com', 'password' => 'password123', 'password_confirmation' => 'password123', ])->assertOk(); $this->postJson('/web-api/logout'); $response = $this->postJson('/web-api/register', [ 'name' => 'Regular User', 'email' => 'user@example.com', 'password' => 'password123', 'password_confirmation' => 'password123', ]); $response->assertCreated()->assertJson(['pending' => true]); $user = User::where('email', 'user@example.com')->firstOrFail(); $this->assertTrue($user->hasRole('user')); $this->assertNull($user->approved_at); $this->assertGuest(); } public function test_registration_requires_matching_password_confirmation(): void { $response = $this->postJson('/web-api/register', [ 'name' => 'Someone', 'email' => 'someone@example.com', 'password' => 'password123', 'password_confirmation' => 'different', ]); $response->assertUnprocessable()->assertJsonValidationErrors('password'); } public function test_registration_requires_unique_email(): void { User::factory()->create(['email' => 'taken@example.com']); $response = $this->postJson('/web-api/register', [ 'name' => 'Someone', 'email' => 'taken@example.com', 'password' => 'password123', 'password_confirmation' => 'password123', ]); $response->assertUnprocessable()->assertJsonValidationErrors('email'); } }