diff --git a/src/base/updater.ts b/src/base/updater.ts index 090de36..28d8e8e 100644 --- a/src/base/updater.ts +++ b/src/base/updater.ts @@ -106,13 +106,16 @@ export class BaseUpdater extends BaseGetter { let index = 0; for (const match of matches) { + // Changing the seeding would reset the matches of round >= 2, leaving the scores behind, with no participants. + if (match.status === Status.Archived) + throw Error('A match of round 1 is archived, which means round 2 was started.'); + const opponent1 = slots[index++]; const opponent2 = slots[index++]; + const isParticipantLocked = helpers.isMatchParticipantLocked(match); - const locked = helpers.isMatchParticipantLocked(match); - if (!locked) continue; - - if (match.opponent1?.id !== opponent1?.id || match.opponent2?.id !== opponent2?.id) + // The match is participant locked, and the participants would have to change. + if (isParticipantLocked && (match.opponent1?.id !== opponent1?.id || match.opponent2?.id !== opponent2?.id)) throw Error('A match is locked.'); } } diff --git a/test/update.spec.js b/test/update.spec.js index c131681..eba63d4 100644 --- a/test/update.spec.js +++ b/test/update.spec.js @@ -897,6 +897,41 @@ describe('Seeding', () => { ]), 'A match is locked.'); }); + it('should throw if a match is archived and would have to be changed', async () => { + await manager.update.seeding(0, [ + 'Team 1', 'Team 2', + 'Team 3', 'Team 4', + 'Team 5', 'Team 6', + 'Team 7', 'Team 8', + ]); + + await manager.update.match({ + id: 0, // WB 1.1 + opponent1: { score: 1, result: 'win' }, + opponent2: { score: 0 }, + }); + + await manager.update.match({ + id: 1, // WB 1.2 + opponent1: { score: 1, result: 'win' }, + opponent2: { score: 0 }, + }); + + // This will archive matches 0 and 1. + await manager.update.match({ + id: 4, // WB Semi 1 + opponent1: { score: 1 }, + opponent2: { score: 0 }, + }); + + await assert.isRejected(manager.update.seeding(0, [ + 'Team 1', 'Team 2', // Do not even need to change this pair. + 'Team 3', 'Team 4', + 'Team 5', 'Team 6', + 'Team 7', 'Team 8', + ]), 'A match of round 1 is archived, which means round 2 was started.'); + }); + it('should throw if a match is locked and would have to be changed', async () => { await manager.update.seeding(0, [ 'Team 1', 'Team 2',