Skip to content

Commit 5632ab9

Browse files
committed
Fix tests
1 parent bfaebb8 commit 5632ab9

File tree

2 files changed

+29
-26
lines changed

2 files changed

+29
-26
lines changed

src/@test/create-fake-match.ts

+18-15
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export async function createFakeMatch(
2525
module: TestingModule,
2626
winner: DotaTeam = DotaTeam.RADIANT,
2727
mode: MatchmakingMode = MatchmakingMode.UNRANKED,
28-
duration: number = 100
28+
duration: number = 100,
2929
): Promise<FinishedMatchEntity> {
3030
const matchRep = module.get<Repository<FinishedMatchEntity>>(
3131
getRepositoryToken(FinishedMatchEntity),
@@ -59,38 +59,41 @@ export async function createFakeMatch(
5959
return match;
6060
}
6161

62-
63-
export async function fillMatch(module: TestingModule, fm: FinishedMatchEntity, count: number = 10){
62+
export async function fillMatch(
63+
module: TestingModule,
64+
fm: FinishedMatchEntity,
65+
count: number = 10,
66+
) {
6467
const pRep = module.get<Repository<PlayerInMatchEntity>>(
6568
getRepositoryToken(PlayerInMatchEntity),
6669
);
6770

68-
const randInt = (r: number) => Math.round(Math.random() * r)
71+
const randInt = (r: number) => Math.round(Math.random() * r);
6972

7073
const pims: PlayerInMatchEntity[] = [];
7174
for (let i = 0; i < count; i++) {
7275
const pim = new PlayerInMatchEntity();
7376
pim.match = fm;
74-
pim.playerId = Math.round((Math.random() * 10000 + 1000000)).toString();
77+
pim.playerId = `${fm.id}${randInt(1000000)}${i}`;
7578
pim.abandoned = false;
76-
pim.denies = randInt(50)
77-
pim.last_hits = randInt(250)
79+
pim.denies = randInt(50);
80+
pim.last_hits = randInt(250);
7881
pim.kills = randInt(20);
7982
pim.deaths = randInt(10);
8083
pim.assists = randInt(20);
8184
pim.team = i < count / 2 ? DotaTeam.RADIANT : DotaTeam.DIRE;
8285
pim.level = randInt(25);
8386
pim.gpm = randInt(800);
8487
pim.xpm = randInt(700);
85-
pim.hero = 'npc_dota_hero_riki';
86-
pim.item0 = randInt(100)
87-
pim.item1 = randInt(100)
88-
pim.item2 = randInt(100)
89-
pim.item3 = randInt(100)
90-
pim.item4 = randInt(100)
91-
pim.item5 = randInt(100)
88+
pim.hero = "npc_dota_hero_riki";
89+
pim.item0 = randInt(100);
90+
pim.item1 = randInt(100);
91+
pim.item2 = randInt(100);
92+
pim.item3 = randInt(100);
93+
pim.item4 = randInt(100);
94+
pim.item5 = randInt(100);
9295
await pRep.save(pim);
93-
pims.push(pim)
96+
pims.push(pim);
9497
}
9598

9699
return pims;

src/gameserver/command/ProcessRankedMatch/process-ranked-match-handler.spec.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -180,17 +180,17 @@ describe("MatchController", () => {
180180
const changes = await mmrRepo.find({ where: { matchId: fm.id } });
181181
expect(changes).toHaveLength(10);
182182

183-
expect(changes[0].change).toBeGreaterThan(0);
184-
expect(changes[1].change).toBeGreaterThan(0);
185-
expect(changes[2].change).toBeGreaterThan(0);
186-
expect(changes[3].change).toBeLessThan(0);
187-
expect(changes[4].change).toBeGreaterThan(0);
188-
189-
expect(changes[5].change).toBeLessThan(0);
190-
expect(changes[6].change).toBeLessThan(0);
191-
expect(changes[7].change).toBeLessThan(0);
192-
expect(changes[8].change).toBeLessThan(0);
193-
expect(changes[9].change).toBeLessThan(0);
183+
for (let change of changes) {
184+
const pim = pims.find((pim) => pim.playerId === change.playerId);
185+
// console.log("Amogus!", change, pim)
186+
if (pim?.abandoned) {
187+
expect(change.change).toBeLessThan(0);
188+
} else if (pim.team === DotaTeam.RADIANT) {
189+
expect(change.change).toBeGreaterThan(0);
190+
} else {
191+
expect(change.change).toBeLessThan(0);
192+
}
193+
}
194194
});
195195

196196
it("should not update mmr for already processed match", async () => {

0 commit comments

Comments
 (0)