resolve todos in website
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import { describe, it, expect, vi, type Mock } from 'vitest';
|
||||
import { GetCurrentUserSessionUseCase } from './GetCurrentUserSessionUseCase';
|
||||
import type { IdentitySessionPort } from '../ports/IdentitySessionPort';
|
||||
import type { AuthSessionDTO } from '../dto/AuthSessionDTO';
|
||||
|
||||
describe('GetCurrentUserSessionUseCase', () => {
|
||||
let sessionPort: {
|
||||
getCurrentSession: Mock;
|
||||
createSession: Mock;
|
||||
clearSession: Mock;
|
||||
};
|
||||
|
||||
let useCase: GetCurrentUserSessionUseCase;
|
||||
|
||||
beforeEach(() => {
|
||||
sessionPort = {
|
||||
getCurrentSession: vi.fn(),
|
||||
createSession: vi.fn(),
|
||||
clearSession: vi.fn(),
|
||||
};
|
||||
|
||||
useCase = new GetCurrentUserSessionUseCase(sessionPort as unknown as IdentitySessionPort);
|
||||
});
|
||||
|
||||
it('returns the current auth session when one exists', async () => {
|
||||
const session: AuthSessionDTO = {
|
||||
user: {
|
||||
id: 'user-1',
|
||||
email: 'test@example.com',
|
||||
displayName: 'Test User',
|
||||
primaryDriverId: 'driver-1',
|
||||
},
|
||||
issuedAt: Date.now(),
|
||||
expiresAt: Date.now() + 1000,
|
||||
token: 'token-123',
|
||||
};
|
||||
|
||||
sessionPort.getCurrentSession.mockResolvedValue(session);
|
||||
|
||||
const result = await useCase.execute();
|
||||
|
||||
expect(sessionPort.getCurrentSession).toHaveBeenCalledTimes(1);
|
||||
expect(result).toEqual(session);
|
||||
});
|
||||
|
||||
it('returns null when there is no active session', async () => {
|
||||
sessionPort.getCurrentSession.mockResolvedValue(null);
|
||||
|
||||
const result = await useCase.execute();
|
||||
|
||||
expect(sessionPort.getCurrentSession).toHaveBeenCalledTimes(1);
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user