diff --git a/server/src/lib/score-import/import-types/common/eamusement-iidx-csv/converter.test.ts b/server/src/lib/score-import/import-types/common/eamusement-iidx-csv/converter.test.ts index 5ce652364..2afbf0ffe 100644 --- a/server/src/lib/score-import/import-types/common/eamusement-iidx-csv/converter.test.ts +++ b/server/src/lib/score-import/import-types/common/eamusement-iidx-csv/converter.test.ts @@ -2,7 +2,7 @@ import t from "tap"; import db from "../../../../../external/mongo/db"; import CreateLogCtx from "../../../../logger/logger"; import ResetDBState from "../../../../../test-utils/reset-db-state"; -import ConvertEamIIDXCSV, { EamScoreConverter, EamScoreConverterWrapper } from "./converter"; +import ConvertEamIIDXCSV from "./converter"; import p from "prudence"; import { prAssert } from "../../../../../test-utils/asserts"; import deepmerge from "deepmerge"; @@ -63,330 +63,6 @@ const data = { title: "5.1.1", }; -// Testing floats with strictSame under tap is a pain because it uses === -// and there is no way around it. We have isApproximately for this purpose -// But it'd be easier if we could just .toFixed() the percent and compare it as -// a string. - -t.test("#EamScoreConverter", async (t) => { - t.beforeEach(ResetDBState); - - const song = { - title: "5.1.1.", - artist: "dj nagureo", - id: 1, - firstVersion: "0", - "alt-titles": [], - "search-titles": [], - data: { - genre: "PIANO AMBIENT", - }, - }; - - function EamScoreConverterAuto(score: Partial = {}) { - return EamScoreConverter( - deepmerge(valid511Score, score) as EamusementScoreData, - song, - converterContext, - data, - false, - logger - ); - } - - t.test("Valid Scores", (t) => { - t.test("Normal 511 SPA Score", async (t) => { - const res = await EamScoreConverterAuto(); - - t.not(res, null, "Should not be null."); - - t.equal( - res!.ktchiChart.chartID, - chartID511, - "Should have selected 511 SPA as the chart." - ); - - prAssert(res!.dryScore, DryScorePrudence, "Should return the expected dryscore."); - - t.end(); - }); - - t.test("--- BP Score", async (t) => { - const res = await EamScoreConverterAuto({ bp: "---" }); - - t.not(res, null, "Should not be null."); - - t.equal( - res!.ktchiChart.chartID, - chartID511, - "Should have selected 511 SPA as the chart." - ); - - prAssert( - res!.dryScore, - deepmerge(DryScorePrudence, { scoreData: { hitMeta: { bp: "undefined" } } }), - "Should return the expected dryscore." - ); - - t.end(); - }); - - t.test("Nonsense String BP Score", async (t) => { - const res = await EamScoreConverterAuto({ bp: "ASDF" }); - - t.not(res, null, "Should not be null."); - - t.equal( - res!.ktchiChart.chartID, - chartID511, - "Should have selected 511 SPA as the chart." - ); - - prAssert( - res!.dryScore, - deepmerge(DryScorePrudence, { scoreData: { hitMeta: { bp: "undefined" } } }), - "Should return the expected dryscore." - ); - - t.end(); - }); - - t.test("0 EX Score", async (t) => { - const res = await EamScoreConverterAuto({ exscore: "0", pgreat: "0", great: "0" }); - - t.equal(res, null, "Should be null."); - - t.end(); - }); - - t.test("1 EX Score", async (t) => { - const res = await EamScoreConverterAuto({ exscore: "1", pgreat: "0", great: "1" }); - - t.not(res, null, "Should not be null."); - - t.equal( - res!.ktchiChart.chartID, - chartID511, - "Should have selected 511 SPA as the chart." - ); - - prAssert( - res!.dryScore, - deepmerge(DryScorePrudence, { - scoreData: { - score: p.equalTo(1), - percent: p.aprx(0.063), - hitData: { - pgreat: p.equalTo(0), - great: p.equalTo(1), - }, - }, - }), - "Should return the expected dryscore." - ); - - t.end(); - }); - - t.test("Level 0 chart", async (t) => { - const res = await EamScoreConverterAuto({ level: "0" }); - - t.equal(res, null, "Should be null."); - - t.end(); - }); - - t.end(); - }); - - t.test("Invalid Scores", (t) => { - t.test("Chart that doesn't exist", (t) => { - EamScoreConverterAuto({ difficulty: "LEGGENDARIA" }) - .then(() => t.fail()) - .catch((err) => { - t.strictSame( - err, - new KTDataNotFoundFailure( - `Could not find chart for 5.1.1. (SP LEGGENDARIA [v27])`, - "file/eamusement-iidx-csv", - data, - converterContext - ), - "Should return a KTDataNotFoundFailure" - ); - - t.end(); - }); - }); - - t.test("Invalid PGreat/Great count", (t) => { - EamScoreConverterAuto({ exscore: "100", pgreat: "20", great: "5" }) - .then(() => t.fail()) - .catch((err) => { - t.strictSame( - err, - new InvalidScoreFailure( - `5.1.1. (SP ANOTHER [v27]) - PGreats * 2 + Greats did not equal EXScore (20 * 2 + 5 != 100).` - ), - "Should return an InvalidScoreFailure" - ); - - t.end(); - }); - }); - - t.test(">100%", (t) => { - EamScoreConverterAuto({ exscore: "9999" }) - .then(() => t.fail()) - .catch((err) => { - t.strictSame( - err, - new InvalidScoreFailure( - `5.1.1. (SP ANOTHER [v27]) - Invalid EX Score of 9999 (Was greater than max chart ex of 1572).` - ), - "Should return an InvalidScoreFailure" - ); - - t.end(); - }); - }); - - t.test("Nonsense Lamp", (t) => { - EamScoreConverterAuto({ lamp: "invalid" }) - .then(() => t.fail()) - .catch((err) => { - t.strictSame( - err, - new InvalidScoreFailure( - `5.1.1. (SP ANOTHER [v27]) - Invalid Lamp of invalid.` - ), - "Should return an InvalidScoreFailure" - ); - - t.end(); - }); - }); - - t.test("Invalid BP", async (t) => { - await EamScoreConverterAuto({ bp: "5.73" }) - .then(() => t.fail()) - .catch((err) => { - t.strictSame( - err, - new InvalidScoreFailure(`5.1.1. (SP ANOTHER [v27]) - Invalid BP of 5.73.`), - "Should return an InvalidScoreFailure" - ); - }); - - await EamScoreConverterAuto({ bp: "-5.73" }) - .then(() => t.fail()) - .catch((err) => { - t.strictSame( - err, - new InvalidScoreFailure(`5.1.1. (SP ANOTHER [v27]) - Invalid BP of -5.73.`), - "Should return an InvalidScoreFailure" - ); - }); - - await EamScoreConverterAuto({ bp: "-1" }) - .then(() => t.fail()) - .catch((err) => { - t.strictSame( - err, - new InvalidScoreFailure(`5.1.1. (SP ANOTHER [v27]) - Invalid BP of -1.`), - "Should return an InvalidScoreFailure" - ); - }); - - await EamScoreConverterAuto({ bp: "10000" }) - .then(() => t.fail()) - .catch((err) => { - t.strictSame( - err, - new InvalidScoreFailure(`5.1.1. (SP ANOTHER [v27]) - Invalid BP of 10000.`), - "Should return an InvalidScoreFailure" - ); - }); - - await EamScoreConverterAuto({ bp: "-10000" }) - .then(() => t.fail()) - .catch((err) => { - t.strictSame( - err, - new InvalidScoreFailure( - `5.1.1. (SP ANOTHER [v27]) - Invalid BP of -10000.` - ), - "Should return an InvalidScoreFailure" - ); - }); - - t.end(); - }); - - t.end(); - }); - - t.end(); -}); - -t.test("#EamScoreConverterWrapper", async (t) => { - t.beforeEach(ResetDBState); - - const song = { - title: "5.1.1.", - artist: "dj nagureo", - id: 1, - firstVersion: "0", - "alt-titles": [], - "search-titles": [], - data: { - genre: "PIANO AMBIENT", - }, - }; - - // wrapper wrapper, lol - function EamScoreConverterWrapperAuto(score: Partial = {}) { - return EamScoreConverterWrapper( - deepmerge(valid511Score, score) as EamusementScoreData, - song, - converterContext, - data, - false, - logger - ); - } - - t.test("Should convert thrown errors into returns", async (t) => { - const res = await EamScoreConverterWrapperAuto({ exscore: "-1" }); - - t.strictSame( - res, - new InvalidScoreFailure( - "5.1.1. (SP ANOTHER [v27]) - Invalid EX score of -1 (Was negative.)" - ) - ); - - t.end(); - }); - - t.test("Should return EamScoreConverter on success", async (t) => { - const res = await EamScoreConverterWrapperAuto(); - - if (res instanceof ConverterFailure || !res) { - return t.fail("Unexpected ConverterFailure"); - } - - t.strictSame(res.song, song, "Should return the right song"); - t.equal(res.chart.chartID, chartID511, "Should return the right chart"); - - prAssert(res.dryScore, DryScorePrudence, "Should return the right DryScore."); - - t.end(); - }); - - t.end(); -}); - t.todo("#ConverterFn", async (t) => { t.beforeEach(ResetDBState);