test password login

This commit is contained in:
Yisroel Baum 2026-07-31 11:34:50 +03:00
parent 879c294582
commit 93f5f022e4
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
6 changed files with 220 additions and 0 deletions

View file

@ -17,6 +17,7 @@ class EloquentUserRepositoryTest extends TestCase
$repository = app(UserRepository::class);
$user = $repository->create(new CreateUserDto(
email: new EmailAddress('Founder@EXAMPLE.COM'),
password: 'correct-password',
));
$this->assertGreaterThan(0, $user->getId());
@ -28,6 +29,10 @@ class EloquentUserRepositoryTest extends TestCase
'id' => $user->getId(),
'email' => 'Founder@example.com',
]);
$this->assertDatabaseMissing('users', [
'id' => $user->getId(),
'password' => 'correct-password',
]);
$foundUser = $repository->find($user->getId());
@ -45,4 +50,39 @@ class EloquentUserRepositoryTest extends TestCase
$this->assertNull($repository->find(999));
}
public function test_it_finds_a_user_with_matching_credentials(): void
{
$repository = app(UserRepository::class);
$createdUser = $repository->create(new CreateUserDto(
email: new EmailAddress('user@example.com'),
password: 'correct-password',
));
$foundUser = $repository->findByCredentials(
new EmailAddress('user@EXAMPLE.COM'),
'correct-password',
);
$this->assertNotNull($foundUser);
$this->assertSame($createdUser->getId(), $foundUser->getId());
}
public function test_it_rejects_non_matching_credentials(): void
{
$repository = app(UserRepository::class);
$repository->create(new CreateUserDto(
email: new EmailAddress('user@example.com'),
password: 'correct-password',
));
$this->assertNull($repository->findByCredentials(
new EmailAddress('user@example.com'),
'wrong-password',
));
$this->assertNull($repository->findByCredentials(
new EmailAddress('unknown@example.com'),
'correct-password',
));
}
}