core tests
This commit is contained in:
48
core/rating/application/use-cases/SaveRatingUseCase.test.ts
Normal file
48
core/rating/application/use-cases/SaveRatingUseCase.test.ts
Normal 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'
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user