fix issues in core

This commit is contained in:
2025-12-23 11:25:08 +01:00
parent 1efd971032
commit 2854ae3c5c
113 changed files with 1142 additions and 458 deletions

View File

@@ -5,6 +5,7 @@ import type { IdentitySessionPort } from '../ports/IdentitySessionPort';
import type { AuthCallbackCommandDTO } from '../dto/AuthCallbackCommandDTO';
import type { AuthenticatedUserDTO } from '../dto/AuthenticatedUserDTO';
import type { AuthSessionDTO } from '../dto/AuthSessionDTO';
import type { Logger, UseCaseOutputPort } from '@core/shared/application';
describe('HandleAuthCallbackUseCase', () => {
let provider: {
@@ -15,6 +16,8 @@ describe('HandleAuthCallbackUseCase', () => {
getCurrentSession: Mock;
clearSession: Mock;
};
let logger: Logger;
let output: UseCaseOutputPort<any> & { present: Mock };
let useCase: HandleAuthCallbackUseCase;
beforeEach(() => {
@@ -26,18 +29,30 @@ describe('HandleAuthCallbackUseCase', () => {
getCurrentSession: vi.fn(),
clearSession: vi.fn(),
};
logger = {
debug: vi.fn(),
info: vi.fn(),
warn: vi.fn(),
error: vi.fn(),
} as unknown as Logger;
output = {
present: vi.fn(),
};
useCase = new HandleAuthCallbackUseCase(
provider as unknown as IdentityProviderPort,
sessionPort as unknown as IdentitySessionPort,
logger,
output,
);
});
it('completes auth and creates a session', async () => {
const command: AuthCallbackCommandDTO = {
provider: 'IRACING_DEMO',
code: 'auth-code',
state: 'state-123',
redirectUri: 'https://app/callback',
returnTo: 'https://app/callback',
};
const user: AuthenticatedUserDTO = {
@@ -60,6 +75,7 @@ describe('HandleAuthCallbackUseCase', () => {
expect(provider.completeAuth).toHaveBeenCalledWith(command);
expect(sessionPort.createSession).toHaveBeenCalledWith(user);
expect(result).toEqual(session);
expect(output.present).toHaveBeenCalledWith(session);
expect(result.isOk()).toBe(true);
});
});