mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-01 11:28:13 +03:00
@@ -3,6 +3,7 @@ import mockApi from "../../test-utils/mock-api";
|
||||
import {
|
||||
GetKTDataBuffer,
|
||||
GetKTDataJSON,
|
||||
LoadKTBlackIIDXData,
|
||||
TestingIIDXEamusementCSV26,
|
||||
TestingIIDXEamusementCSV27,
|
||||
} from "../../test-utils/test-data";
|
||||
@@ -12,16 +13,6 @@ import { CreateFakeAuthCookie } from "../../test-utils/fake-session";
|
||||
import ResetDBState from "../../test-utils/reset-db-state";
|
||||
import db from "../../db/db";
|
||||
|
||||
async function LoadKTBlackIIDXData() {
|
||||
const songs = GetKTDataJSON("./kamaitachi/ktblack-songs-iidx.json");
|
||||
const charts = GetKTDataJSON("./kamaitachi/ktblack-charts-iidx.json");
|
||||
|
||||
await db.songs.iidx.remove({});
|
||||
await db.songs.iidx.insert(songs);
|
||||
await db.charts.iidx.remove({});
|
||||
await db.charts.iidx.insert(charts);
|
||||
}
|
||||
|
||||
// reset DB handles the post-stuff
|
||||
|
||||
t.test("POST /api/import/file", async (t) => {
|
||||
|
||||
@@ -1,14 +1,137 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import t from "tap";
|
||||
import { CloseMongoConnection } from "../../../../db/db";
|
||||
import db, { CloseMongoConnection } from "../../../../db/db";
|
||||
import CreateLogCtx from "../../../../logger";
|
||||
import ResetDBState from "../../../../test-utils/reset-db-state";
|
||||
import {
|
||||
GetKTDataJSON,
|
||||
LoadKTBlackIIDXData,
|
||||
Testing511Song,
|
||||
Testing511SPA,
|
||||
} from "../../../../test-utils/test-data";
|
||||
import { ConvertFileMerIIDX } from "./converter";
|
||||
import deepmerge from "deepmerge";
|
||||
import { MerScore } from "./types";
|
||||
|
||||
t.todo("#ConvertFileMerIIDX", (t) => {
|
||||
const logger = CreateLogCtx("converter.test.ts");
|
||||
|
||||
t.test("#ConvertFileMerIIDX", (t) => {
|
||||
t.beforeEach(ResetDBState);
|
||||
|
||||
// t.test("", (t) => {
|
||||
// t.end();
|
||||
// });
|
||||
function merc(g: Partial<MerScore> = {}) {
|
||||
return ConvertFileMerIIDX(deepmerge(MerScore, g), {}, "file/mer-iidx", logger);
|
||||
}
|
||||
|
||||
const MerScore = GetKTDataJSON("./mer/merscore.json");
|
||||
|
||||
t.test("Valid Conversion", async (t) => {
|
||||
const res = await ConvertFileMerIIDX(MerScore, {}, "file/mer-iidx", logger);
|
||||
|
||||
t.hasStrict(
|
||||
res,
|
||||
{
|
||||
song: Testing511Song,
|
||||
chart: Testing511SPA,
|
||||
dryScore: {
|
||||
game: "iidx",
|
||||
comment: null,
|
||||
importType: "file/mer-iidx",
|
||||
service: "MER",
|
||||
scoreData: {
|
||||
score: 1000,
|
||||
// percent: 63.61, approximately, fpa impossible.
|
||||
grade: "B",
|
||||
lamp: "CLEAR",
|
||||
hitData: {},
|
||||
hitMeta: {
|
||||
bp: 21,
|
||||
},
|
||||
},
|
||||
scoreMeta: {},
|
||||
timeAchieved: 1616570122000,
|
||||
},
|
||||
} as any,
|
||||
"Should return the converted dry score."
|
||||
);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.test("Valid DP Conversion", async (t) => {
|
||||
await LoadKTBlackIIDXData();
|
||||
const res = await merc({ play_type: "DOUBLE" });
|
||||
|
||||
t.hasStrict(
|
||||
res,
|
||||
{
|
||||
song: { id: 1 },
|
||||
chart: { playtype: "DP", data: { inGameID: 1000 } },
|
||||
dryScore: {
|
||||
game: "iidx",
|
||||
comment: null,
|
||||
importType: "file/mer-iidx",
|
||||
service: "MER",
|
||||
scoreData: {
|
||||
score: 1000,
|
||||
// percent: 63.61, approximately, fpa impossible.
|
||||
grade: "B",
|
||||
lamp: "CLEAR",
|
||||
hitData: {},
|
||||
hitMeta: {
|
||||
bp: 21,
|
||||
},
|
||||
},
|
||||
scoreMeta: {},
|
||||
timeAchieved: 1616570122000,
|
||||
},
|
||||
} as any,
|
||||
"Should return the converted dry score."
|
||||
);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.test("Invalid Chart", (t) => {
|
||||
t.rejects(() => merc({ diff_type: "LEGGENDARIA" }), {
|
||||
message: /Could not find chart with musicID 1000 \(SP LEGGENDARIA/u,
|
||||
} as any);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.test("Invalid Song", (t) => {
|
||||
t.rejects(() => merc({ music_id: 0 }), {
|
||||
message: /Could not find chart with musicID 0/u,
|
||||
} as any);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.test("Should log severe on Song-Chart Desync", async (t) => {
|
||||
await db.songs.iidx.remove({});
|
||||
|
||||
t.rejects(() => merc(), {
|
||||
message: /Song-Chart Desync on songID 1/u,
|
||||
} as any);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.test("Invalid Percent", (t) => {
|
||||
t.rejects(() => merc({ score: 9999 }), {
|
||||
message: /Percent was greater than 100%/u,
|
||||
} as any);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.test("Invalid Date", (t) => {
|
||||
t.rejects(() => merc({ update_time: "INVALID" }), {
|
||||
message: /Invalid score timestamp of INVALID/u,
|
||||
} as any);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
@@ -64,7 +64,7 @@ export const ConvertFileMerIIDX: ConverterFunction<MerScore, EmptyObject> = asyn
|
||||
const timeAchieved = Date.parse(data.update_time);
|
||||
|
||||
if (Number.isNaN(timeAchieved)) {
|
||||
throw new InvalidScoreFailure(`Invalid score timestamp of ${timeAchieved}`);
|
||||
throw new InvalidScoreFailure(`Invalid score timestamp of ${data.update_time}`);
|
||||
}
|
||||
|
||||
const dryScore: DryScore<"iidx:SP" | "iidx:DP"> = {
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
SongDocument,
|
||||
} from "kamaitachi-common";
|
||||
import path from "path";
|
||||
import db from "../db/db";
|
||||
import { BarbatosScore } from "../score-import/import-types/ir/barbatos/types";
|
||||
import { DryScore } from "../types";
|
||||
|
||||
@@ -144,3 +145,13 @@ export const TestingIIDXSPMilestone: MilestoneDocument = {
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export async function LoadKTBlackIIDXData() {
|
||||
const songs = GetKTDataJSON("./kamaitachi/ktblack-songs-iidx.json");
|
||||
const charts = GetKTDataJSON("./kamaitachi/ktblack-charts-iidx.json");
|
||||
|
||||
await db.songs.iidx.remove({});
|
||||
await db.songs.iidx.insert(songs);
|
||||
await db.charts.iidx.remove({});
|
||||
await db.charts.iidx.insert(charts);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"music_id": 1000,
|
||||
"play_type": "SINGLE",
|
||||
"diff_type": "ANOTHER",
|
||||
"score": 1000,
|
||||
"miss_count": 21,
|
||||
"clear_type": "CLEAR",
|
||||
"update_time": "2021-03-24 07:15:22"
|
||||
}
|
||||
Reference in New Issue
Block a user