Skip to content

Commit 9d1af70

Browse files
committed
fix(jsbattle-server): fix winner selection
1 parent 2cd7c4e commit 9d1af70

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

packages/jsbattle-server/app/services/LeagueScheduler.service.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,13 @@ class LeagueScheduler extends Service {
7070
}
7171
});
7272

73-
let winner = teamList.reduce((winner, current) => {
74-
if(current.score > winner.score) {
73+
this.logger.info('Battle result: ' + teamList.map((t) => `${t.name} (${t.battleScore})`).join(' vs '))
74+
75+
let winner = teamList.reduce((best, current) => {
76+
if(current.battleScore > best.battleScore) {
7577
return current;
7678
} else {
77-
return winner;
79+
return best;
7880
}
7981
}, teamList[0]);
8082

packages/jsbattle-server/test/unit/services/LeagueScheduler.spec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,10 @@ describe("Test 'League' service", () => {
188188

189189
expect(entityId1).toBe('987243');
190190
expect(entityId2).toBe('50872');
191-
expect(entityWon1).toBe(true);
192-
expect(entityWon2).toBe(false);
193-
});
191+
expect(entityWon1).toBe(false);
192+
expect(entityWon2).toBe(true);
194193

194+
});
195195

196196
it('should not process battle errors', async () => {
197197
leagueUpdate.mockReset();

0 commit comments

Comments
 (0)