rating
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
import { RatingSnapshotCalculator } from './RatingSnapshotCalculator';
|
||||
import { RatingEvent } from '../entities/RatingEvent';
|
||||
import { RatingEventId } from '../value-objects/RatingEventId';
|
||||
import { RatingDimensionKey } from '../value-objects/RatingDimensionKey';
|
||||
import { RatingDelta } from '../value-objects/RatingDelta';
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user