fix(user): update hidden attributes and handle soft-deleted users in registration
This commit is contained in:
@@ -135,4 +135,36 @@ class RegisterControllerTest extends TestCase
|
||||
'password',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_it_can_reuse_the_email_of_a_soft_deleted_user(): void
|
||||
{
|
||||
$deletedUser = User::factory()->create([
|
||||
'email' => 'reused@example.com',
|
||||
]);
|
||||
$deletedUser->delete();
|
||||
|
||||
$response = $this->postJson('/api/register', [
|
||||
'nombre_apellido' => 'New Account',
|
||||
'email' => 'reused@example.com',
|
||||
'password' => 'Secret!123',
|
||||
'password_confirmation' => 'Secret!123',
|
||||
])->assertCreated();
|
||||
|
||||
$newUserId = $response->json('data.id');
|
||||
|
||||
$this->assertNotSame($deletedUser->id, $newUserId);
|
||||
$this->assertSame(
|
||||
2,
|
||||
User::withTrashed()->where('email', 'reused@example.com')->count(),
|
||||
);
|
||||
$this->assertDatabaseHas('users', [
|
||||
'id' => $deletedUser->id,
|
||||
'active_email' => null,
|
||||
]);
|
||||
$this->assertDatabaseHas('users', [
|
||||
'id' => $newUserId,
|
||||
'active_email' => 'reused@example.com',
|
||||
'deleted_at' => null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user