feat: add optional 'dni' and 'telefono' fields to User model and registration process
This commit is contained in:
@@ -36,7 +36,7 @@ class LoginControllerTest extends TestCase
|
||||
$this->assertNotEmpty($response->json('token'));
|
||||
|
||||
$this->withHeader('Authorization', 'Bearer '.$response->json('token'))
|
||||
->getJson('/api/user')
|
||||
->getJson('/api/me')
|
||||
->assertOk()
|
||||
->assertJsonPath('id', $user->id)
|
||||
->assertJsonPath('email', 'grace@example.com');
|
||||
@@ -44,7 +44,7 @@ class LoginControllerTest extends TestCase
|
||||
|
||||
public function test_it_rejects_access_to_the_current_user_endpoint_without_a_token(): void
|
||||
{
|
||||
$this->getJson('/api/user')->assertUnauthorized();
|
||||
$this->getJson('/api/me')->assertUnauthorized();
|
||||
}
|
||||
|
||||
public function test_it_logs_out_the_current_token(): void
|
||||
|
||||
@@ -17,17 +17,23 @@ class RegisterControllerTest extends TestCase
|
||||
'email' => 'ada@example.com',
|
||||
'password' => 'secret123',
|
||||
'password_confirmation' => 'secret123',
|
||||
'dni' => '12345678A',
|
||||
'telefono' => '+541122334455',
|
||||
]);
|
||||
|
||||
$response
|
||||
->assertCreated()
|
||||
->assertJsonPath('message', 'Usuario registrado correctamente.')
|
||||
->assertJsonPath('data.nombre_apellido', 'Ada Lovelace')
|
||||
->assertJsonPath('data.email', 'ada@example.com');
|
||||
->assertJsonPath('data.email', 'ada@example.com')
|
||||
->assertJsonPath('data.dni', '12345678A')
|
||||
->assertJsonPath('data.telefono', '+541122334455');
|
||||
|
||||
$this->assertDatabaseHas('users', [
|
||||
'nombre_apellido' => 'Ada Lovelace',
|
||||
'email' => 'ada@example.com',
|
||||
'dni' => '12345678A',
|
||||
'telefono' => '+541122334455',
|
||||
]);
|
||||
|
||||
$user = User::query()->where('email', 'ada@example.com')->firstOrFail();
|
||||
@@ -35,6 +41,31 @@ class RegisterControllerTest extends TestCase
|
||||
$this->assertNotSame('secret123', $user->password);
|
||||
}
|
||||
|
||||
public function test_it_registers_a_user_without_optional_fields(): void
|
||||
{
|
||||
$response = $this->postJson('/api/register', [
|
||||
'nombre_apellido' => 'Alan Turing',
|
||||
'email' => 'alan@example.com',
|
||||
'password' => 'secret123',
|
||||
'password_confirmation' => 'secret123',
|
||||
]);
|
||||
|
||||
$response
|
||||
->assertCreated()
|
||||
->assertJsonPath('message', 'Usuario registrado correctamente.')
|
||||
->assertJsonPath('data.nombre_apellido', 'Alan Turing')
|
||||
->assertJsonPath('data.email', 'alan@example.com')
|
||||
->assertJsonPath('data.dni', null)
|
||||
->assertJsonPath('data.telefono', null);
|
||||
|
||||
$this->assertDatabaseHas('users', [
|
||||
'nombre_apellido' => 'Alan Turing',
|
||||
'email' => 'alan@example.com',
|
||||
'dni' => null,
|
||||
'telefono' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_it_validates_required_fields_and_unique_email(): void
|
||||
{
|
||||
User::factory()->create([
|
||||
|
||||
Reference in New Issue
Block a user