fix everything

This commit is contained in:
zkldi
2021-06-20 20:43:19 +01:00
parent f4c32aa201
commit 650e0bf65a
12 changed files with 104 additions and 110 deletions
-1
View File
@@ -65,7 +65,6 @@
"default-param-last": "error",
"no-new-func": "error",
"arrow-body-style": "error",
// "arrow-parens": ["error", "as-needed"] prettier hates this
"no-useless-constructor": "error",
"no-duplicate-imports": "error",
"dot-notation": "error",
+11 -6
View File
@@ -13,6 +13,7 @@ import {
} from "../../test-utils/test-data";
import { CreateFolderChartLookup } from "../../utils/folder";
import { CloseAllConnections } from "../../test-utils/close-connections";
import { Random20Hex } from "../../utils/misc";
const logger = CreateLogCtx(__filename);
@@ -208,17 +209,21 @@ t.test("#EvaluateGoalForUser", (t) => {
delete Testing511SPA._id;
await db.charts.iidx.insert([
// @ts-expect-error ???
deepmerge(Testing511SPA, {
songID: 123,
level: "9",
chartID: "not_sp10",
data: {
arcChartID: Random20Hex(),
},
}),
// @ts-expect-error ???
deepmerge(Testing511SPA, {
songID: 124,
level: "10",
chartID: "other_sp10",
data: {
arcChartID: Random20Hex(),
},
}),
]);
@@ -298,10 +303,10 @@ t.test("#EvaluateGoalForUser", (t) => {
});
t.test("#HumaniseGoalProgress", (t) => {
t.equal(HumaniseGoalProgress("iidx", "scoreData.gradeIndex", 4, null), "B");
t.equal(HumaniseGoalProgress("iidx", "scoreData.lampIndex", 4, null), "CLEAR");
t.equal(HumaniseGoalProgress("iidx", "scoreData.percent", 90.1142, null), "90.11%");
t.equal(HumaniseGoalProgress("iidx", "scoreData.score", 2240, null), "2240");
t.equal(HumaniseGoalProgress("iidx", "SP", "scoreData.gradeIndex", 4, null), "B");
t.equal(HumaniseGoalProgress("iidx", "SP", "scoreData.lampIndex", 4, null), "CLEAR");
t.equal(HumaniseGoalProgress("iidx", "SP", "scoreData.percent", 90.1142, null), "90.11%");
t.equal(HumaniseGoalProgress("iidx", "SP", "scoreData.score", 2240, null), "2240");
t.end();
});
@@ -347,43 +347,43 @@ t.test("#CalculateDataForGamePT", (t) => {
t.end();
});
t.test("jubeat:Single", async (t) => {
const res = await CalculateDataForGamePT(
"jubeat",
"Single",
Testing511SPA,
TestingIIDXSPDryScore, // fake! this is an iidx score. but we're testing
null,
defaultTierlistID,
logger
);
// t.test("jubeat:Single", async (t) => {
// const res = await CalculateDataForGamePT(
// "jubeat",
// "Single",
// Testing511SPA,
// TestingIIDXSPDryScore, // fake! this is an iidx score. but we're testing
// null,
// defaultTierlistID,
// logger
// );
prAssert(
res,
{
jubility: "?number",
},
"Response should contain nulled keys for jubeat:Single"
);
// prAssert(
// res,
// {
// jubility: "?number",
// },
// "Response should contain nulled keys for jubeat:Single"
// );
t.end();
});
// t.end();
// });
t.test("popn:9B", async (t) => {
const res = await CalculateDataForGamePT(
"popn",
"9B",
Testing511SPA,
TestingIIDXSPDryScore, // fake! this is an iidx score. but we're testing
null,
defaultTierlistID,
logger
);
// t.test("popn:9B", async (t) => {
// const res = await CalculateDataForGamePT(
// "popn",
// "9B",
// Testing511SPA,
// TestingIIDXSPDryScore, // fake! this is an iidx score. but we're testing
// null,
// defaultTierlistID,
// logger
// );
prAssert(res, {}, "Response should contain nulled keys for popn:9B");
// prAssert(res, {}, "Response should contain nulled keys for popn:9B");
t.end();
});
// t.end();
// });
t.end();
});
@@ -16,11 +16,15 @@ const batchManualScore: BatchManualScore = {
lamp: "HARD CLEAR",
matchType: "songTitle",
identifier: "5.1.1.",
playtype: "SP",
difficulty: "ANOTHER",
};
const batchManualContext: BatchManualContext = { game: "iidx", service: "foo", version: "27" };
const batchManualContext: BatchManualContext = {
game: "iidx",
playtype: "SP",
service: "foo",
version: "27",
};
t.test("#OrphanScore", (t) => {
t.beforeEach(ResetDBState);
@@ -9,14 +9,6 @@ const logger = CreateLogCtx(__filename);
t.test("#CalculateRatings", (t) => {
t.beforeEach(ResetDBState);
t.test("Should work for games with no custom ratings", async (t) => {
const res = await CalculateRatings("popn", "9B", 1, logger);
t.strictSame(res, {}, "Should return an empty object.");
t.end();
});
t.test("Should return BPI for IIDX", async (t) => {
const res = await CalculateRatings("iidx", "SP", 1, logger);
@@ -20,6 +20,7 @@ const baseBatchManualScore = {
const context = {
game: "iidx" as const,
playtype: "SP" as const,
service: "foo",
version: null,
};
@@ -105,7 +106,7 @@ t.test("#ResolveMatchTypeToKTData", (t) => {
const gazerSong = GetKTDataJSON("./tachi/bms-gazer-song.json");
const gazerChart = GetKTDataJSON("./tachi/bms-gazer-chart.json");
const bmsContext: any = deepmerge(context, { game: "bms" });
const bmsContext: any = deepmerge(context, { game: "bms", playtype: "7K" });
const resMD5 = await ResolveMatchTypeToKTData(
deepmerge(baseBatchManualScore, {
@@ -244,7 +245,7 @@ t.test("#ResolveChartFromSong", (t) => {
const res = await ResolveChartFromSong(
Testing511Song,
baseBatchManualScore, // has playtype + diff
{ game: "iidx", service: "foo", version: null },
{ game: "iidx", service: "foo", playtype: "SP", version: null },
importType
);
@@ -253,30 +254,13 @@ t.test("#ResolveChartFromSong", (t) => {
t.end();
});
t.test("Should throw an error if no playtype is provided.", (t) => {
t.rejects(
() =>
ResolveChartFromSong(
Testing511Song,
deepmerge(baseBatchManualScore, { playtype: null }),
{ game: "iidx", service: "foo", version: null },
importType
),
new InvalidScoreFailure(
`Missing 'playtype' field, but was necessary for this lookup.`
) as any
);
t.end();
});
t.test("Should throw an error if no difficulty is provided.", (t) => {
t.rejects(
() =>
ResolveChartFromSong(
Testing511Song,
deepmerge(baseBatchManualScore, { difficulty: null }),
{ game: "iidx", service: "foo", version: null },
{ game: "iidx", service: "foo", playtype: "SP", version: null },
importType
),
new InvalidScoreFailure(
@@ -294,7 +278,7 @@ t.test("#ResolveChartFromSong", (t) => {
Testing511Song,
// @ts-expect-error faulty deepmerge types
deepmerge(baseBatchManualScore, { difficulty: "NOT_VALID_DIFFICULTY" }),
{ game: "iidx", service: "foo", version: null },
{ game: "iidx", service: "foo", playtype: "SP", version: null },
importType
),
new InvalidScoreFailure(
@@ -312,7 +296,7 @@ t.test("#ResolveChartFromSong", (t) => {
Testing511Song,
// @ts-expect-error faulty deepmerge types
deepmerge(baseBatchManualScore, { difficulty: "LEGGENDARIA" }), // 511 has no legg (yet, lol)
{ game: "iidx", service: "foo", version: null },
{ game: "iidx", service: "foo", version: null, playtype: "SP" },
importType
),
ktdWrap("Cannot find chart for 5.1.1. (SP LEGGENDARIA)")
@@ -328,6 +312,7 @@ t.test("#ResolveChartFromSong", (t) => {
{
game: "iidx",
service: "foo",
playtype: "SP",
version: "27",
},
importType
@@ -345,7 +330,7 @@ t.test("#ConverterFn", (t) => {
t.test("Should produce a DryScore", async (t) => {
const res = await ConverterBatchManual(
baseBatchManualScore,
{ game: "iidx", service: "foo", version: null },
{ game: "iidx", service: "foo", playtype: "SP", version: null },
importType,
logger
);
@@ -380,7 +365,7 @@ t.test("#ConverterFn", (t) => {
ConverterBatchManual(
// @ts-expect-error broken deepmerge
deepmerge(baseBatchManualScore, { score: 2000 }),
{ game: "iidx", service: "foo", version: null },
{ game: "iidx", service: "foo", playtype: "SP", version: null },
importType,
logger
),
@@ -18,7 +18,7 @@ const logger = CreateLogCtx(__filename);
const baseBatchManual = {
body: [],
head: { service: "foo", game: "iidx" },
head: { service: "foo", game: "iidx", playtype: "SP" },
};
const baseBatchManualScore = {
@@ -26,7 +26,6 @@ const baseBatchManualScore = {
lamp: "HARD CLEAR",
matchType: "songID",
identifier: "123",
playtype: "SP",
difficulty: "ANOTHER",
};
@@ -68,7 +67,12 @@ t.test("#ParserFn", (t) => {
t.test("No Game", (t) => {
t.throws(
() => ParserFn({ body: [], head: { service: "foo" } }, "file/batch-manual", logger),
() =>
ParserFn(
{ body: [], head: { service: "foo", playtype: "SP" } },
"file/batch-manual",
logger
),
new ScoreImportFatalError(
400,
"Could not retrieve head.game - is this valid BATCH-MANUAL?"
@@ -79,11 +83,29 @@ t.test("#ParserFn", (t) => {
t.end();
});
t.test("No Playtype", (t) => {
t.throws(
() =>
ParserFn(
{ body: [], head: { service: "foo", game: "iidx" } },
"file/batch-manual",
logger
),
new ScoreImportFatalError(
400,
"Could not retrieve head.playtype - is this valid BATCH-MANUAL?"
),
"Should throw an error."
);
t.end();
});
t.test("Invalid Game", (t) => {
t.throws(
() =>
ParserFn(
{ body: [], head: { service: "foo", game: "invalid_game" } },
{ body: [], head: { service: "foo", game: "invalid_game", playtype: "SP" } },
"file/batch-manual",
logger
),
@@ -93,7 +115,7 @@ t.test("#ParserFn", (t) => {
t.throws(
() =>
ParserFn(
{ body: [], head: { service: "foo", game: 123 } },
{ body: [], head: { service: "foo", game: 123, playtype: "SP" } },
"file/batch-manual",
logger
),
@@ -107,7 +129,7 @@ t.test("#ParserFn", (t) => {
t.throws(
() =>
ParserFn(
{ body: [], head: { service: "1", game: "iidx" } },
{ body: [], head: { service: "1", game: "iidx", playtype: "SP" } },
"file/batch-manual",
logger
),
@@ -121,7 +143,7 @@ t.test("#ParserFn", (t) => {
t.throws(
() =>
ParserFn(
{ body: [], head: { service: 1, game: "iidx" } },
{ body: [], head: { service: 1, game: "iidx", playtype: "SP" } },
"file/batch-manual",
logger
),
@@ -137,7 +159,7 @@ t.test("#ParserFn", (t) => {
t.test("Valid Empty BATCH-MANUAL", (t) => {
const res = ParserFn(
{ body: [], head: { service: "foo", game: "iidx" } },
{ body: [], head: { service: "foo", game: "iidx", playtype: "SP" } },
"file/batch-manual",
logger
);
@@ -165,7 +187,6 @@ t.test("#ParserFn", (t) => {
lamp: "HARD CLEAR",
matchType: "songID",
identifier: "123",
playtype: "SP",
difficulty: "ANOTHER",
},
{
@@ -173,7 +194,6 @@ t.test("#ParserFn", (t) => {
lamp: "HARD CLEAR",
matchType: "kamaitachiSongID",
identifier: "123",
playtype: "DP",
difficulty: "HYPER",
},
{
@@ -189,7 +209,7 @@ t.test("#ParserFn", (t) => {
identifier: "5.1.1.",
},
],
head: { service: "foo", game: "iidx" },
head: { service: "foo", game: "iidx", playtype: "SP" },
} as BatchManual,
"file/batch-manual",
logger
@@ -200,6 +220,7 @@ t.test("#ParserFn", (t) => {
context: {
service: "foo",
game: "iidx",
playtype: "SP",
version: null,
},
iterable: [
@@ -208,7 +229,6 @@ t.test("#ParserFn", (t) => {
lamp: "HARD CLEAR",
matchType: "songID",
identifier: "123",
playtype: "SP",
difficulty: "ANOTHER",
},
{
@@ -216,7 +236,6 @@ t.test("#ParserFn", (t) => {
lamp: "HARD CLEAR",
matchType: "kamaitachiSongID",
identifier: "123",
playtype: "DP",
difficulty: "HYPER",
},
{
@@ -249,6 +268,7 @@ t.test("#ParserFn", (t) => {
context: {
service: "foo",
game: "iidx",
playtype: "SP",
version: null,
},
iterable: [
@@ -257,7 +277,6 @@ t.test("#ParserFn", (t) => {
lamp: "HARD CLEAR",
matchType: "songID",
identifier: "123",
playtype: "SP",
difficulty: "ANOTHER",
hitMeta: {
bp: 10,
@@ -284,6 +303,7 @@ t.test("#ParserFn", (t) => {
context: {
service: "foo",
game: "iidx",
playtype: "SP",
version: null,
},
iterable: [
@@ -292,7 +312,6 @@ t.test("#ParserFn", (t) => {
lamp: "HARD CLEAR",
matchType: "songID",
identifier: "123",
playtype: "SP",
difficulty: "ANOTHER",
judgements: {
pgreat: 1,
@@ -320,11 +339,10 @@ t.test("#ParserFn", (t) => {
lamp: "ALL JUSTICE", // not an iidx lamp
matchType: "songID",
identifier: "123",
playtype: "SP",
difficulty: "ANOTHER",
},
],
head: { service: "foo", game: "iidx" },
head: { service: "foo", game: "iidx", playtype: "SP" },
},
"file/batch-manual",
logger
@@ -385,21 +403,6 @@ t.test("#ParserFn", (t) => {
t.end();
});
t.test("Invalid Playtype", (t) => {
// this is not a valid playtype for IIDX
const fn = () => ParserFn(dm({ playtype: "Single" }), "file/batch-manual", logger);
t.throws(
fn,
new ScoreImportFatalError(
400,
"Invalid BATCH-MANUAL: body[0].playtype | Expected any of SP, DP. | Received Single [string]."
)
);
t.end();
});
t.test("Invalid Identifier", (t) => {
// this is not a valid playtype for IIDX
const fn = () => ParserFn(dm({ identifier: null }), "file/batch-manual", logger);
@@ -139,13 +139,20 @@ export function ParseBatchManualFromObject(
// @ts-expect-error man.
const possiblyPlaytype = object?.head?.playtype;
if (!possiblyGame || !possiblyPlaytype) {
if (!possiblyGame) {
throw new ScoreImportFatalError(
400,
`Could not retrieve head.game - is this valid BATCH-MANUAL?`
);
}
if (!possiblyPlaytype) {
throw new ScoreImportFatalError(
400,
`Could not retrieve head.playtype - is this valid BATCH-MANUAL?`
);
}
if (!CONF_INFO.supportedGames.includes(possiblyGame)) {
throw new ScoreImportFatalError(
400,
@@ -8,8 +8,6 @@ import { GetKTDataJSON } from "../../../../test-utils/test-data";
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function TestHeaders(url: string, data: any) {
t.beforeEach(InsertFakeTokenWithAllPerms("mock_token"));
t.test("Should reject invalid X-Software-Models", async (t) => {
let res = await mockApi
.post(url)
@@ -1,6 +1,7 @@
{
"head": {
"game": "chunithm",
"playtype": "Single",
"service": "Chunitachi"
},
"body": [{
@@ -8,7 +9,6 @@
"lamp": "CLEAR",
"matchType": "songTitle",
"identifier": "B.B.K.K.B.K.K.",
"playtype": "Single",
"difficulty": "BASIC"
}]
}
@@ -1,6 +1,7 @@
{
"head": {
"game": "iidx",
"playtype": "SP",
"service": "foobar"
},
"body": []
@@ -1,6 +1,7 @@
{
"head": {
"game": "iidx",
"playtype": "SP",
"service": "foobar"
},
"body": [{
@@ -8,7 +9,6 @@
"lamp": "HARD CLEAR",
"matchType": "songTitle",
"identifier": "5.1.1.",
"playtype": "SP",
"difficulty": "ANOTHER"
}]
}