fix issues
This commit is contained in:
@@ -46,10 +46,21 @@ describe('GetLeagueEligibilityPreviewQuery', () => {
|
||||
const leagueId = 'league-456';
|
||||
const rules = 'platform.driving >= 55';
|
||||
|
||||
const userRating = UserRating.create(userId);
|
||||
// Update driving to 65
|
||||
const updatedRating = userRating.updateDriverRating(65);
|
||||
vi.mocked(mockUserRatingRepo.findByUserId).mockResolvedValue(updatedRating);
|
||||
// Create a rating with driver value of 65 directly
|
||||
const now = new Date();
|
||||
const userRating = UserRating.restore({
|
||||
userId,
|
||||
driver: { value: 65, confidence: 0.5, sampleSize: 10, trend: 'rising', lastUpdated: now },
|
||||
admin: { value: 50, confidence: 0, sampleSize: 0, trend: 'stable', lastUpdated: now },
|
||||
steward: { value: 50, confidence: 0, sampleSize: 0, trend: 'stable', lastUpdated: now },
|
||||
trust: { value: 50, confidence: 0, sampleSize: 0, trend: 'stable', lastUpdated: now },
|
||||
fairness: { value: 50, confidence: 0, sampleSize: 0, trend: 'stable', lastUpdated: now },
|
||||
overallReputation: 50,
|
||||
calculatorVersion: '1.0',
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
});
|
||||
vi.mocked(mockUserRatingRepo.findByUserId).mockResolvedValue(userRating);
|
||||
vi.mocked(mockExternalRatingRepo.findByUserId).mockResolvedValue([]);
|
||||
|
||||
const query: GetLeagueEligibilityPreviewQuery = {
|
||||
@@ -123,9 +134,21 @@ describe('GetLeagueEligibilityPreviewQuery', () => {
|
||||
const leagueId = 'league-456';
|
||||
const rules = 'platform.driving >= 55 AND external.iracing.iRating >= 2000';
|
||||
|
||||
const userRating = UserRating.create(userId);
|
||||
const updatedRating = userRating.updateDriverRating(65);
|
||||
vi.mocked(mockUserRatingRepo.findByUserId).mockResolvedValue(updatedRating);
|
||||
// Create a rating with driver value of 65 directly
|
||||
const now = new Date();
|
||||
const userRating = UserRating.restore({
|
||||
userId,
|
||||
driver: { value: 65, confidence: 0.5, sampleSize: 10, trend: 'rising', lastUpdated: now },
|
||||
admin: { value: 50, confidence: 0, sampleSize: 0, trend: 'stable', lastUpdated: now },
|
||||
steward: { value: 50, confidence: 0, sampleSize: 0, trend: 'stable', lastUpdated: now },
|
||||
trust: { value: 50, confidence: 0, sampleSize: 0, trend: 'stable', lastUpdated: now },
|
||||
fairness: { value: 50, confidence: 0, sampleSize: 0, trend: 'stable', lastUpdated: now },
|
||||
overallReputation: 50,
|
||||
calculatorVersion: '1.0',
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
});
|
||||
vi.mocked(mockUserRatingRepo.findByUserId).mockResolvedValue(userRating);
|
||||
|
||||
const gameKey = GameKey.create('iracing');
|
||||
const profile = ExternalGameRatingProfile.create({
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
* Tests for GetUserRatingsSummaryQuery
|
||||
*/
|
||||
|
||||
import { describe, expect, it, beforeEach, vi } from 'vitest';
|
||||
import { GetUserRatingsSummaryQuery, GetUserRatingsSummaryQueryHandler } from './GetUserRatingsSummaryQuery';
|
||||
import { UserRating } from '../../domain/value-objects/UserRating';
|
||||
import { ExternalGameRatingProfile } from '../../domain/entities/ExternalGameRatingProfile';
|
||||
@@ -21,13 +22,13 @@ describe('GetUserRatingsSummaryQuery', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
mockUserRatingRepo = {
|
||||
findByUserId: jest.fn(),
|
||||
findByUserId: vi.fn(),
|
||||
};
|
||||
mockExternalRatingRepo = {
|
||||
findByUserId: jest.fn(),
|
||||
findByUserId: vi.fn(),
|
||||
};
|
||||
mockRatingEventRepo = {
|
||||
getAllByUserId: jest.fn(),
|
||||
getAllByUserId: vi.fn(),
|
||||
};
|
||||
|
||||
handler = new GetUserRatingsSummaryQueryHandler(
|
||||
@@ -54,15 +55,15 @@ describe('GetUserRatingsSummaryQuery', () => {
|
||||
['iRating', ExternalRating.create(gameKey, 'iRating', 2200)],
|
||||
['safetyRating', ExternalRating.create(gameKey, 'safetyRating', 4.5)],
|
||||
]),
|
||||
provenance: ExternalRatingProvenance.create('iRacing API', new Date()),
|
||||
provenance: ExternalRatingProvenance.create({ source: 'iRacing API', lastSyncedAt: new Date() }),
|
||||
});
|
||||
mockExternalRatingRepo.findByUserId.mockResolvedValue([profile]);
|
||||
|
||||
// Mock rating events
|
||||
const event = RatingEvent.create({
|
||||
id: RatingEventId.create(),
|
||||
id: RatingEventId.generate(),
|
||||
userId,
|
||||
dimension: RatingDimensionKey.create('driver'),
|
||||
dimension: RatingDimensionKey.create('driving'),
|
||||
delta: RatingDelta.create(5),
|
||||
occurredAt: new Date('2024-01-01'),
|
||||
createdAt: new Date('2024-01-01'),
|
||||
@@ -113,7 +114,7 @@ describe('GetUserRatingsSummaryQuery', () => {
|
||||
ratings: new Map([
|
||||
['iRating', ExternalRating.create(GameKey.create('iracing'), 'iRating', 2200)],
|
||||
]),
|
||||
provenance: ExternalRatingProvenance.create('iRacing API', new Date()),
|
||||
provenance: ExternalRatingProvenance.create({ source: 'iRacing API', lastSyncedAt: new Date() }),
|
||||
});
|
||||
|
||||
const assettoProfile = ExternalGameRatingProfile.create({
|
||||
@@ -122,7 +123,7 @@ describe('GetUserRatingsSummaryQuery', () => {
|
||||
ratings: new Map([
|
||||
['rating', ExternalRating.create(GameKey.create('assetto'), 'rating', 85)],
|
||||
]),
|
||||
provenance: ExternalRatingProvenance.create('Assetto API', new Date()),
|
||||
provenance: ExternalRatingProvenance.create({ source: 'Assetto API', lastSyncedAt: new Date() }),
|
||||
});
|
||||
|
||||
mockExternalRatingRepo.findByUserId.mockResolvedValue([iracingProfile, assettoProfile]);
|
||||
|
||||
Reference in New Issue
Block a user