Some checks failed
CI / lint-typecheck (pull_request) Failing after 4m51s
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
55 lines
1.9 KiB
TypeScript
55 lines
1.9 KiB
TypeScript
import { describe, it, expect, beforeAll, beforeEach } from 'vitest';
|
|
import { RatingTestContext } from './RatingTestContext';
|
|
import { SaveRatingUseCase } from '../../../../core/rating/application/use-cases/SaveRatingUseCase';
|
|
import { Driver } from '../../../../core/racing/domain/entities/Driver';
|
|
import { Rating } from '../../../../core/rating/domain/entities/Rating';
|
|
import { DriverId } from '../../../../core/racing/domain/entities/DriverId';
|
|
import { RaceId } from '../../../../core/racing/domain/entities/RaceId';
|
|
|
|
describe('Rating Persistence Use Cases', () => {
|
|
let context: RatingTestContext;
|
|
let saveRatingUseCase: SaveRatingUseCase;
|
|
|
|
beforeAll(() => {
|
|
context = RatingTestContext.create();
|
|
saveRatingUseCase = new SaveRatingUseCase({
|
|
ratingRepository: context.ratingRepository
|
|
});
|
|
});
|
|
|
|
beforeEach(async () => {
|
|
await context.clear();
|
|
});
|
|
|
|
describe('SaveRatingUseCase', () => {
|
|
describe('UseCase - Success Path', () => {
|
|
it('should save rating successfully', async () => {
|
|
// Given: A driver
|
|
const driverId = 'd1';
|
|
const driver = Driver.create({ id: driverId, iracingId: '100', name: 'John Doe', country: 'US' });
|
|
await context.driverRepository.create(driver);
|
|
|
|
// When: SaveRatingUseCase.execute() is called
|
|
await saveRatingUseCase.execute({
|
|
driverId,
|
|
raceId: 'r1',
|
|
rating: 1500,
|
|
components: {
|
|
resultsStrength: 80,
|
|
consistency: 75,
|
|
cleanDriving: 90,
|
|
racecraft: 85,
|
|
reliability: 95,
|
|
teamContribution: 70
|
|
}
|
|
});
|
|
|
|
// Then: The rating should be saved
|
|
const savedRatings = await context.ratingRepository.findByDriver(driverId);
|
|
expect(savedRatings).toHaveLength(1);
|
|
expect(savedRatings[0].rating).toBe(1500);
|
|
});
|
|
});
|
|
});
|
|
});
|