style: format community stats service tests
This commit is contained in:
1 parent
be4de61bb7
commit
3f68997b9a
1 file changed
+49
-12
@@ -825,28 +825,65 @@ describe('CommunityStatsService', () => {
|
|||||||
const matchId = new mongoose.Types.ObjectId();
|
const matchId = new mongoose.Types.ObjectId();
|
||||||
const userId = new mongoose.Types.ObjectId();
|
const userId = new mongoose.Types.ObjectId();
|
||||||
const records = Array.from({ length: 60 }, (_, index) => ({
|
const records = Array.from({ length: 60 }, (_, index) => ({
|
||||||
...record(matchId), userId: userId.toString(), gameNumber: index + 1,
|
...record(matchId),
|
||||||
riotMatchId: `KR_${index}`, gameCreation: index * 1000,
|
userId: userId.toString(),
|
||||||
|
gameNumber: index + 1,
|
||||||
|
riotMatchId: `KR_${index}`,
|
||||||
|
gameCreation: index * 1000,
|
||||||
teamPosition: index < 25 ? 'MIDDLE' : 'TOP',
|
teamPosition: index < 25 ? 'MIDDLE' : 'TOP',
|
||||||
}));
|
}));
|
||||||
const repository = {
|
const repository = {
|
||||||
findUserRecordFragments: jest.fn().mockResolvedValue([{ matchId, builderVersion: MATCH_STATS_BUILDER_VERSION, records }]),
|
findUserRecordFragments: jest
|
||||||
|
.fn()
|
||||||
|
.mockResolvedValue([
|
||||||
|
{ matchId, builderVersion: MATCH_STATS_BUILDER_VERSION, records },
|
||||||
|
]),
|
||||||
findDetailsByMatches: jest.fn().mockResolvedValue([]),
|
findDetailsByMatches: jest.fn().mockResolvedValue([]),
|
||||||
} as unknown as jest.Mocked<MatchStatsRepository>;
|
} as unknown as jest.Mocked<MatchStatsRepository>;
|
||||||
const cache = { get: jest.fn().mockResolvedValue(null), set: jest.fn().mockResolvedValue(undefined) } as unknown as CommunityStatsCacheService;
|
const cache = {
|
||||||
const service = new CommunityStatsService({} as ConnectionService, cache, repository, {} as MatchStatsService);
|
get: jest.fn().mockResolvedValue(null),
|
||||||
(service as unknown as { resolveContext: jest.Mock }).resolveContext = jest.fn().mockResolvedValue({
|
set: jest.fn().mockResolvedValue(undefined),
|
||||||
community: {}, season: { id: 'all', label: '전체', startedAt: null, endedAt: null }, from: null, to: null,
|
} as unknown as CommunityStatsCacheService;
|
||||||
|
const service = new CommunityStatsService(
|
||||||
|
{} as ConnectionService,
|
||||||
|
cache,
|
||||||
|
repository,
|
||||||
|
{} as MatchStatsService,
|
||||||
|
);
|
||||||
|
(service as unknown as { resolveContext: jest.Mock }).resolveContext = jest
|
||||||
|
.fn()
|
||||||
|
.mockResolvedValue({
|
||||||
|
community: {},
|
||||||
|
season: { id: 'all', label: '전체', startedAt: null, endedAt: null },
|
||||||
|
from: null,
|
||||||
|
to: null,
|
||||||
|
});
|
||||||
|
const mid = await service.getUserInternalHistory({
|
||||||
|
communityId,
|
||||||
|
userId,
|
||||||
|
filters: { limit: 20, lane: 'MIDDLE', includePositionCounts: true },
|
||||||
});
|
});
|
||||||
const mid = await service.getUserInternalHistory({ communityId, userId, filters: { limit: 20, lane: 'MIDDLE', includePositionCounts: true } });
|
|
||||||
expect(mid.matches).toHaveLength(20);
|
expect(mid.matches).toHaveLength(20);
|
||||||
expect(mid.matches[0].matchId).toBe('KR_24');
|
expect(mid.matches[0].matchId).toBe('KR_24');
|
||||||
expect(mid.matches[19].matchId).toBe('KR_5');
|
expect(mid.matches[19].matchId).toBe('KR_5');
|
||||||
expect(mid.matches[0].damageShare).toBe(30);
|
expect(mid.matches[0].damageShare).toBe(30);
|
||||||
expect(mid.positionCounts).toEqual({ ALL: 20, TOP: 20, JUNGLE: 0, MIDDLE: 20, BOTTOM: 0, UTILITY: 0 });
|
expect(mid.positionCounts).toEqual({
|
||||||
expect(repository.findUserRecordFragments).toHaveBeenCalledWith(expect.objectContaining({ limit: 0 }));
|
ALL: 20,
|
||||||
const all = await service.getUserInternalHistory({ communityId, userId, filters: { limit: 20, includePositionCounts: true } });
|
TOP: 20,
|
||||||
expect(all.matches.every(game => game.teamPosition === 'TOP')).toBe(true);
|
JUNGLE: 0,
|
||||||
|
MIDDLE: 20,
|
||||||
|
BOTTOM: 0,
|
||||||
|
UTILITY: 0,
|
||||||
|
});
|
||||||
|
expect(repository.findUserRecordFragments).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({ limit: 0 }),
|
||||||
|
);
|
||||||
|
const all = await service.getUserInternalHistory({
|
||||||
|
communityId,
|
||||||
|
userId,
|
||||||
|
filters: { limit: 20, includePositionCounts: true },
|
||||||
|
});
|
||||||
|
expect(all.matches.every((game) => game.teamPosition === 'TOP')).toBe(true);
|
||||||
expect(all.positionCounts).toEqual(mid.positionCounts);
|
expect(all.positionCounts).toEqual(mid.positionCounts);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user