adapter tests
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
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
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
import { InMemoryRatingRepository } from './InMemoryRatingRepository';
|
||||
import { Rating } from '../../../../core/rating/domain/Rating';
|
||||
import { DriverId } from '../../../../core/racing/domain/entities/DriverId';
|
||||
import { RaceId } from '../../../../core/racing/domain/entities/RaceId';
|
||||
|
||||
describe('InMemoryRatingRepository', () => {
|
||||
let repository: InMemoryRatingRepository;
|
||||
|
||||
beforeEach(() => {
|
||||
repository = new InMemoryRatingRepository();
|
||||
});
|
||||
|
||||
const createRating = (driverId: string, raceId: string, ratingValue: number) => {
|
||||
return Rating.create({
|
||||
driverId: DriverId.create(driverId),
|
||||
raceId: RaceId.create(raceId),
|
||||
rating: ratingValue,
|
||||
components: {
|
||||
resultsStrength: ratingValue,
|
||||
consistency: 0,
|
||||
cleanDriving: 0,
|
||||
racecraft: 0,
|
||||
reliability: 0,
|
||||
teamContribution: 0,
|
||||
},
|
||||
timestamp: new Date(),
|
||||
});
|
||||
};
|
||||
|
||||
describe('save and findByDriverAndRace', () => {
|
||||
it('should return null when rating does not exist', async () => {
|
||||
// When
|
||||
const result = await repository.findByDriverAndRace('d1', 'r1');
|
||||
|
||||
// Then
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
it('should save and retrieve a rating', async () => {
|
||||
// Given
|
||||
const rating = createRating('d1', 'r1', 1500);
|
||||
|
||||
// When
|
||||
await repository.save(rating);
|
||||
const result = await repository.findByDriverAndRace('d1', 'r1');
|
||||
|
||||
// Then
|
||||
expect(result).toEqual(rating);
|
||||
});
|
||||
|
||||
it('should overwrite rating for same driver and race (idempotency)', async () => {
|
||||
// Given
|
||||
const r1 = createRating('d1', 'r1', 1500);
|
||||
const r2 = createRating('d1', 'r1', 1600);
|
||||
|
||||
// When
|
||||
await repository.save(r1);
|
||||
await repository.save(r2);
|
||||
const result = await repository.findByDriverAndRace('d1', 'r1');
|
||||
|
||||
// Then
|
||||
expect(result?.rating).toBe(1600);
|
||||
});
|
||||
});
|
||||
|
||||
describe('findByDriver', () => {
|
||||
it('should return all ratings for a driver', async () => {
|
||||
// Given
|
||||
const r1 = createRating('d1', 'r1', 1500);
|
||||
const r2 = createRating('d1', 'r2', 1600);
|
||||
const r3 = createRating('d2', 'r1', 1400);
|
||||
|
||||
await repository.save(r1);
|
||||
await repository.save(r2);
|
||||
await repository.save(r3);
|
||||
|
||||
// When
|
||||
const result = await repository.findByDriver('d1');
|
||||
|
||||
// Then
|
||||
expect(result).toHaveLength(2);
|
||||
expect(result).toContainEqual(r1);
|
||||
expect(result).toContainEqual(r2);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user