From d48ccee388dc71829981c5a36dc708107cb3419d Mon Sep 17 00:00:00 2001 From: zkldi <20380519+zkldi@users.noreply.github.com> Date: Sun, 18 Dec 2022 08:45:35 +0000 Subject: [PATCH] test: other cg converter tests honestly these tests are super barebones but i mean they're good enough. I hate writing tests. --- .../common/api-cg/museca/converter.test.ts | 103 +++++++++++++++++ .../common/api-cg/sdvx/converter.test.ts | 104 ++++++++++++++++++ .../src/test-utils/mock-db/charts-museca.json | 20 ++++ .../src/test-utils/mock-db/songs-museca.json | 14 +++ 4 files changed, 241 insertions(+) create mode 100644 server/src/lib/score-import/import-types/common/api-cg/museca/converter.test.ts create mode 100644 server/src/lib/score-import/import-types/common/api-cg/sdvx/converter.test.ts create mode 100644 server/src/test-utils/mock-db/charts-museca.json create mode 100644 server/src/test-utils/mock-db/songs-museca.json diff --git a/server/src/lib/score-import/import-types/common/api-cg/museca/converter.test.ts b/server/src/lib/score-import/import-types/common/api-cg/museca/converter.test.ts new file mode 100644 index 000000000..fc5c62c6a --- /dev/null +++ b/server/src/lib/score-import/import-types/common/api-cg/museca/converter.test.ts @@ -0,0 +1,103 @@ +import { ConverterAPICGMuseca } from "./converter"; +import CreateLogCtx from "lib/logger/logger"; +import t from "tap"; +import { dmf } from "test-utils/misc"; +import type { CGContext, CGMusecaScore } from "../types"; +import type { DryScore } from "lib/score-import/framework/common/types"; + +const logger = CreateLogCtx(__filename); + +function mkInput(modifant: Partial = {}) { + const validInput: CGMusecaScore = { + internalId: 1, // ALBIDA (Remix) ADV + difficulty: 0, + dateTime: "2019-06-06 08:14:22", + score: 912_000, + version: 1, + clearType: 2, + critical: 100, + near: 50, + error: 10, + maxChain: 300, + scoreGrade: "whatever, this is unused", + }; + + return dmf(validInput, modifant); +} + +// we use any here because it's not easy to allow deep partials +function mkOutput(modifant: any = {}): DryScore<"museca:Single"> { + const validOutput: DryScore<"museca:Single"> = { + comment: null, + game: "museca", + importType: "api/cg-dev-museca", + timeAchieved: 1559805262000, + service: "dev", + scoreData: { + grade: "優", + percent: 91.2, + score: 912_000, + lamp: "CLEAR", + judgements: { + critical: 100, + near: 50, + miss: 10, + }, + hitMeta: {}, + }, + scoreMeta: {}, + }; + + return dmf(validOutput, modifant); +} + +t.test("#ConverterAPICGMuseca", (t) => { + const context: CGContext = { + service: "dev", + userID: 1, + }; + + const convert = (modifant: Partial = {}) => + ConverterAPICGMuseca(mkInput(modifant), context, "api/cg-dev-museca", logger); + + t.test("Valid Input", async (t) => { + const res = await convert(); + + t.hasStrict(res, { + song: { + id: 1, + }, + chart: { + difficulty: "Green", + data: { + inGameID: 1, + }, + }, + dryScore: mkOutput(), + }); + + t.end(); + }); + + t.test("Lamps", async (t) => { + t.hasStrict(await convert({ score: 1_000_000 }), { + dryScore: { scoreData: { lamp: "PERFECT CONNECT ALL" } }, + }); + t.hasStrict(await convert({ score: 900_000, error: 0 }), { + dryScore: { scoreData: { lamp: "CONNECT ALL" } }, + }); + t.hasStrict(await convert({ score: 800_000, error: 10 }), { + dryScore: { scoreData: { lamp: "CLEAR" } }, + }); + t.hasStrict(await convert({ score: 700_000, error: 10 }), { + dryScore: { scoreData: { lamp: "FAILED" } }, + }); + t.hasStrict(await convert({ score: 799_999, error: 10 }), { + dryScore: { scoreData: { lamp: "FAILED" } }, + }); + + t.end(); + }); + + t.end(); +}); diff --git a/server/src/lib/score-import/import-types/common/api-cg/sdvx/converter.test.ts b/server/src/lib/score-import/import-types/common/api-cg/sdvx/converter.test.ts new file mode 100644 index 000000000..b8cc0ed96 --- /dev/null +++ b/server/src/lib/score-import/import-types/common/api-cg/sdvx/converter.test.ts @@ -0,0 +1,104 @@ +import { ConverterAPICGSDVX } from "./converter"; +import CreateLogCtx from "lib/logger/logger"; +import t from "tap"; +import { dmf } from "test-utils/misc"; +import type { CGContext, CGSDVXScore } from "../types"; +import type { DryScore } from "lib/score-import/framework/common/types"; + +const logger = CreateLogCtx(__filename); + +function mkInput(modifant: Partial = {}) { + const validInput: CGSDVXScore = { + internalId: 1, // ALBIDA (Remix) ADV + difficulty: 1, + dateTime: "2019-06-06 08:14:22", + score: 9_123_000, + version: 6, + clearType: 2, + critical: 100, + near: 50, + error: 10, + exScore: 1234, + maxChain: 300, + scoreGrade: "whatever, this is unused", + }; + + return dmf(validInput, modifant); +} + +// we use any here because it's not easy to allow deep partials +function mkOutput(modifant: any = {}): DryScore<"sdvx:Single"> { + const validOutput: DryScore<"sdvx:Single"> = { + comment: null, + game: "sdvx", + importType: "api/cg-dev-sdvx", + timeAchieved: 1559805262000, + service: "dev", + scoreData: { + grade: "A+", + percent: 91.23, + score: 9_123_000, + lamp: "EXCESSIVE CLEAR", + judgements: { + critical: 100, + near: 50, + miss: 10, + }, + hitMeta: {}, + }, + scoreMeta: {}, + }; + + return dmf(validOutput, modifant); +} + +t.test("#ConverterAPICGSDVX", (t) => { + const context: CGContext = { + service: "dev", + userID: 1, + }; + + const convert = (modifant: Partial = {}) => + ConverterAPICGSDVX(mkInput(modifant), context, "api/cg-dev-sdvx", logger); + + t.test("Valid Input", async (t) => { + const res = await convert(); + + t.hasStrict(res, { + song: { + id: 1, + }, + chart: { + difficulty: "ADV", + data: { + inGameID: 1, + }, + }, + dryScore: mkOutput(), + }); + + t.end(); + }); + + t.test("Lamps", async (t) => { + t.hasStrict(await convert({ clearType: 0 }), { + dryScore: mkOutput({ scoreData: { lamp: "FAILED" } }), + }); + t.hasStrict(await convert({ clearType: 1 }), { + dryScore: mkOutput({ scoreData: { lamp: "CLEAR" } }), + }); + t.hasStrict(await convert({ clearType: 2 }), { + dryScore: mkOutput({ scoreData: { lamp: "EXCESSIVE CLEAR" } }), + }); + t.hasStrict(await convert({ clearType: 3 }), { + dryScore: mkOutput({ scoreData: { lamp: "ULTIMATE CHAIN" } }), + }); + t.hasStrict(await convert({ clearType: 4 }), { + dryScore: mkOutput({ scoreData: { lamp: "PERFECT ULTIMATE CHAIN" } }), + }); + + t.end(); + }); + + t.end(); +}); diff --git a/server/src/test-utils/mock-db/charts-museca.json b/server/src/test-utils/mock-db/charts-museca.json new file mode 100644 index 000000000..d193c22db --- /dev/null +++ b/server/src/test-utils/mock-db/charts-museca.json @@ -0,0 +1,20 @@ +[ + { + "chartID": "70b80da02a2037d556026b412c386b2fd1e57dbd", + "data": { + "inGameID": 1 + }, + "difficulty": "Green", + "isPrimary": true, + "level": "3", + "levelNum": 3, + "playtype": "Single", + "rgcID": null, + "songID": 1, + "tierlistInfo": {}, + "versions": [ + "1.5", + "1.5-b" + ] + } +] \ No newline at end of file diff --git a/server/src/test-utils/mock-db/songs-museca.json b/server/src/test-utils/mock-db/songs-museca.json new file mode 100644 index 000000000..17e1eef37 --- /dev/null +++ b/server/src/test-utils/mock-db/songs-museca.json @@ -0,0 +1,14 @@ +[ + { + "altTitles": [], + "artist": "Last Note. feat. GUMI", + "data": { + "artistJP": "ラストノートフィーチャリンググミ", + "displayVersion": "1", + "titleJP": "セツナトリップ" + }, + "id": 1, + "searchTerms": [], + "title": "セツナトリップ" + } +] \ No newline at end of file