diff --git a/server/@types/tap/index.d.ts b/server/@types/tap/index.d.ts deleted file mode 100644 index 88fb9ff62..000000000 --- a/server/@types/tap/index.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ - -declare module "tap" { - export function rejects( - promiseOrFn: Promise | ((...args: any[]) => Promise), - expectedError: any, - message?: string, - extra?: any - ): Promise; -} diff --git a/server/src/lib/score-import/import-types/api/arc-ddr/converter.test.ts b/server/src/lib/score-import/import-types/api/arc-ddr/converter.test.ts new file mode 100644 index 000000000..e7ae4cdde --- /dev/null +++ b/server/src/lib/score-import/import-types/api/arc-ddr/converter.test.ts @@ -0,0 +1,66 @@ +import t from "tap"; +import { CloseAllConnections } from "../../../../../test-utils/close-connections"; +import ResetDBState from "../../../../../test-utils/reset-db-state"; +import { GetKTDataJSON } from "../../../../../test-utils/test-data"; +import CreateLogCtx from "../../../../logger/logger"; +import { ConvertAPIArcDDR } from "./converter"; +import { ARCDDRScore } from "./types"; +import deepmerge from "deepmerge"; + +const logger = CreateLogCtx(__filename); + +const arcScore = GetKTDataJSON("./api-arc/ddr-score.json") as ARCDDRScore; + +t.test("#ConvertAPIArcDDR", (t) => { + t.beforeEach(ResetDBState); + + t.test("Should convert a valid score", async (t) => { + const res = await ConvertAPIArcDDR(arcScore, {}, "api/arc-ddr", logger); + + t.strictSame(res, { + song: {}, + chart: {}, + dryScore: {}, + }); + + t.end(); + }); + + t.test("Should throw on an invalid score", (t) => { + t.rejects( + () => + ConvertAPIArcDDR( + deepmerge(arcScore, { ex_score: "foo" }), + {}, + "api/arc-ddr", + logger + ), + { + message: /Invalid ARC Score:/iu, + } as any + ); + + t.end(); + }); + + t.test("Should throw on no chart", (t) => { + t.rejects( + () => + ConvertAPIArcDDR( + deepmerge(arcScore, { chart_id: "foo" }), + {}, + "api/arc-ddr", + logger + ), + { + message: /Could not find chart/iu, + } as any + ); + + t.end(); + }); + + t.end(); +}); + +t.teardown(CloseAllConnections);