admin area
This commit is contained in:
@@ -2,25 +2,37 @@
|
||||
* Tests for GetLeagueEligibilityPreviewQuery
|
||||
*/
|
||||
|
||||
import { GetLeagueEligibilityPreviewQuery, GetLeagueEligibilityPreviewQueryHandler } from './GetLeagueEligibilityPreviewQuery';
|
||||
import { UserRating } from '../../domain/value-objects/UserRating';
|
||||
import { ExternalGameRatingProfile } from '../../domain/entities/ExternalGameRatingProfile';
|
||||
import { GameKey } from '../../domain/value-objects/GameKey';
|
||||
import { ExternalRating } from '../../domain/value-objects/ExternalRating';
|
||||
import { ExternalRatingProvenance } from '../../domain/value-objects/ExternalRatingProvenance';
|
||||
import { GameKey } from '../../domain/value-objects/GameKey';
|
||||
import { UserRating } from '../../domain/value-objects/UserRating';
|
||||
import { UserId } from '../../domain/value-objects/UserId';
|
||||
import { GetLeagueEligibilityPreviewQuery, GetLeagueEligibilityPreviewQueryHandler } from './GetLeagueEligibilityPreviewQuery';
|
||||
import { IUserRatingRepository } from '../../domain/repositories/IUserRatingRepository';
|
||||
import { IExternalGameRatingRepository } from '../../domain/repositories/IExternalGameRatingRepository';
|
||||
|
||||
describe('GetLeagueEligibilityPreviewQuery', () => {
|
||||
let mockUserRatingRepo: any;
|
||||
let mockExternalRatingRepo: any;
|
||||
let mockUserRatingRepo: IUserRatingRepository;
|
||||
let mockExternalRatingRepo: IExternalGameRatingRepository;
|
||||
let handler: GetLeagueEligibilityPreviewQueryHandler;
|
||||
|
||||
beforeEach(() => {
|
||||
mockUserRatingRepo = {
|
||||
findByUserId: jest.fn(),
|
||||
};
|
||||
findByUserId: vi.fn(),
|
||||
save: vi.fn(),
|
||||
} as unknown as IUserRatingRepository;
|
||||
|
||||
mockExternalRatingRepo = {
|
||||
findByUserId: jest.fn(),
|
||||
};
|
||||
findByUserId: vi.fn(),
|
||||
findByUserIdAndGameKey: vi.fn(),
|
||||
findByGameKey: vi.fn(),
|
||||
save: vi.fn(),
|
||||
saveMany: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
exists: vi.fn(),
|
||||
findProfilesPaginated: vi.fn(),
|
||||
} as unknown as IExternalGameRatingRepository;
|
||||
|
||||
handler = new GetLeagueEligibilityPreviewQueryHandler(
|
||||
mockUserRatingRepo,
|
||||
@@ -37,8 +49,8 @@ describe('GetLeagueEligibilityPreviewQuery', () => {
|
||||
const userRating = UserRating.create(userId);
|
||||
// Update driving to 65
|
||||
const updatedRating = userRating.updateDriverRating(65);
|
||||
mockUserRatingRepo.findByUserId.mockResolvedValue(updatedRating);
|
||||
mockExternalRatingRepo.findByUserId.mockResolvedValue([]);
|
||||
vi.mocked(mockUserRatingRepo.findByUserId).mockResolvedValue(updatedRating);
|
||||
vi.mocked(mockExternalRatingRepo.findByUserId).mockResolvedValue([]);
|
||||
|
||||
const query: GetLeagueEligibilityPreviewQuery = {
|
||||
userId,
|
||||
@@ -50,8 +62,8 @@ describe('GetLeagueEligibilityPreviewQuery', () => {
|
||||
|
||||
expect(result.eligible).toBe(true);
|
||||
expect(result.reasons).toHaveLength(1);
|
||||
expect(result.reasons[0].target).toBe('platform.driving');
|
||||
expect(result.reasons[0].failed).toBe(false);
|
||||
expect(result.reasons[0]!.target).toBe('platform.driving');
|
||||
expect(result.reasons[0]!.failed).toBe(false);
|
||||
});
|
||||
|
||||
it('should evaluate simple platform eligibility - not eligible', async () => {
|
||||
@@ -61,8 +73,8 @@ describe('GetLeagueEligibilityPreviewQuery', () => {
|
||||
|
||||
const userRating = UserRating.create(userId);
|
||||
// Driving is 50 by default
|
||||
mockUserRatingRepo.findByUserId.mockResolvedValue(userRating);
|
||||
mockExternalRatingRepo.findByUserId.mockResolvedValue([]);
|
||||
vi.mocked(mockUserRatingRepo.findByUserId).mockResolvedValue(userRating);
|
||||
vi.mocked(mockExternalRatingRepo.findByUserId).mockResolvedValue([]);
|
||||
|
||||
const query: GetLeagueEligibilityPreviewQuery = {
|
||||
userId,
|
||||
@@ -73,7 +85,7 @@ describe('GetLeagueEligibilityPreviewQuery', () => {
|
||||
const result = await handler.execute(query);
|
||||
|
||||
expect(result.eligible).toBe(false);
|
||||
expect(result.reasons[0].failed).toBe(true);
|
||||
expect(result.reasons[0]!.failed).toBe(true);
|
||||
});
|
||||
|
||||
it('should evaluate external rating eligibility', async () => {
|
||||
@@ -81,18 +93,18 @@ describe('GetLeagueEligibilityPreviewQuery', () => {
|
||||
const leagueId = 'league-456';
|
||||
const rules = 'external.iracing.iRating between 2000 2500';
|
||||
|
||||
mockUserRatingRepo.findByUserId.mockResolvedValue(null);
|
||||
vi.mocked(mockUserRatingRepo.findByUserId).mockResolvedValue(null);
|
||||
|
||||
const gameKey = GameKey.create('iracing');
|
||||
const profile = ExternalGameRatingProfile.create({
|
||||
userId: { toString: () => userId } as any,
|
||||
userId: UserId.fromString(userId),
|
||||
gameKey,
|
||||
ratings: new Map([
|
||||
['iRating', ExternalRating.create(gameKey, 'iRating', 2200)],
|
||||
]),
|
||||
provenance: ExternalRatingProvenance.create({ source: 'iRacing API', lastSyncedAt: new Date() }),
|
||||
});
|
||||
mockExternalRatingRepo.findByUserId.mockResolvedValue([profile]);
|
||||
vi.mocked(mockExternalRatingRepo.findByUserId).mockResolvedValue([profile]);
|
||||
|
||||
const query: GetLeagueEligibilityPreviewQuery = {
|
||||
userId,
|
||||
@@ -103,7 +115,7 @@ describe('GetLeagueEligibilityPreviewQuery', () => {
|
||||
const result = await handler.execute(query);
|
||||
|
||||
expect(result.eligible).toBe(true);
|
||||
expect(result.reasons[0].target).toBe('external.iracing.iRating');
|
||||
expect(result.reasons[0]!.target).toBe('external.iracing.iRating');
|
||||
});
|
||||
|
||||
it('should evaluate complex AND conditions', async () => {
|
||||
@@ -113,18 +125,18 @@ describe('GetLeagueEligibilityPreviewQuery', () => {
|
||||
|
||||
const userRating = UserRating.create(userId);
|
||||
const updatedRating = userRating.updateDriverRating(65);
|
||||
mockUserRatingRepo.findByUserId.mockResolvedValue(updatedRating);
|
||||
vi.mocked(mockUserRatingRepo.findByUserId).mockResolvedValue(updatedRating);
|
||||
|
||||
const gameKey = GameKey.create('iracing');
|
||||
const profile = ExternalGameRatingProfile.create({
|
||||
userId: { toString: () => userId } as any,
|
||||
userId: UserId.fromString(userId),
|
||||
gameKey,
|
||||
ratings: new Map([
|
||||
['iRating', ExternalRating.create(gameKey, 'iRating', 2200)],
|
||||
]),
|
||||
provenance: ExternalRatingProvenance.create({ source: 'iRacing API', lastSyncedAt: new Date() }),
|
||||
});
|
||||
mockExternalRatingRepo.findByUserId.mockResolvedValue([profile]);
|
||||
vi.mocked(mockExternalRatingRepo.findByUserId).mockResolvedValue([profile]);
|
||||
|
||||
const query: GetLeagueEligibilityPreviewQuery = {
|
||||
userId,
|
||||
@@ -145,18 +157,18 @@ describe('GetLeagueEligibilityPreviewQuery', () => {
|
||||
const rules = 'platform.driving >= 75 OR external.iracing.iRating >= 2000';
|
||||
|
||||
const userRating = UserRating.create(userId);
|
||||
mockUserRatingRepo.findByUserId.mockResolvedValue(userRating);
|
||||
vi.mocked(mockUserRatingRepo.findByUserId).mockResolvedValue(userRating);
|
||||
|
||||
const gameKey = GameKey.create('iracing');
|
||||
const profile = ExternalGameRatingProfile.create({
|
||||
userId: { toString: () => userId } as any,
|
||||
userId: UserId.fromString(userId),
|
||||
gameKey,
|
||||
ratings: new Map([
|
||||
['iRating', ExternalRating.create(gameKey, 'iRating', 2200)],
|
||||
]),
|
||||
provenance: ExternalRatingProvenance.create({ source: 'iRacing API', lastSyncedAt: new Date() }),
|
||||
});
|
||||
mockExternalRatingRepo.findByUserId.mockResolvedValue([profile]);
|
||||
vi.mocked(mockExternalRatingRepo.findByUserId).mockResolvedValue([profile]);
|
||||
|
||||
const query: GetLeagueEligibilityPreviewQuery = {
|
||||
userId,
|
||||
@@ -175,8 +187,8 @@ describe('GetLeagueEligibilityPreviewQuery', () => {
|
||||
const leagueId = 'league-456';
|
||||
const rules = 'platform.driving >= 55';
|
||||
|
||||
mockUserRatingRepo.findByUserId.mockResolvedValue(null);
|
||||
mockExternalRatingRepo.findByUserId.mockResolvedValue([]);
|
||||
vi.mocked(mockUserRatingRepo.findByUserId).mockResolvedValue(null);
|
||||
vi.mocked(mockExternalRatingRepo.findByUserId).mockResolvedValue([]);
|
||||
|
||||
const query: GetLeagueEligibilityPreviewQuery = {
|
||||
userId,
|
||||
|
||||
Reference in New Issue
Block a user