postJson('/api/register', [ 'nombre_apellido' => 'Ada Lovelace', 'email' => 'ada@example.com', 'password' => 'secret123', 'password_confirmation' => 'secret123', ]); $response ->assertCreated() ->assertJsonPath('message', 'Usuario registrado correctamente.') ->assertJsonPath('data.nombre_apellido', 'Ada Lovelace') ->assertJsonPath('data.email', 'ada@example.com'); $this->assertDatabaseHas('users', [ 'nombre_apellido' => 'Ada Lovelace', 'email' => 'ada@example.com', ]); $user = User::query()->where('email', 'ada@example.com')->firstOrFail(); $this->assertNotSame('secret123', $user->password); } public function test_it_validates_required_fields_and_unique_email(): void { User::factory()->create([ 'nombre_apellido' => 'Existing User', 'email' => 'existing@example.com', ]); $response = $this->postJson('/api/register', [ 'nombre_apellido' => '', 'email' => 'existing@example.com', 'password' => 'secret123', 'password_confirmation' => 'different-secret', ]); $response->assertUnprocessable()->assertJsonValidationErrors([ 'nombre_apellido', 'email', 'password', ]); } }