core tests

This commit is contained in:
2026-01-24 19:19:16 +01:00
parent 5da14b1b21
commit 1e821c4a5c
8 changed files with 1499 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
/**
* Unit tests for SaveRatingUseCase
*/
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { SaveRatingUseCase } from './SaveRatingUseCase';
const mockRatingRepository = {
save: vi.fn(),
};
describe('SaveRatingUseCase', () => {
let useCase: SaveRatingUseCase;
beforeEach(() => {
vi.clearAllMocks();
useCase = new SaveRatingUseCase({
ratingRepository: mockRatingRepository as any,
});
});
describe('Scenario 11: Repository error wraps correctly', () => {
it('should wrap repository error with specific prefix', async () => {
// Given
const request = {
driverId: 'd1',
raceId: 'r1',
rating: 1200,
components: {
resultsStrength: 80,
consistency: 70,
cleanDriving: 90,
racecraft: 75,
reliability: 85,
teamContribution: 60,
},
};
const repoError = new Error('Database connection failed');
mockRatingRepository.save.mockRejectedValue(repoError);
// When & Then
await expect(useCase.execute(request)).rejects.toThrow(
'Failed to save rating: Error: Database connection failed'
);
});
});
});