From ff6a77d431919fda7fb0b4263cbcd00a9c36a514 Mon Sep 17 00:00:00 2001 From: Hamcha Date: Thu, 12 Sep 2019 14:37:50 +0200 Subject: [PATCH] Include shim in testing package --- src/testing/index.ts | 1 + src/tests/unit/database.spec.ts | 2 +- src/tests/unit/draft.spec.ts | 18 ++++++++++++++++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/testing/index.ts b/src/testing/index.ts index a0824bf..a9aa129 100644 --- a/src/testing/index.ts +++ b/src/testing/index.ts @@ -2,3 +2,4 @@ export * from "./MockDataConnection"; export * from "./MockPeer"; export * from "./MockHelper"; export * from "./EventHook"; +export * from "./IDBShim"; diff --git a/src/tests/unit/database.spec.ts b/src/tests/unit/database.spec.ts index 1bb70a5..d1d77ff 100644 --- a/src/tests/unit/database.spec.ts +++ b/src/tests/unit/database.spec.ts @@ -1,5 +1,5 @@ import { loadSets, getCards, Database, initDB, cardFullName } from "@/mlpccg"; -import { setupIDBShim } from "@/testing/IDBShim"; +import { setupIDBShim } from "@/testing"; setupIDBShim(); diff --git a/src/tests/unit/draft.spec.ts b/src/tests/unit/draft.spec.ts index 3d49435..d9015e3 100644 --- a/src/tests/unit/draft.spec.ts +++ b/src/tests/unit/draft.spec.ts @@ -1,6 +1,6 @@ -import { setupIDBShim } from "@/testing/IDBShim"; +import { setupIDBShim } from "@/testing"; import { initDB, loadSets, Database } from "@/mlpccg"; -import { PackBuilder, spanByRarity } from "@/mlpccg/draft"; +import { PackBuilder, spanByRarity, Cube } from "@/mlpccg/draft"; setupIDBShim(); @@ -22,4 +22,18 @@ describe("mlpccg/draft", () => { expect(rarities["R"]).toHaveLength(1); expect(rarities["U"]).toHaveLength(3); }); + + test("Cube can load a newline separated card list", async () => { + expect(Database).toBeTruthy(); + const cubeCards = ["ff10", "ff11", "ff12", "ff13", "ff14", "ff15"]; + const cubeList = cubeCards.join("\n"); + const cube = await Cube.fromList(cubeList); + const builder = new PackBuilder(cube.schema()); + const pack = builder.buildPack(); + // Pack size should only be 6, since there are not enough cards for a 12 cards pack + expect(pack).toHaveLength(6); + // Make sure pack has ALL the cards from the pool, no duplicates + const sortedPack = pack.map(c => c.ID).sort(); + expect(sortedPack).toEqual(cubeCards); + }); });