test auth contracts
This commit is contained in:
parent
3da9c586c3
commit
b3266b38c8
15 changed files with 457 additions and 165 deletions
|
|
@ -17,7 +17,7 @@ class EloquentUserRepositoryTest extends TestCase
|
|||
$repository = app(UserRepository::class);
|
||||
$user = $repository->create(new CreateUserDto(
|
||||
email: new EmailAddress('Founder@EXAMPLE.COM'),
|
||||
password: 'correct-password',
|
||||
passwordHash: 'hashed-password',
|
||||
));
|
||||
|
||||
$this->assertGreaterThan(0, $user->getId());
|
||||
|
|
@ -29,9 +29,9 @@ class EloquentUserRepositoryTest extends TestCase
|
|||
'id' => $user->getId(),
|
||||
'email' => 'Founder@example.com',
|
||||
]);
|
||||
$this->assertDatabaseMissing('users', [
|
||||
$this->assertDatabaseHas('users', [
|
||||
'id' => $user->getId(),
|
||||
'password' => 'correct-password',
|
||||
'passwordHash' => 'hashed-password',
|
||||
]);
|
||||
|
||||
$foundUser = $repository->find($user->getId());
|
||||
|
|
@ -42,6 +42,10 @@ class EloquentUserRepositoryTest extends TestCase
|
|||
$user->getEmail()->value(),
|
||||
$foundUser->getEmail()->value(),
|
||||
);
|
||||
$this->assertSame(
|
||||
$user->getPasswordHash(),
|
||||
$foundUser->getPasswordHash(),
|
||||
);
|
||||
}
|
||||
|
||||
public function test_it_returns_null_for_an_unknown_user(): void
|
||||
|
|
@ -51,38 +55,27 @@ class EloquentUserRepositoryTest extends TestCase
|
|||
$this->assertNull($repository->find(999));
|
||||
}
|
||||
|
||||
public function test_it_finds_a_user_with_matching_credentials(): void
|
||||
public function test_it_finds_a_user_by_email(): void
|
||||
{
|
||||
$repository = app(UserRepository::class);
|
||||
$createdUser = $repository->create(new CreateUserDto(
|
||||
email: new EmailAddress('user@example.com'),
|
||||
password: 'correct-password',
|
||||
passwordHash: 'hashed-password',
|
||||
));
|
||||
|
||||
$foundUser = $repository->findByCredentials(
|
||||
$foundUser = $repository->findByEmail(
|
||||
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
|
||||
public function test_it_returns_null_for_an_unknown_email(): 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(
|
||||
$this->assertNull($repository->findByEmail(
|
||||
new EmailAddress('unknown@example.com'),
|
||||
'correct-password',
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue