feat: implement user registration functionality with validation and response handling

This commit is contained in:
2026-07-02 12:23:50 -03:00
parent 18eedd3209
commit a95cfc780b
16 changed files with 202 additions and 14 deletions

View File

@@ -0,0 +1,58 @@
<?php
namespace Tests\Feature\Auth;
use App\Domains\Auth\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class RegisterControllerTest extends TestCase
{
use RefreshDatabase;
public function test_it_registers_a_user(): void
{
$response = $this->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',
]);
}
}