From 6916cf8ed7b348dc2e2e1127dff1bdce10c4715c Mon Sep 17 00:00:00 2001 From: zkldi Date: Thu, 29 Apr 2021 23:16:11 +0100 Subject: [PATCH] Add PB Processor tests --- .../framework/core/pb/process-pbs.test.ts | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 server/src/score-import/framework/core/pb/process-pbs.test.ts diff --git a/server/src/score-import/framework/core/pb/process-pbs.test.ts b/server/src/score-import/framework/core/pb/process-pbs.test.ts new file mode 100644 index 000000000..d627950a9 --- /dev/null +++ b/server/src/score-import/framework/core/pb/process-pbs.test.ts @@ -0,0 +1,69 @@ +import t from "tap"; +import db, { CloseMongoConnection } from "../../../../db/db"; +import CreateLogCtx from "../../../../logger"; +import ResetDBState from "../../../../test-utils/reset-db-state"; +import { Testing511SPA, TestingIIDXSPScore } from "../../../../test-utils/test-data"; +import { ProcessPBs } from "./process-pbs"; +import deepmerge from "deepmerge"; +import crypto from "crypto"; + +const logger = CreateLogCtx("process-pbs.test.ts"); + +t.test("#ProcessPBs", (t) => { + t.beforeEach(ResetDBState); + + t.test("Should successfully insert a pb into the score-pb database", async (t) => { + await db["score-pbs"].remove({}); + + // scores on 511 SPA are pre-loaded into the database + let res = await ProcessPBs(1, new Set([Testing511SPA.chartID]), logger); + + t.equal(res, 1, "Should return the amount of PBs inserted"); + + let pbs = await db["score-pbs"].find({}); + + t.equal(res, pbs.length, "Should match the amount of PBs inserted into the DB."); + + t.end(); + }); + + t.test("Should successfully insert multiple pbs into the score-pb database", async (t) => { + await db["score-pbs"].remove({}); + + await db.scores.insert([ + // @ts-expect-error lol + deepmerge(TestingIIDXSPScore, { + chartID: "test1", + scoreID: crypto.randomBytes(20).toString("hex"), + }), + // @ts-expect-error lol + deepmerge(TestingIIDXSPScore, { + chartID: "test2", + scoreID: crypto.randomBytes(20).toString("hex"), + }), + // @ts-expect-error lol + deepmerge(TestingIIDXSPScore, { + chartID: "test3", + scoreID: crypto.randomBytes(20).toString("hex"), + }), + ]); + + let res = await ProcessPBs( + 1, + new Set([Testing511SPA.chartID, "test1", "test2", "test3"]), + logger + ); + + t.equal(res, 4, "Should return the amount of PBs inserted"); + + let pbs = await db["score-pbs"].find({}); + + t.equal(res, pbs.length, "Should match the amount of PBs inserted into the DB."); + + t.end(); + }); + + t.end(); +}); + +t.teardown(CloseMongoConnection);