feat(test): init test auth
This commit is contained in:
parent
a4085e7852
commit
d7ab87ae75
8 changed files with 460 additions and 21 deletions
59
tests/Unit/Auth/AuthenticationTest.php
Normal file
59
tests/Unit/Auth/AuthenticationTest.php
Normal file
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
use App\Actions\Fortify\LoginUser;
|
||||
use function Pest\Laravel\post;
|
||||
|
||||
|
||||
it('logs in a user with MD5 password', function () {
|
||||
$userInfo = [
|
||||
'username' => 'testuser',
|
||||
'password' => 'password',
|
||||
];
|
||||
|
||||
$response = post(
|
||||
'/login',
|
||||
['username' => $userInfo['username'], 'password' => $userInfo['password']],
|
||||
['Accept' => 'application/json']
|
||||
);
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
$data = $response->json()['data'];
|
||||
|
||||
expect($data['username'])->toBe($userInfo['password']);
|
||||
});
|
||||
|
||||
it('logs in a normal user with hashed password', function () {
|
||||
// Arrange
|
||||
$request = (object)['username' => 'testestest', 'password' => 'testestest'];
|
||||
|
||||
// Act
|
||||
$result = LoginUser::login($request);
|
||||
|
||||
// Assert
|
||||
expect($result)->toBe($this->user);
|
||||
});
|
||||
|
||||
it('returns null for non-existent user', function () {
|
||||
// Arrange
|
||||
$request = (object)['username' => 'nonexistent', 'password' => 'password'];
|
||||
$this->userMock->shouldReceive('where->first')->andReturn(null);
|
||||
|
||||
// Act
|
||||
$result = LoginUser::login($request);
|
||||
|
||||
// Assert
|
||||
expect($result)->toBeNull();
|
||||
});
|
||||
|
||||
it('returns password error for existent user', function () {
|
||||
// Arrange
|
||||
$request = (object)['username' => 'testestest', 'password' => 'balaclava'];
|
||||
$this->userMock->shouldReceive('where->first')->andReturn(null);
|
||||
|
||||
// Act
|
||||
$result = LoginUser::login($request);
|
||||
|
||||
// Assert
|
||||
expect($result)->toBeNull();
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue