mirror of
https://github.com/zkldi/Tachi.git
synced 2026-09-29 18:37:58 +03:00
Mer test groundwork
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import t from "tap";
|
||||
import { CloseMongoConnection } from "../../../../db/db";
|
||||
import ResetDBState from "../../../../test-utils/reset-db-state";
|
||||
import { ConvertFileMerIIDX } from "./converter";
|
||||
|
||||
t.test("#ConvertFileMerIIDX", (t) => {
|
||||
t.beforeEach(ResetDBState);
|
||||
|
||||
t.test("", (t) => {
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseMongoConnection);
|
||||
@@ -0,0 +1,94 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import t from "tap";
|
||||
import { CloseMongoConnection } from "../../../../db/db";
|
||||
import CreateLogCtx from "../../../../logger";
|
||||
import { MockMulterFile } from "../../../../test-utils/mock-multer";
|
||||
import ResetDBState from "../../../../test-utils/reset-db-state";
|
||||
import { GetKTDataBuffer } from "../../../../test-utils/test-data";
|
||||
import { ParseMerIIDX } from "./parser";
|
||||
|
||||
const logger = CreateLogCtx("parser.test.ts");
|
||||
|
||||
t.test("#ParseMerIIDX", (t) => {
|
||||
t.beforeEach(ResetDBState);
|
||||
|
||||
function mrfb(buffer: Buffer) {
|
||||
return ParseMerIIDX(MockMulterFile(buffer, "buffer.json"), {}, logger);
|
||||
}
|
||||
|
||||
function mrff(filename: string) {
|
||||
return ParseMerIIDX(MockMulterFile(GetKTDataBuffer(filename), filename), {}, logger);
|
||||
}
|
||||
|
||||
// @todo Better tests for invalidating bad input?
|
||||
|
||||
t.test("Basic Parsing", (t) => {
|
||||
const res = mrff("./mer/base.json");
|
||||
|
||||
t.hasStrict(
|
||||
res,
|
||||
{
|
||||
game: "iidx",
|
||||
context: {},
|
||||
classHandler: null,
|
||||
iterable: [
|
||||
{
|
||||
music_id: 3007,
|
||||
music_name: "Presto",
|
||||
play_type: "SINGLE",
|
||||
diff_type: "HYPER",
|
||||
score: 566,
|
||||
miss_count: 46,
|
||||
clear_type: "NO PLAY",
|
||||
update_time: "2019-06-01 19:56:59",
|
||||
},
|
||||
{
|
||||
music_id: 3013,
|
||||
music_name: "THE SAFARI",
|
||||
play_type: "SINGLE",
|
||||
diff_type: "NORMAL",
|
||||
score: 681,
|
||||
miss_count: 102,
|
||||
clear_type: "FAILED",
|
||||
update_time: "2019-05-30 03:21:57",
|
||||
},
|
||||
{
|
||||
music_id: 3213,
|
||||
music_name: "TAKE ON ME",
|
||||
play_type: "SINGLE",
|
||||
diff_type: "ANOTHER",
|
||||
score: 922,
|
||||
miss_count: 56,
|
||||
clear_type: "CLEAR",
|
||||
update_time: "2019-05-03 02:10:58",
|
||||
},
|
||||
],
|
||||
} as any,
|
||||
"Should correctly parse data."
|
||||
);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.test("Should throw on invalid JSON", (t) => {
|
||||
t.throws(() => mrfb(Buffer.from("{]")));
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.test("Should throw on non-top-level-array", (t) => {
|
||||
t.throws(() => mrfb(Buffer.from("{}")));
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.test("Should throw on invalid Mer Scores", (t) => {
|
||||
t.throws(() => mrfb(Buffer.from(JSON.stringify([{ foo: "bar" }]))));
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseMongoConnection);
|
||||
@@ -34,7 +34,7 @@ export function ParseMerIIDX(
|
||||
try {
|
||||
jsonData = JSON.parse(fileData.buffer.toString("utf-8"));
|
||||
} catch (err) {
|
||||
logger.info(err);
|
||||
logger.info(err.message);
|
||||
throw new ScoreImportFatalError(400, "Invalid JSON.");
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ export function ParseMerIIDX(
|
||||
const err = p(jsonData[i], PR_MerIIDX, {}, { allowExcessKeys: true });
|
||||
|
||||
if (err) {
|
||||
throw new ScoreImportFatalError(400, FormatPrError(err));
|
||||
throw new ScoreImportFatalError(400, `${FormatPrError(err)} [Index ${i}]`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user