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 userId = new mongoose.Types.ObjectId();
|
||||
const records = Array.from({ length: 60 }, (_, index) => ({
|
||||
...record(matchId), userId: userId.toString(), gameNumber: index + 1,
|
||||
riotMatchId: `KR_${index}`, gameCreation: index * 1000,
|
||||
...record(matchId),
|
||||
userId: userId.toString(),
|
||||
gameNumber: index + 1,
|
||||
riotMatchId: `KR_${index}`,
|
||||
gameCreation: index * 1000,
|
||||
teamPosition: index < 25 ? 'MIDDLE' : 'TOP',
|
||||
}));
|
||||
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([]),
|
||||
} as unknown as jest.Mocked<MatchStatsRepository>;
|
||||
const cache = { get: jest.fn().mockResolvedValue(null), set: jest.fn().mockResolvedValue(undefined) } 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 cache = {
|
||||
get: jest.fn().mockResolvedValue(null),
|
||||
set: jest.fn().mockResolvedValue(undefined),
|
||||
} 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[0].matchId).toBe('KR_24');
|
||||
expect(mid.matches[19].matchId).toBe('KR_5');
|
||||
expect(mid.matches[0].damageShare).toBe(30);
|
||||
expect(mid.positionCounts).toEqual({ ALL: 20, TOP: 20, 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(mid.positionCounts).toEqual({
|
||||
ALL: 20,
|
||||
TOP: 20,
|
||||
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);
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user