core tests
This commit is contained in:
354
core/rating/application/use-cases/CalculateRatingUseCase.test.ts
Normal file
354
core/rating/application/use-cases/CalculateRatingUseCase.test.ts
Normal file
@@ -0,0 +1,354 @@
|
||||
/**
|
||||
* Unit tests for CalculateRatingUseCase
|
||||
*
|
||||
* Tests business logic and orchestration using mocked ports.
|
||||
*/
|
||||
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { CalculateRatingUseCase } from './CalculateRatingUseCase';
|
||||
import { Driver } from '../../../racing/domain/entities/Driver';
|
||||
import { Race } from '../../../racing/domain/entities/Race';
|
||||
import { Result } from '../../../racing/domain/entities/result/Result';
|
||||
import { Rating } from '../../domain/Rating';
|
||||
import { RatingCalculatedEvent } from '../../domain/events/RatingCalculatedEvent';
|
||||
|
||||
// Mock repositories and publisher
|
||||
const mockDriverRepository = {
|
||||
findById: vi.fn(),
|
||||
};
|
||||
|
||||
const mockRaceRepository = {
|
||||
findById: vi.fn(),
|
||||
};
|
||||
|
||||
const mockResultRepository = {
|
||||
findByRaceId: vi.fn(),
|
||||
};
|
||||
|
||||
const mockRatingRepository = {
|
||||
save: vi.fn(),
|
||||
};
|
||||
|
||||
const mockEventPublisher = {
|
||||
publish: vi.fn(),
|
||||
};
|
||||
|
||||
describe('CalculateRatingUseCase', () => {
|
||||
let useCase: CalculateRatingUseCase;
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
useCase = new CalculateRatingUseCase({
|
||||
driverRepository: mockDriverRepository as any,
|
||||
raceRepository: mockRaceRepository as any,
|
||||
resultRepository: mockResultRepository as any,
|
||||
ratingRepository: mockRatingRepository as any,
|
||||
eventPublisher: mockEventPublisher as any,
|
||||
});
|
||||
});
|
||||
|
||||
describe('Scenario 1: Driver missing', () => {
|
||||
it('should return error when driver is not found', async () => {
|
||||
// Given
|
||||
mockDriverRepository.findById.mockResolvedValue(null);
|
||||
|
||||
// When
|
||||
const result = await useCase.execute({
|
||||
driverId: 'driver-123',
|
||||
raceId: 'race-456',
|
||||
});
|
||||
|
||||
// Then
|
||||
expect(result.isErr()).toBe(true);
|
||||
expect(result.unwrapErr().message).toBe('Driver not found');
|
||||
expect(mockRatingRepository.save).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Scenario 2: Race missing', () => {
|
||||
it('should return error when race is not found', async () => {
|
||||
// Given
|
||||
const mockDriver = Driver.create({
|
||||
id: 'driver-123',
|
||||
iracingId: 'iracing-123',
|
||||
name: 'Test Driver',
|
||||
country: 'US',
|
||||
});
|
||||
mockDriverRepository.findById.mockResolvedValue(mockDriver);
|
||||
mockRaceRepository.findById.mockResolvedValue(null);
|
||||
|
||||
// When
|
||||
const result = await useCase.execute({
|
||||
driverId: 'driver-123',
|
||||
raceId: 'race-456',
|
||||
});
|
||||
|
||||
// Then
|
||||
expect(result.isErr()).toBe(true);
|
||||
expect(result.unwrapErr().message).toBe('Race not found');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Scenario 3: No results', () => {
|
||||
it('should return error when no results found for race', async () => {
|
||||
// Given
|
||||
const mockDriver = Driver.create({
|
||||
id: 'driver-123',
|
||||
iracingId: 'iracing-123',
|
||||
name: 'Test Driver',
|
||||
country: 'US',
|
||||
});
|
||||
const mockRace = Race.create({
|
||||
id: 'race-456',
|
||||
leagueId: 'league-789',
|
||||
scheduledAt: new Date(),
|
||||
track: 'Test Track',
|
||||
car: 'Test Car',
|
||||
});
|
||||
mockDriverRepository.findById.mockResolvedValue(mockDriver);
|
||||
mockRaceRepository.findById.mockResolvedValue(mockRace);
|
||||
mockResultRepository.findByRaceId.mockResolvedValue([]);
|
||||
|
||||
// When
|
||||
const result = await useCase.execute({
|
||||
driverId: 'driver-123',
|
||||
raceId: 'race-456',
|
||||
});
|
||||
|
||||
// Then
|
||||
expect(result.isErr()).toBe(true);
|
||||
expect(result.unwrapErr().message).toBe('No results found for race');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Scenario 4: Driver not present in results', () => {
|
||||
it('should return error when driver is not in race results', async () => {
|
||||
// Given
|
||||
const mockDriver = Driver.create({
|
||||
id: 'driver-123',
|
||||
iracingId: 'iracing-123',
|
||||
name: 'Test Driver',
|
||||
country: 'US',
|
||||
});
|
||||
const mockRace = Race.create({
|
||||
id: 'race-456',
|
||||
leagueId: 'league-789',
|
||||
scheduledAt: new Date(),
|
||||
track: 'Test Track',
|
||||
car: 'Test Car',
|
||||
});
|
||||
const otherResult = Result.create({
|
||||
id: 'result-1',
|
||||
raceId: 'race-456',
|
||||
driverId: 'driver-456',
|
||||
position: 1,
|
||||
fastestLap: 60000,
|
||||
incidents: 0,
|
||||
startPosition: 1,
|
||||
points: 25,
|
||||
});
|
||||
mockDriverRepository.findById.mockResolvedValue(mockDriver);
|
||||
mockRaceRepository.findById.mockResolvedValue(mockRace);
|
||||
mockResultRepository.findByRaceId.mockResolvedValue([otherResult]);
|
||||
|
||||
// When
|
||||
const result = await useCase.execute({
|
||||
driverId: 'driver-123',
|
||||
raceId: 'race-456',
|
||||
});
|
||||
|
||||
// Then
|
||||
expect(result.isErr()).toBe(true);
|
||||
expect(result.unwrapErr().message).toBe('Driver not found in race results');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Scenario 5: Publishes event after save', () => {
|
||||
it('should call ratingRepository.save before eventPublisher.publish', async () => {
|
||||
// Given
|
||||
const mockDriver = Driver.create({
|
||||
id: 'driver-123',
|
||||
iracingId: 'iracing-123',
|
||||
name: 'Test Driver',
|
||||
country: 'US',
|
||||
});
|
||||
const mockRace = Race.create({
|
||||
id: 'race-456',
|
||||
leagueId: 'league-789',
|
||||
scheduledAt: new Date(),
|
||||
track: 'Test Track',
|
||||
car: 'Test Car',
|
||||
});
|
||||
const mockResult = Result.create({
|
||||
id: 'result-1',
|
||||
raceId: 'race-456',
|
||||
driverId: 'driver-123',
|
||||
position: 1,
|
||||
fastestLap: 60000,
|
||||
incidents: 0,
|
||||
startPosition: 1,
|
||||
points: 25,
|
||||
});
|
||||
mockDriverRepository.findById.mockResolvedValue(mockDriver);
|
||||
mockRaceRepository.findById.mockResolvedValue(mockRace);
|
||||
mockResultRepository.findByRaceId.mockResolvedValue([mockResult]);
|
||||
mockRatingRepository.save.mockResolvedValue(undefined);
|
||||
mockEventPublisher.publish.mockResolvedValue(undefined);
|
||||
|
||||
// When
|
||||
const result = await useCase.execute({
|
||||
driverId: 'driver-123',
|
||||
raceId: 'race-456',
|
||||
});
|
||||
|
||||
// Then
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(mockRatingRepository.save).toHaveBeenCalledTimes(1);
|
||||
expect(mockEventPublisher.publish).toHaveBeenCalledTimes(1);
|
||||
|
||||
// Verify call order: save should be called before publish
|
||||
const saveCallOrder = mockRatingRepository.save.mock.invocationCallOrder[0];
|
||||
const publishCallOrder = mockEventPublisher.publish.mock.invocationCallOrder[0];
|
||||
expect(saveCallOrder).toBeLessThan(publishCallOrder);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Scenario 6: Component boundaries for cleanDriving', () => {
|
||||
it('should return cleanDriving = 100 when incidents = 0', async () => {
|
||||
// Given
|
||||
const mockDriver = Driver.create({
|
||||
id: 'driver-123',
|
||||
iracingId: 'iracing-123',
|
||||
name: 'Test Driver',
|
||||
country: 'US',
|
||||
});
|
||||
const mockRace = Race.create({
|
||||
id: 'race-456',
|
||||
leagueId: 'league-789',
|
||||
scheduledAt: new Date(),
|
||||
track: 'Test Track',
|
||||
car: 'Test Car',
|
||||
});
|
||||
const mockResult = Result.create({
|
||||
id: 'result-1',
|
||||
raceId: 'race-456',
|
||||
driverId: 'driver-123',
|
||||
position: 1,
|
||||
fastestLap: 60000,
|
||||
incidents: 0,
|
||||
startPosition: 1,
|
||||
points: 25,
|
||||
});
|
||||
mockDriverRepository.findById.mockResolvedValue(mockDriver);
|
||||
mockRaceRepository.findById.mockResolvedValue(mockRace);
|
||||
mockResultRepository.findByRaceId.mockResolvedValue([mockResult]);
|
||||
mockRatingRepository.save.mockResolvedValue(undefined);
|
||||
mockEventPublisher.publish.mockResolvedValue(undefined);
|
||||
|
||||
// When
|
||||
const result = await useCase.execute({
|
||||
driverId: 'driver-123',
|
||||
raceId: 'race-456',
|
||||
});
|
||||
|
||||
// Then
|
||||
expect(result.isOk()).toBe(true);
|
||||
const rating = result.unwrap();
|
||||
expect(rating.components.cleanDriving).toBe(100);
|
||||
});
|
||||
|
||||
it('should return cleanDriving = 20 when incidents >= 5', async () => {
|
||||
// Given
|
||||
const mockDriver = Driver.create({
|
||||
id: 'driver-123',
|
||||
iracingId: 'iracing-123',
|
||||
name: 'Test Driver',
|
||||
country: 'US',
|
||||
});
|
||||
const mockRace = Race.create({
|
||||
id: 'race-456',
|
||||
leagueId: 'league-789',
|
||||
scheduledAt: new Date(),
|
||||
track: 'Test Track',
|
||||
car: 'Test Car',
|
||||
});
|
||||
const mockResult = Result.create({
|
||||
id: 'result-1',
|
||||
raceId: 'race-456',
|
||||
driverId: 'driver-123',
|
||||
position: 1,
|
||||
fastestLap: 60000,
|
||||
incidents: 5,
|
||||
startPosition: 1,
|
||||
points: 25,
|
||||
});
|
||||
mockDriverRepository.findById.mockResolvedValue(mockDriver);
|
||||
mockRaceRepository.findById.mockResolvedValue(mockRace);
|
||||
mockResultRepository.findByRaceId.mockResolvedValue([mockResult]);
|
||||
mockRatingRepository.save.mockResolvedValue(undefined);
|
||||
mockEventPublisher.publish.mockResolvedValue(undefined);
|
||||
|
||||
// When
|
||||
const result = await useCase.execute({
|
||||
driverId: 'driver-123',
|
||||
raceId: 'race-456',
|
||||
});
|
||||
|
||||
// Then
|
||||
expect(result.isOk()).toBe(true);
|
||||
const rating = result.unwrap();
|
||||
expect(rating.components.cleanDriving).toBe(20);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Scenario 7: Time-dependent output', () => {
|
||||
it('should produce deterministic timestamp when time is frozen', async () => {
|
||||
// Given
|
||||
const frozenTime = new Date('2024-01-01T12:00:00.000Z');
|
||||
vi.useFakeTimers();
|
||||
vi.setSystemTime(frozenTime);
|
||||
|
||||
const mockDriver = Driver.create({
|
||||
id: 'driver-123',
|
||||
iracingId: 'iracing-123',
|
||||
name: 'Test Driver',
|
||||
country: 'US',
|
||||
});
|
||||
const mockRace = Race.create({
|
||||
id: 'race-456',
|
||||
leagueId: 'league-789',
|
||||
scheduledAt: new Date(),
|
||||
track: 'Test Track',
|
||||
car: 'Test Car',
|
||||
});
|
||||
const mockResult = Result.create({
|
||||
id: 'result-1',
|
||||
raceId: 'race-456',
|
||||
driverId: 'driver-123',
|
||||
position: 1,
|
||||
fastestLap: 60000,
|
||||
incidents: 0,
|
||||
startPosition: 1,
|
||||
points: 25,
|
||||
});
|
||||
mockDriverRepository.findById.mockResolvedValue(mockDriver);
|
||||
mockRaceRepository.findById.mockResolvedValue(mockRace);
|
||||
mockResultRepository.findByRaceId.mockResolvedValue([mockResult]);
|
||||
mockRatingRepository.save.mockResolvedValue(undefined);
|
||||
mockEventPublisher.publish.mockResolvedValue(undefined);
|
||||
|
||||
// When
|
||||
const result = await useCase.execute({
|
||||
driverId: 'driver-123',
|
||||
raceId: 'race-456',
|
||||
});
|
||||
|
||||
// Then
|
||||
expect(result.isOk()).toBe(true);
|
||||
const rating = result.unwrap();
|
||||
expect(rating.timestamp).toEqual(frozenTime);
|
||||
|
||||
vi.useRealTimers();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,132 @@
|
||||
/**
|
||||
* Unit tests for CalculateTeamContributionUseCase
|
||||
*/
|
||||
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { CalculateTeamContributionUseCase } from './CalculateTeamContributionUseCase';
|
||||
import { Driver } from '../../../racing/domain/entities/Driver';
|
||||
import { Race } from '../../../racing/domain/entities/Race';
|
||||
import { Result } from '../../../racing/domain/entities/result/Result';
|
||||
import { Rating } from '../../domain/Rating';
|
||||
|
||||
const mockRatingRepository = {
|
||||
findByDriverAndRace: vi.fn(),
|
||||
save: vi.fn(),
|
||||
};
|
||||
|
||||
const mockDriverRepository = {
|
||||
findById: vi.fn(),
|
||||
};
|
||||
|
||||
const mockRaceRepository = {
|
||||
findById: vi.fn(),
|
||||
};
|
||||
|
||||
const mockResultRepository = {
|
||||
findByRaceId: vi.fn(),
|
||||
};
|
||||
|
||||
describe('CalculateTeamContributionUseCase', () => {
|
||||
let useCase: CalculateTeamContributionUseCase;
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
useCase = new CalculateTeamContributionUseCase({
|
||||
ratingRepository: mockRatingRepository as any,
|
||||
driverRepository: mockDriverRepository as any,
|
||||
raceRepository: mockRaceRepository as any,
|
||||
resultRepository: mockResultRepository as any,
|
||||
});
|
||||
});
|
||||
|
||||
describe('Scenario 8: Creates rating when missing', () => {
|
||||
it('should create and save a new rating when none exists', async () => {
|
||||
// Given
|
||||
const driverId = 'driver-1';
|
||||
const raceId = 'race-1';
|
||||
const points = 25;
|
||||
|
||||
mockDriverRepository.findById.mockResolvedValue(Driver.create({
|
||||
id: driverId,
|
||||
iracingId: 'ir-1',
|
||||
name: 'Driver 1',
|
||||
country: 'US'
|
||||
}));
|
||||
mockRaceRepository.findById.mockResolvedValue(Race.create({
|
||||
id: raceId,
|
||||
leagueId: 'l-1',
|
||||
scheduledAt: new Date(),
|
||||
track: 'Track',
|
||||
car: 'Car'
|
||||
}));
|
||||
mockResultRepository.findByRaceId.mockResolvedValue([
|
||||
Result.create({
|
||||
id: 'res-1',
|
||||
raceId,
|
||||
driverId,
|
||||
position: 1,
|
||||
points,
|
||||
incidents: 0,
|
||||
startPosition: 1,
|
||||
fastestLap: 0
|
||||
})
|
||||
]);
|
||||
mockRatingRepository.findByDriverAndRace.mockResolvedValue(null);
|
||||
|
||||
// When
|
||||
const result = await useCase.execute({ driverId, raceId });
|
||||
|
||||
// Then
|
||||
expect(mockRatingRepository.save).toHaveBeenCalled();
|
||||
const savedRating = mockRatingRepository.save.mock.calls[0][0] as Rating;
|
||||
expect(savedRating.components.teamContribution).toBe(100); // 25/25 * 100
|
||||
expect(result.teamContribution).toBe(100);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Scenario 9: Updates existing rating', () => {
|
||||
it('should preserve other fields and only update teamContribution', async () => {
|
||||
// Given
|
||||
const driverId = 'driver-1';
|
||||
const raceId = 'race-1';
|
||||
const points = 12.5; // 50% contribution
|
||||
|
||||
const existingRating = Rating.create({
|
||||
driverId: 'driver-1' as any, // Simplified for test
|
||||
raceId: 'race-1' as any,
|
||||
rating: 1500,
|
||||
components: {
|
||||
resultsStrength: 80,
|
||||
consistency: 70,
|
||||
cleanDriving: 90,
|
||||
racecraft: 75,
|
||||
reliability: 85,
|
||||
teamContribution: 10, // Old value
|
||||
},
|
||||
timestamp: new Date('2023-01-01')
|
||||
});
|
||||
|
||||
mockDriverRepository.findById.mockResolvedValue({ id: driverId } as any);
|
||||
mockRaceRepository.findById.mockResolvedValue({ id: raceId } as any);
|
||||
mockResultRepository.findByRaceId.mockResolvedValue([
|
||||
{ driverId: { toString: () => driverId }, points } as any
|
||||
]);
|
||||
mockRatingRepository.findByDriverAndRace.mockResolvedValue(existingRating);
|
||||
|
||||
// When
|
||||
const result = await useCase.execute({ driverId, raceId });
|
||||
|
||||
// Then
|
||||
expect(mockRatingRepository.save).toHaveBeenCalled();
|
||||
const savedRating = mockRatingRepository.save.mock.calls[0][0] as Rating;
|
||||
|
||||
// Check preserved fields
|
||||
expect(savedRating.rating).toBe(1500);
|
||||
expect(savedRating.components.resultsStrength).toBe(80);
|
||||
|
||||
// Check updated field
|
||||
expect(savedRating.components.teamContribution).toBe(50); // 12.5/25 * 100
|
||||
expect(result.teamContribution).toBe(50);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,105 @@
|
||||
/**
|
||||
* Unit tests for GetRatingLeaderboardUseCase
|
||||
*/
|
||||
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { GetRatingLeaderboardUseCase } from './GetRatingLeaderboardUseCase';
|
||||
import { Rating } from '../../domain/Rating';
|
||||
|
||||
const mockRatingRepository = {
|
||||
findByDriver: vi.fn(),
|
||||
};
|
||||
|
||||
const mockDriverRepository = {
|
||||
findAll: vi.fn(),
|
||||
findById: vi.fn(),
|
||||
};
|
||||
|
||||
describe('GetRatingLeaderboardUseCase', () => {
|
||||
let useCase: GetRatingLeaderboardUseCase;
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
useCase = new GetRatingLeaderboardUseCase({
|
||||
ratingRepository: mockRatingRepository as any,
|
||||
driverRepository: mockDriverRepository as any,
|
||||
});
|
||||
});
|
||||
|
||||
describe('Scenario 10: Pagination + Sorting', () => {
|
||||
it('should return latest rating per driver, sorted desc, sliced by limit/offset', async () => {
|
||||
// Given
|
||||
const drivers = [
|
||||
{ id: 'd1', name: { toString: () => 'Driver 1' } },
|
||||
{ id: 'd2', name: { toString: () => 'Driver 2' } },
|
||||
{ id: 'd3', name: { toString: () => 'Driver 3' } },
|
||||
];
|
||||
|
||||
const ratingsD1 = [
|
||||
Rating.create({
|
||||
driverId: 'd1' as any,
|
||||
raceId: 'r1' as any,
|
||||
rating: 1000,
|
||||
components: {} as any,
|
||||
timestamp: new Date('2023-01-01')
|
||||
}),
|
||||
Rating.create({
|
||||
driverId: 'd1' as any,
|
||||
raceId: 'r2' as any,
|
||||
rating: 1200, // Latest for D1
|
||||
components: {} as any,
|
||||
timestamp: new Date('2023-01-02')
|
||||
})
|
||||
];
|
||||
|
||||
const ratingsD2 = [
|
||||
Rating.create({
|
||||
driverId: 'd2' as any,
|
||||
raceId: 'r1' as any,
|
||||
rating: 1500, // Latest for D2
|
||||
components: {} as any,
|
||||
timestamp: new Date('2023-01-01')
|
||||
})
|
||||
];
|
||||
|
||||
const ratingsD3 = [
|
||||
Rating.create({
|
||||
driverId: 'd3' as any,
|
||||
raceId: 'r1' as any,
|
||||
rating: 800, // Latest for D3
|
||||
components: {} as any,
|
||||
timestamp: new Date('2023-01-01')
|
||||
})
|
||||
];
|
||||
|
||||
mockDriverRepository.findAll.mockResolvedValue(drivers);
|
||||
mockDriverRepository.findById.mockImplementation((id) =>
|
||||
Promise.resolve(drivers.find(d => d.id === id))
|
||||
);
|
||||
mockRatingRepository.findByDriver.mockImplementation((id) => {
|
||||
if (id === 'd1') return Promise.resolve(ratingsD1);
|
||||
if (id === 'd2') return Promise.resolve(ratingsD2);
|
||||
if (id === 'd3') return Promise.resolve(ratingsD3);
|
||||
return Promise.resolve([]);
|
||||
});
|
||||
|
||||
// When: limit 2, offset 0
|
||||
const result = await useCase.execute({ limit: 2, offset: 0 });
|
||||
|
||||
// Then: Sorted D2 (1500), D1 (1200), D3 (800). Slice(0, 2) -> D2, D1
|
||||
expect(result).toHaveLength(2);
|
||||
expect(result[0].driverId).toBe('d2');
|
||||
expect(result[0].rating).toBe(1500);
|
||||
expect(result[1].driverId).toBe('d1');
|
||||
expect(result[1].rating).toBe(1200);
|
||||
|
||||
// When: limit 2, offset 1
|
||||
const resultOffset = await useCase.execute({ limit: 2, offset: 1 });
|
||||
|
||||
// Then: Slice(1, 3) -> D1, D3
|
||||
expect(resultOffset).toHaveLength(2);
|
||||
expect(resultOffset[0].driverId).toBe('d1');
|
||||
expect(resultOffset[1].driverId).toBe('d3');
|
||||
});
|
||||
});
|
||||
});
|
||||
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