test logout flow
This commit is contained in:
parent
2e140cd8d8
commit
89f448bd42
3 changed files with 150 additions and 0 deletions
58
backend/tests/Unit/Auth/UseCases/LogoutTest.php
Normal file
58
backend/tests/Unit/Auth/UseCases/LogoutTest.php
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Unit\Auth\UseCases;
|
||||
|
||||
use App\Auth\CreateSessionDto;
|
||||
use App\Auth\UseCases\Logout\Logout;
|
||||
use App\Shared\ValueObject\EmailAddress;
|
||||
use App\User\User;
|
||||
use DateTimeImmutable;
|
||||
use DateTimeZone;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Tests\Fakes\FakeSessionRepository;
|
||||
|
||||
class LogoutTest extends TestCase
|
||||
{
|
||||
private FakeSessionRepository $sessionRepository;
|
||||
|
||||
private Logout $useCase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->sessionRepository = new FakeSessionRepository;
|
||||
$this->useCase = new Logout($this->sessionRepository);
|
||||
}
|
||||
|
||||
public function test_existing_token_session_is_removed(): void
|
||||
{
|
||||
$now = new DateTimeImmutable(
|
||||
'2026-07-31T12:00:00',
|
||||
new DateTimeZone('UTC'),
|
||||
);
|
||||
$this->sessionRepository->create(new CreateSessionDto(
|
||||
token: 'session-token',
|
||||
user: new User(
|
||||
id: 7,
|
||||
email: new EmailAddress('user@example.com'),
|
||||
passwordHash: 'hashed-password',
|
||||
),
|
||||
createdAt: $now,
|
||||
expiresAt: $now->modify('+7 days'),
|
||||
));
|
||||
|
||||
$this->useCase->execute('session-token');
|
||||
|
||||
$this->assertNull(
|
||||
$this->sessionRepository->findByToken('session-token'),
|
||||
);
|
||||
}
|
||||
|
||||
public function test_unknown_token_does_not_throw(): void
|
||||
{
|
||||
$this->useCase->execute('unknown-token');
|
||||
|
||||
$this->assertNull(
|
||||
$this->sessionRepository->findByToken('unknown-token'),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue