Skip to content

Commit

Permalink
Handle incomplete seeding in update.seeding()
Browse files Browse the repository at this point in the history
Closes #121
  • Loading branch information
Drarig29 committed Mar 16, 2022
1 parent 6319cb4 commit b84e02b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 20 deletions.
3 changes: 0 additions & 3 deletions src/base/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ export class BaseUpdater extends BaseGetter {
const stage = await this.storage.select('stage', stageId);
if (!stage) throw Error('Stage not found.');

if (seeding && seeding.length !== stage.settings.size)
throw Error('The size of the seeding is incorrect.');

const create = new Create(this.storage, {
name: stage.name,
tournamentId: stage.tournament_id,
Expand Down
22 changes: 22 additions & 0 deletions test/general.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,28 @@ describe('BYE handling', () => {
assert.strictEqual((await storage.select('match', 5)).opponent2, null);
});

it('should handle incomplete seeding during creation', async () => {
await manager.create({
name: 'Example with BYEs',
tournamentId: 0,
type: 'double_elimination',
seeding: [
'Team 1', 'Team 2',
],
settings: {
seedOrdering: ['natural'],
balanceByes: false, // Default value.
size: 4,
},
});

assert.strictEqual((await storage.select('match', 0)).opponent1.id, 0);
assert.strictEqual((await storage.select('match', 0)).opponent2.id, 1);

assert.strictEqual((await storage.select('match', 1)).opponent1, null);
assert.strictEqual((await storage.select('match', 1)).opponent2, null);
});

it('should balance BYEs in the seeding', async () => {
await manager.create({
name: 'Example with BYEs',
Expand Down
29 changes: 12 additions & 17 deletions test/update.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ describe('Update matches', () => {
}), 'There are two losers.');
});

it('should throw if two forfeits', async() => {
it('should throw if two forfeits', async () => {
await assert.isRejected(manager.update.match({
id: 3,
opponent1: { forfeit: true },
Expand Down Expand Up @@ -612,6 +612,17 @@ describe('Seeding', () => {
assert.strictEqual((await storage.select('match', 3)).opponent2.id, null);
});

it('should handle incomplete seeding during seeding update', async () => {
await manager.update.seeding(0, ['Team 1', 'Team 2']);

assert.strictEqual((await storage.select('match', 0)).opponent1.id, 0);
assert.strictEqual((await storage.select('match', 0)).opponent2.id, 1);

// Same here, see comments above.
assert.strictEqual((await storage.select('match', 1)).opponent1.id, null);
assert.strictEqual((await storage.select('match', 1)).opponent2.id, null);
});

it('should reset the seeding of a stage', async () => {
await manager.update.seeding(0, [
'Team 1', 'Team 2',
Expand Down Expand Up @@ -761,22 +772,6 @@ describe('Seeding', () => {
]), 'A match is locked.');
});

it('should throw if the new seeding doesn\'t have the correct size', async () => {
await manager.update.seeding(0, [
'Team 1', 'Team 2',
'Team 3', 'Team 4',
'Team 5', 'Team 6',
'Team 7', 'Team 8',
]);

await assert.isRejected(manager.update.seeding(0, [
'Team A', 'Team B',
'Team C', 'Team D',
'Team E', 'Team F',
'Team G', // Missing value.
]), 'The size of the seeding is incorrect.');
});

it('should throw if the seeding has duplicate participants', async () => {
await assert.isRejected(manager.update.seeding(0, [
'Team 1', 'Team 1', // Duplicate
Expand Down

0 comments on commit b84e02b

Please sign in to comment.