Files
gridpilot.gg/core/rating/application/use-cases/SaveRatingUseCase.test.ts
Marc Mintel afef777961
Some checks failed
CI / lint-typecheck (pull_request) Failing after 12s
CI / tests (pull_request) Has been skipped
CI / contract-tests (pull_request) Has been skipped
CI / e2e-tests (pull_request) Has been skipped
CI / comment-pr (pull_request) Has been skipped
CI / commit-types (pull_request) Has been skipped
code quality
2026-01-26 02:27:37 +01:00

50 lines
1.3 KiB
TypeScript

/**
* Unit tests for SaveRatingUseCase
*/
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { SaveRatingUseCase } from './SaveRatingUseCase';
import { RatingRepository } from '../../ports/RatingRepository';
const mockRatingRepository = {
save: vi.fn(),
};
describe('SaveRatingUseCase', () => {
let useCase: SaveRatingUseCase;
beforeEach(() => {
vi.clearAllMocks();
useCase = new SaveRatingUseCase({
ratingRepository: mockRatingRepository as unknown as RatingRepository,
});
});
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'
);
});
});
});