add beatoraja score conversion tests

This commit is contained in:
zkldi
2021-05-28 09:35:28 +01:00
parent e2bd24595d
commit 65f810db09
2 changed files with 189 additions and 3 deletions
@@ -1,6 +1,190 @@
import t from "tap";
import db, { CloseMongoConnection } from "../../../../../external/mongo/db";
import ResetDBState from "../../../../../test-utils/reset-db-state";
import { GetKTDataJSON } from "../../../../../test-utils/test-data";
import { KtchiPBScoreToBeatorajaFormat } from "./convert-scores";
import { ScoreDocument, PBScoreDocument } from "kamaitachi-common";
import { Random20Hex } from "../../../../../utils/misc";
import deepmerge from "deepmerge";
const gazerChart = GetKTDataJSON("./kamaitachi/bms-gazer-chart.json");
const pbScore = ({
composedFrom: {
lampPB: "mock_lampPB",
},
scoreData: {
lampIndex: 4,
score: 1234,
hitMeta: {},
},
playtype: "7K",
scoreMeta: {},
chartID: gazerChart.chartID,
userID: 1,
} as unknown) as PBScoreDocument<"bms:7K" | "bms:14K">;
t.test("#KtchiPBScoreToBeatorajaFormat", (t) => {
t.beforeEach(ResetDBState);
t.beforeEach(async () => {
await db.scores.insert(
[1, 2, 3, 4, 5].map(() => ({
userID: 1,
chartID: gazerChart.chartID,
scoreID: Random20Hex(),
})) as ScoreDocument[]
);
await db.scores.insert({
scoreID: "mock_lampPB",
scoreData: {
hitMeta: {},
},
scoreMeta: {
inputDevice: "KEYBOARD",
},
} as ScoreDocument);
});
t.test("Should convert score.", async (t) => {
const res = await KtchiPBScoreToBeatorajaFormat(pbScore, gazerChart, 1);
t.strictSame(
res,
{
sha256: "195fe1be5c3e74fccd04dc426e05f8a9cfa8a1059c339d0a23e99f63661f0b7d",
player: "",
playcount: 5,
clear: 5,
date: 0,
maxcombo: 0,
deviceType: "KEYBOARD",
gauge: 0,
random: 0,
passnotes: 2256,
minbp: 0,
notes: 2256,
},
"Should return the beatoraja score format."
);
t.end();
});
t.test("Should emplace username if requestingUserID is not the pbscore owner", async (t) => {
const res = await KtchiPBScoreToBeatorajaFormat(pbScore, gazerChart, 2);
t.strictSame(
res,
{
sha256: "195fe1be5c3e74fccd04dc426e05f8a9cfa8a1059c339d0a23e99f63661f0b7d",
player: "test_zkldi",
playcount: 5,
clear: 5,
date: 0,
maxcombo: 0,
deviceType: "KEYBOARD",
gauge: 0,
random: 0,
passnotes: 2256,
minbp: 0,
notes: 2256,
},
"Should return the beatoraja score format."
);
t.end();
});
t.test("Should return random if one is present", async (t) => {
await db.scores.remove({ scoreID: "mock_lampPB" });
await db.scores.insert({
scoreID: "mock_lampPB",
scoreData: {
hitMeta: {},
},
scoreMeta: {
inputDevice: "KEYBOARD",
random: "RANDOM",
},
} as ScoreDocument);
const res = await KtchiPBScoreToBeatorajaFormat(pbScore, gazerChart, 2);
t.strictSame(
res,
{
sha256: "195fe1be5c3e74fccd04dc426e05f8a9cfa8a1059c339d0a23e99f63661f0b7d",
player: "test_zkldi",
playcount: 5,
clear: 5,
date: 0,
maxcombo: 0,
deviceType: "KEYBOARD",
gauge: 0,
random: 2,
passnotes: 2256,
minbp: 0,
notes: 2256,
},
"Should return the beatoraja score format."
);
t.end();
});
t.test("Should skip random if score is 14K", async (t) => {
await db.scores.remove({ scoreID: "mock_lampPB" });
await db.scores.insert({
scoreID: "mock_lampPB",
scoreData: {
hitMeta: {},
},
scoreMeta: {
inputDevice: "KEYBOARD",
random: "RANDOM",
},
} as ScoreDocument);
const res = await KtchiPBScoreToBeatorajaFormat(
deepmerge(pbScore, { playtype: "14K" }),
gazerChart,
2
);
t.strictSame(
res,
{
sha256: "195fe1be5c3e74fccd04dc426e05f8a9cfa8a1059c339d0a23e99f63661f0b7d",
player: "test_zkldi",
playcount: 5,
clear: 5,
date: 0,
maxcombo: 0,
deviceType: "KEYBOARD",
gauge: 0,
random: 0,
passnotes: 2256,
minbp: 0,
notes: 2256,
},
"Should return the beatoraja score format."
);
t.end();
});
t.test("Should throw severe if no lampPB exists.", async (t) => {
await db.scores.remove({ scoreID: "mock_lampPB" });
t.rejects(() => KtchiPBScoreToBeatorajaFormat(pbScore, gazerChart, 2), {
message: /User's PB on.*has no lampPB/u,
} as any);
t.end();
});
t.todo("#KtchiPBScoreToBeatorajaFormat", (t) => {
t.end();
});
t.teardown(CloseMongoConnection);
@@ -62,7 +62,9 @@ export async function KtchiPBScoreToBeatorajaFormat(
logger.severe(
`User ${pbScore.userID}'s PB on ${chart.chartID} has no lampPB, but references ${pbScore.composedFrom.lampPB}.`
);
throw new Error();
throw new Error(
`User ${pbScore.userID}'s PB on ${chart.chartID} has no lampPB, but references ${pbScore.composedFrom.lampPB}.`
);
}
return KtchiScoreDataToBeatorajaFormat(
@@ -98,7 +100,7 @@ function KtchiScoreDataToBeatorajaFormat(
) {
const scoreData = pbScore.scoreData;
let rajaRandom = null;
let rajaRandom = 0 as const;
// @todo #138 Investigate how beatoraja handles DP randoms - for now, we just skip them.
if (pbScore.playtype === "7K") {