test password login
This commit is contained in:
parent
879c294582
commit
93f5f022e4
6 changed files with 220 additions and 0 deletions
|
|
@ -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',
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue