77 lines
2.8 KiB
TypeScript
77 lines
2.8 KiB
TypeScript
import { RatingEvent } from '../entities/RatingEvent';
|
|
import { RatingDelta } from '../value-objects/RatingDelta';
|
|
import { RatingDimensionKey } from '../value-objects/RatingDimensionKey';
|
|
import { RatingEventId } from '../value-objects/RatingEventId';
|
|
import { RatingSnapshotCalculator } from './RatingSnapshotCalculator';
|
|
|
|
describe('RatingSnapshotCalculator', () => {
|
|
describe('calculate', () => {
|
|
it('should return stub implementation with basic snapshot', () => {
|
|
const userId = 'user-123';
|
|
const events: RatingEvent[] = [
|
|
RatingEvent.create({
|
|
id: RatingEventId.generate(),
|
|
userId: userId,
|
|
dimension: RatingDimensionKey.create('driving'),
|
|
delta: RatingDelta.create(10),
|
|
occurredAt: new Date(),
|
|
createdAt: new Date(),
|
|
source: { type: 'race', id: 'race-123' },
|
|
reason: { code: 'TEST', summary: 'Test', details: {} },
|
|
visibility: { public: true, redactedFields: [] },
|
|
version: 1,
|
|
}),
|
|
];
|
|
|
|
const result = RatingSnapshotCalculator.calculate(userId, events);
|
|
|
|
// Stub returns a UserRating with updated driver dimension
|
|
expect(result.userId).toBe(userId);
|
|
expect(result.driver.value).toBeGreaterThan(50); // Should have increased
|
|
expect(result.driver.sampleSize).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('should handle empty events array', () => {
|
|
const userId = 'user-123';
|
|
const result = RatingSnapshotCalculator.calculate(userId, []);
|
|
|
|
expect(result.userId).toBe(userId);
|
|
expect(result.driver.sampleSize).toBe(0);
|
|
});
|
|
|
|
it('should handle multiple dimensions', () => {
|
|
const userId = 'user-123';
|
|
const events: RatingEvent[] = [
|
|
RatingEvent.create({
|
|
id: RatingEventId.generate(),
|
|
userId: userId,
|
|
dimension: RatingDimensionKey.create('driving'),
|
|
delta: RatingDelta.create(10),
|
|
occurredAt: new Date(),
|
|
createdAt: new Date(),
|
|
source: { type: 'race', id: 'race-123' },
|
|
reason: { code: 'TEST', summary: 'Test', details: {} },
|
|
visibility: { public: true, redactedFields: [] },
|
|
version: 1,
|
|
}),
|
|
RatingEvent.create({
|
|
id: RatingEventId.generate(),
|
|
userId: userId,
|
|
dimension: RatingDimensionKey.create('adminTrust'),
|
|
delta: RatingDelta.create(5),
|
|
occurredAt: new Date(),
|
|
createdAt: new Date(),
|
|
source: { type: 'vote', id: 'vote-123' },
|
|
reason: { code: 'TEST', summary: 'Test', details: {} },
|
|
visibility: { public: true, redactedFields: [] },
|
|
version: 1,
|
|
}),
|
|
];
|
|
|
|
const result = RatingSnapshotCalculator.calculate(userId, events);
|
|
|
|
expect(result.driver.value).toBeGreaterThan(50);
|
|
expect(result.admin.value).toBeGreaterThan(50);
|
|
});
|
|
});
|
|
}); |