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

@@ -2,6 +2,7 @@ import { vi, type Mock } from 'vitest';
import { GetCurrentSessionUseCase } from './GetCurrentSessionUseCase';
import { User } from '../../domain/entities/User';
import { IUserRepository, StoredUser } from '../../domain/repositories/IUserRepository';
import type { Logger, UseCaseOutputPort } from '@core/shared/application';
describe('GetCurrentSessionUseCase', () => {
let useCase: GetCurrentSessionUseCase;
@@ -12,6 +13,8 @@ describe('GetCurrentSessionUseCase', () => {
update: Mock;
emailExists: Mock;
};
let logger: Logger;
let output: UseCaseOutputPort<any> & { present: Mock };
beforeEach(() => {
mockUserRepo = {
@@ -21,7 +24,20 @@ describe('GetCurrentSessionUseCase', () => {
update: vi.fn(),
emailExists: vi.fn(),
};
useCase = new GetCurrentSessionUseCase(mockUserRepo as IUserRepository);
logger = {
debug: vi.fn(),
info: vi.fn(),
warn: vi.fn(),
error: vi.fn(),
} as unknown as Logger;
output = {
present: vi.fn(),
};
useCase = new GetCurrentSessionUseCase(
mockUserRepo as IUserRepository,
logger,
output,
);
});
it('should return User when user exists', async () => {
@@ -37,21 +53,24 @@ describe('GetCurrentSessionUseCase', () => {
};
mockUserRepo.findById.mockResolvedValue(storedUser);
const result = await useCase.execute(userId);
const result = await useCase.execute({ userId });
expect(mockUserRepo.findById).toHaveBeenCalledWith(userId);
expect(result).toBeInstanceOf(User);
expect(result?.getId().value).toBe(userId);
expect(result?.getDisplayName()).toBe('Test User');
expect(result.isOk()).toBe(true);
expect(output.present).toHaveBeenCalled();
const callArgs = output.present.mock.calls?.[0]?.[0];
expect(callArgs?.user).toBeInstanceOf(User);
expect(callArgs?.user.getId().value).toBe(userId);
expect(callArgs?.user.getDisplayName()).toBe('Test User');
});
it('should return null when user does not exist', async () => {
it('should return error when user does not exist', async () => {
const userId = 'user-123';
mockUserRepo.findById.mockResolvedValue(null);
const result = await useCase.execute(userId);
const result = await useCase.execute({ userId });
expect(mockUserRepo.findById).toHaveBeenCalledWith(userId);
expect(result).toBeNull();
expect(result.isErr()).toBe(true);
});
});