sendou.ink/app/modules/brackets-manager/test/delete.test.ts
Kalle fd48bced91
Migrate Prettier/Eslint/Stylelint setup to Biome (#1772)
* Initial

* CSS lint

* Test CI

* Add 1v1, 2v2, and 3v3 Tags (#1771)

* Initial

* CSS lint

* Test CI

* Rename step

---------

Co-authored-by: xi <104683822+ximk@users.noreply.github.com>
2024-06-24 13:07:17 +03:00

99 lines
2.3 KiB
TypeScript

import { suite } from "uvu";
import * as assert from "uvu/assert";
import { InMemoryDatabase } from "~/modules/brackets-memory-db";
import { BracketsManager } from "../manager";
const storage = new InMemoryDatabase();
const manager = new BracketsManager(storage);
const DeleteStage = suite("Delete stage");
DeleteStage.before.each(() => {
storage.reset();
});
DeleteStage("should delete a stage and all its linked data", () => {
manager.create({
name: "Example",
tournamentId: 0,
type: "single_elimination",
seeding: [1, 2, 3, 4],
});
manager.delete.stage(0);
const stages = storage.select("stage")!;
const groups = storage.select("group")!;
const rounds = storage.select("round")!;
const matches = storage.select<any>("match")!;
assert.equal(stages.length, 0);
assert.equal(groups.length, 0);
assert.equal(rounds.length, 0);
assert.equal(matches.length, 0);
});
DeleteStage("should delete one stage and only its linked data", () => {
manager.create({
name: "Example 1",
tournamentId: 0,
type: "single_elimination",
seeding: [1, 2, 3, 4],
});
manager.create({
name: "Example 2",
tournamentId: 0,
type: "single_elimination",
seeding: [1, 2, 3, 4],
});
manager.delete.stage(0);
const stages = storage.select<any>("stage")!;
const groups = storage.select<any>("group")!;
const rounds = storage.select<any>("round")!;
const matches = storage.select<any>("match")!;
assert.equal(stages.length, 1);
assert.equal(groups.length, 1);
assert.equal(rounds.length, 2);
assert.equal(matches.length, 3);
// Remaining data
assert.equal(stages[0].id, 1);
assert.equal(groups[0].id, 1);
assert.equal(rounds[0].id, 2);
assert.equal(matches[0].id, 3);
});
DeleteStage("should delete all stages of the tournament", () => {
manager.create({
name: "Example 1",
tournamentId: 0,
type: "single_elimination",
seeding: [1, 2, 3, 4],
});
manager.create({
name: "Example 2",
tournamentId: 0,
type: "single_elimination",
seeding: [1, 2, 3, 4],
});
manager.delete.tournament(0);
const stages = storage.select("stage")!;
const groups = storage.select("group")!;
const rounds = storage.select("round")!;
const matches = storage.select<any>("match")!;
assert.equal(stages.length, 0);
assert.equal(groups.length, 0);
assert.equal(rounds.length, 0);
assert.equal(matches.length, 0);
});
DeleteStage.run();