website refactor
This commit is contained in:
@@ -3,7 +3,6 @@ import { RatingEvent } from '../entities/RatingEvent';
|
||||
import { RatingEventId } from '../value-objects/RatingEventId';
|
||||
import { RatingDimensionKey } from '../value-objects/RatingDimensionKey';
|
||||
import { RatingDelta } from '../value-objects/RatingDelta';
|
||||
import { AdminVoteOutcome } from '../entities/AdminVoteSession';
|
||||
|
||||
describe('AdminTrustRatingCalculator', () => {
|
||||
describe('calculate', () => {
|
||||
@@ -316,13 +315,12 @@ describe('AdminTrustRatingCalculator', () => {
|
||||
|
||||
it('should default to zero for unknown action type', () => {
|
||||
const input: SystemSignalInput = {
|
||||
actionType: 'sla_response' as any,
|
||||
actionType: 'unknown_type' as unknown as SystemSignalInput['actionType'],
|
||||
details: {},
|
||||
};
|
||||
|
||||
// Override for test
|
||||
const delta = AdminTrustRatingCalculator.calculateFromSystemSignal(input);
|
||||
expect(delta.value).toBe(5); // Known type
|
||||
expect(delta.value).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import { RatingEvent } from '../entities/RatingEvent';
|
||||
import { DrivingReasonCode } from '../value-objects/DrivingReasonCode';
|
||||
import { RatingDelta } from '../value-objects/RatingDelta';
|
||||
|
||||
/**
|
||||
* Input DTO for driving rating calculation from race facts
|
||||
@@ -71,7 +69,7 @@ export class DrivingRatingCalculator {
|
||||
const fieldStrength = facts.results.length > 0
|
||||
? (facts.results
|
||||
.filter(r => r.status === 'finished')
|
||||
.reduce((sum, r) => sum + (r.sof || this.estimateDriverRating(r.userId)), 0) /
|
||||
.reduce((sum, r) => sum + (r.sof || this.estimateDriverRating()), 0) /
|
||||
Math.max(1, facts.results.filter(r => r.status === 'finished').length))
|
||||
: 0;
|
||||
|
||||
@@ -297,7 +295,7 @@ export class DrivingRatingCalculator {
|
||||
* Estimate driver rating for SoF calculation
|
||||
* This is a placeholder - in real implementation, would query user rating snapshot
|
||||
*/
|
||||
private static estimateDriverRating(userId: string): number {
|
||||
private static estimateDriverRating(): number {
|
||||
// Default rating for new drivers
|
||||
return 50;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
*/
|
||||
|
||||
import { EligibilityEvaluator, RatingData } from './EligibilityEvaluator';
|
||||
import { EligibilityFilterDto } from '../../application/dtos/EligibilityFilterDto';
|
||||
import { EligibilityFilterDto } from '../types/Eligibility';
|
||||
|
||||
describe('EligibilityEvaluator', () => {
|
||||
let evaluator: EligibilityEvaluator;
|
||||
|
||||
@@ -6,8 +6,13 @@
|
||||
* Provides explainable results with detailed reasons.
|
||||
*/
|
||||
|
||||
import { EvaluationResultDto, EvaluationReason } from '../../application/dtos/EvaluationResultDto';
|
||||
import { EligibilityFilterDto, ParsedEligibilityFilter, EligibilityCondition } from '../../application/dtos/EligibilityFilterDto';
|
||||
import {
|
||||
EvaluationResultDto,
|
||||
EvaluationReason,
|
||||
EligibilityFilterDto,
|
||||
ParsedEligibilityFilter,
|
||||
EligibilityCondition
|
||||
} from '../types/Eligibility';
|
||||
|
||||
export interface RatingData {
|
||||
platform: {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
||||
import { describe, it, expect, beforeEach, vi, type Mock } from 'vitest';
|
||||
import { RatingUpdateService } from './RatingUpdateService';
|
||||
import type { UserRatingRepository } from '../repositories/UserRatingRepository';
|
||||
import type { RatingEventRepository } from '../repositories/RatingEventRepository';
|
||||
@@ -10,8 +10,8 @@ import { RatingDelta } from '../value-objects/RatingDelta';
|
||||
|
||||
describe('RatingUpdateService - Slice 7 Evolution', () => {
|
||||
let service: RatingUpdateService;
|
||||
let userRatingRepository: any;
|
||||
let ratingEventRepository: any;
|
||||
let userRatingRepository: { findByUserId: Mock; save: Mock };
|
||||
let ratingEventRepository: { save: Mock; getAllByUserId: Mock };
|
||||
|
||||
beforeEach(() => {
|
||||
userRatingRepository = {
|
||||
@@ -24,7 +24,10 @@ describe('RatingUpdateService - Slice 7 Evolution', () => {
|
||||
getAllByUserId: vi.fn(),
|
||||
};
|
||||
|
||||
service = new RatingUpdateService(userRatingRepository, ratingEventRepository);
|
||||
service = new RatingUpdateService(
|
||||
userRatingRepository as unknown as UserRatingRepository,
|
||||
ratingEventRepository as unknown as RatingEventRepository
|
||||
);
|
||||
});
|
||||
|
||||
describe('recordRaceRatingEvents - Ledger-based approach', () => {
|
||||
@@ -150,7 +153,7 @@ describe('RatingUpdateService - Slice 7 Evolution', () => {
|
||||
|
||||
// Verify DNF penalty event was created
|
||||
const savedEvents = ratingEventRepository.save.mock.calls.map(call => call[0]);
|
||||
const hasDnfPenalty = savedEvents.some((event: any) =>
|
||||
const hasDnfPenalty = savedEvents.some((event: RatingEvent) =>
|
||||
event.reason.code === 'DRIVING_DNF_PENALTY'
|
||||
);
|
||||
expect(hasDnfPenalty).toBe(true);
|
||||
|
||||
Reference in New Issue
Block a user