Some last tests

This commit is contained in:
zkldi
2022-01-19 22:44:12 +00:00
parent ae5d5bc9f5
commit 77c516a4d2
8 changed files with 284 additions and 25 deletions
+4 -1
View File
@@ -97,7 +97,10 @@ const staticIndexes: Partial<Record<Databases, Index[]>> = {
"charts-wacca": [index({ isHot: 1 })],
"charts-usc": [index({ "data.hashSHA1": 1, playtype: 1 }, UNIQUE)],
"charts-jubeat": [index({ "data.inGameID": 1, difficulty: 1 }, UNIQUE)],
"charts-pms": [index({ "data.hashSHA256": 1 }, UNIQUE), index({ "data.hashMD5": 1 }, UNIQUE)],
"charts-pms": [
index({ "data.hashSHA256": 1, playtype: 1 }, UNIQUE),
index({ "data.hashMD5": 1, playtype: 1 }, UNIQUE),
],
};
const indexes: Partial<Record<Databases, Index[]>> = staticIndexes;
@@ -144,7 +144,7 @@ export const ConverterIRBeatoraja: ConverterFunction<BeatorajaScore, BeatorajaCo
const game = context.chart.mode === "POPN_9K" ? "pms" : "bms";
let chart;
let chart: ChartDocument<"bms:14K" | "bms:7K" | "pms:Controller" | "pms:Keyboard"> | null;
if (game === "bms") {
chart = (await FindChartOnSHA256(game, data.sha256)) as ChartDocument<
@@ -76,11 +76,11 @@ const SUPPORTED_BMS_CLIENTS = [
];
const SUPPORTED_PMS_CLIENTS = [
"Beatoraja 0.8.4",
"Beatoraja 0.8.3",
"Beatoraja 0.8.2",
"Beatoraja 0.8.1",
"Beatoraja 0.8.0",
"beatoraja 0.8.4",
"beatoraja 0.8.3",
"beatoraja 0.8.2",
"beatoraja 0.8.1",
"beatoraja 0.8.0",
];
export function ParseBeatorajaSingle(
@@ -20,20 +20,22 @@ t.test("POST /ir/beatoraja/submit-score", (t) => {
})
);
const scoreReq = GetKTDataJSON("./beatoraja/base.json");
const bmsScoreReq = GetKTDataJSON("./beatoraja/base.json");
const pmsScoreReq = GetKTDataJSON("./beatoraja/pms-base.json");
t.test("Should import a valid score.", async (t) => {
t.test("Should import a valid BMS score.", async (t) => {
const res = await mockApi
.post("/ir/beatoraja/submit-score")
.set("X-TachiIR-Version", "v2.0.0")
.set("Authorization", "Bearer mock_token")
.send(scoreReq);
.send(bmsScoreReq);
t.equal(res.status, 200);
t.equal(res.body.success, true);
t.hasStrict(res.body.body, {
score: {
game: "bms",
scoreData: {
score: 1004,
},
@@ -54,6 +56,85 @@ t.test("POST /ir/beatoraja/submit-score", (t) => {
t.not(score, null);
t.hasStrict(res.body.body.score, score);
t.hasStrict(res.body.body.score, score);
t.end();
});
t.test("Should import a valid PMS score.", async (t) => {
const res = await mockApi
.post("/ir/beatoraja/submit-score")
.set("X-TachiIR-Version", "v2.0.0")
.set("Authorization", "Bearer mock_token")
.send(pmsScoreReq);
t.equal(res.status, 200);
t.equal(res.body.success, true);
t.hasStrict(res.body.body, {
score: {
game: "pms",
playtype: "Controller",
scoreData: {
score: 1004,
},
importType: "ir/beatoraja",
},
chart: {
chartID: "0446f1b54e90d631ff9fe98419ebaea9481fab1f",
},
song: {
id: 1,
},
});
const score = await db.scores.findOne(
{ scoreID: res.body.body.score.scoreID },
{ projection: { _id: 0 } }
);
t.not(score, null);
t.hasStrict(res.body.body.score, score);
t.end();
});
t.test("Should infer playtype from the PMS score.", async (t) => {
const res = await mockApi
.post("/ir/beatoraja/submit-score")
.set("X-TachiIR-Version", "v2.0.0")
.set("Authorization", "Bearer mock_token")
.send(deepmerge(pmsScoreReq, { score: { deviceType: "KEYBOARD" } }));
t.equal(res.status, 200);
t.equal(res.body.success, true);
t.hasStrict(res.body.body, {
score: {
game: "pms",
playtype: "Keyboard",
scoreData: {
score: 1004,
},
importType: "ir/beatoraja",
},
chart: {
chartID: "ca553d77cbf8b3e9e7709dad6123ffed1695a1dd",
},
song: {
id: 1,
},
});
const score = await db.scores.findOne(
{ scoreID: res.body.body.score.scoreID },
{ projection: { _id: 0 } }
);
t.not(score, null);
t.hasStrict(res.body.body.score, score);
t.end();
@@ -64,7 +145,7 @@ t.test("POST /ir/beatoraja/submit-score", (t) => {
.post("/ir/beatoraja/submit-score")
.set("X-TachiIR-Version", "v2.0.0")
.set("Authorization", "Bearer mock_token")
.send(deepmerge(scoreReq, { client: "INVALID" }));
.send(deepmerge(bmsScoreReq, { client: "INVALID" }));
t.equal(res.status, 400);
@@ -74,12 +155,42 @@ t.test("POST /ir/beatoraja/submit-score", (t) => {
t.end();
});
t.test("Should return an error if BMS scores try to use beatoraja.", async (t) => {
const res = await mockApi
.post("/ir/beatoraja/submit-score")
.set("X-TachiIR-Version", "v2.0.0")
.set("Authorization", "Bearer mock_token")
.send(deepmerge(bmsScoreReq, { client: "beatoraja 0.8.0" }));
t.equal(res.status, 400);
t.equal(res.body.success, false);
t.match(res.body.description, /Unsupported BMS client/u);
t.end();
});
t.test("Should return an error if PMS scores try to use lr2oraja.", async (t) => {
const res = await mockApi
.post("/ir/beatoraja/submit-score")
.set("X-TachiIR-Version", "v2.0.0")
.set("Authorization", "Bearer mock_token")
.send(deepmerge(pmsScoreReq, { client: "LR2oraja 0.8.0" }));
t.equal(res.status, 400);
t.equal(res.body.success, false);
t.match(res.body.description, /Unsupported PMS client/u);
t.end();
});
t.test("Should return an error if invalid score.", async (t) => {
const res = await mockApi
.post("/ir/beatoraja/submit-score")
.set("X-TachiIR-Version", "v2.0.0")
.set("Authorization", "Bearer mock_token")
.send(deepmerge(scoreReq, { score: { exscore: -1 } }));
.send(deepmerge(bmsScoreReq, { score: { exscore: -1 } }));
t.equal(res.status, 400);
@@ -94,7 +205,7 @@ t.test("POST /ir/beatoraja/submit-score", (t) => {
.post("/ir/beatoraja/submit-score")
.set("X-TachiIR-Version", "v2.0.0")
.set("Authorization", "Bearer mock_token")
.send(deepmerge(scoreReq, { chart: { title: null } }));
.send(deepmerge(bmsScoreReq, { chart: { title: null } }));
t.equal(res.status, 400);
@@ -110,7 +221,7 @@ t.test("POST /ir/beatoraja/submit-score", (t) => {
.set("X-TachiIR-Version", "v2.0.0")
.set("Authorization", "Bearer mock_token")
.send(
deepmerge(scoreReq, {
deepmerge(bmsScoreReq, {
chart: { sha256: "new_chart", md5: "new_md5" },
score: { sha256: "new_chart", md5: "new_md5" },
})
@@ -171,7 +282,7 @@ t.test("POST /ir/beatoraja/submit-score", (t) => {
.set("X-TachiIR-Version", "v2.0.0")
.set("Authorization", "Bearer mock_token")
.send(
deepmerge(scoreReq, {
deepmerge(bmsScoreReq, {
chart: { sha256: "new_chart", md5: "new_md5" },
score: { sha256: "new_chart", md5: "new_md5" },
})
@@ -184,7 +295,7 @@ t.test("POST /ir/beatoraja/submit-score", (t) => {
.set("X-TachiIR-Version", "v2.0.0")
.set("Authorization", "Bearer token2")
.send(
deepmerge(scoreReq, {
deepmerge(bmsScoreReq, {
chart: { sha256: "new_chart", md5: "new_md5" },
score: { sha256: "new_chart", md5: "new_md5" },
})
@@ -203,7 +314,7 @@ t.test("POST /ir/beatoraja/submit-score", (t) => {
.set("X-TachiIR-Version", "v2.0.0")
.set("Authorization", "Bearer token3")
.send(
deepmerge(scoreReq, {
deepmerge(bmsScoreReq, {
chart: { sha256: "new_chart", md5: "new_md5" },
score: { sha256: "new_chart", md5: "new_md5" },
})
@@ -236,7 +347,7 @@ t.test("POST /ir/beatoraja/submit-score", (t) => {
const res = await mockApi
.post("/ir/beatoraja/submit-score")
.set("X-TachiIR-Version", "v2.0.0")
.send(scoreReq);
.send(bmsScoreReq);
t.equal(res.status, 401);
@@ -249,7 +360,7 @@ t.test("POST /ir/beatoraja/submit-score", (t) => {
.set("X-TachiIR-Version", "v2.0.0")
.set("Authorization", "Bearer invalid_token")
.send(scoreReq);
.send(bmsScoreReq);
t.equal(res.status, 401);
@@ -74,13 +74,26 @@ router.post("/submit-score", RequireNotGuest, async (req, res) => {
});
}
const chart = await db.charts.bms.findOne({
chartID: scoreDoc.chartID,
});
let song;
let chart;
const song = await db.songs.bms.findOne({
id: chart!.songID,
});
if (importRes.body.body.game === "bms") {
chart = await db.charts.bms.findOne({
chartID: scoreDoc.chartID,
});
song = await db.songs.bms.findOne({
id: chart!.songID,
});
} else {
chart = await db.charts.pms.findOne({
chartID: scoreDoc.chartID,
});
song = await db.songs.pms.findOne({
id: chart!.songID,
});
}
return res.status(importRes.statusCode).json({
success: true,
@@ -0,0 +1,58 @@
[
{
"chartID": "0446f1b54e90d631ff9fe98419ebaea9481fab1f",
"data": {
"hashMD5": "d1253dd56bb2087d0b0d474f0d562aae",
"hashSHA256": "a10193f7ae05ce839292dc716f182fda0b1cc6ac5382c2056f37e22ffba87b7d",
"notecount": 1065,
"tableFolders": [
{
"table": "P●",
"level": "1"
}
]
},
"level": "?",
"levelNum": 0,
"playtype": "Controller",
"rgcID": null,
"songID": 1,
"tierlistInfo": {
"sgl-EC": {
"value": 46
},
"sgl-HC": {
"value": 46
}
},
"versions": []
},
{
"chartID": "ca553d77cbf8b3e9e7709dad6123ffed1695a1dd",
"data": {
"hashMD5": "d1253dd56bb2087d0b0d474f0d562aae",
"hashSHA256": "a10193f7ae05ce839292dc716f182fda0b1cc6ac5382c2056f37e22ffba87b7d",
"notecount": 1065,
"tableFolders": [
{
"table": "P●",
"level": "1"
}
]
},
"level": "?",
"levelNum": 0,
"playtype": "Keyboard",
"rgcID": null,
"songID": 1,
"tierlistInfo": {
"sgl-EC": {
"value": 46
},
"sgl-HC": {
"value": 46
}
},
"versions": []
}
]
@@ -0,0 +1,14 @@
[
{
"altTitles": [],
"artist": "Rocky",
"data": {
"genre": null,
"subartist": null,
"subtitle": null
},
"id": 1,
"searchTerms": [],
"title": "Annihilate the living"
}
]
@@ -0,0 +1,60 @@
{
"chart": {
"md5": "d1253dd56bb2087d0b0d474f0d562aae",
"sha256": "a10193f7ae05ce839292dc716f182fda0b1cc6ac5382c2056f37e22ffba87b7d",
"title": "GPMSAZER [MANIAQ]",
"subtitle": "",
"genre": "Annihilate the living",
"artist": "Rocky",
"subartist": "",
"url": "",
"appendurl": "",
"level": 8,
"total": 220,
"mode": "POPN_9K",
"lntype": 0,
"judge": 100,
"minbpm": 135,
"maxbpm": 135,
"notes": 568,
"hasUndefinedLN": false,
"hasLN": false,
"hasCN": false,
"hasHCN": false,
"hasMine": false,
"hasRandom": false,
"hasStop": false,
"values": {}
},
"score": {
"sha256": "a10193f7ae05ce839292dc716f182fda0b1cc6ac5382c2056f37e22ffba87b7d",
"lntype": 0,
"player": "unknown",
"clear": "Easy",
"date": 0,
"epg": 332,
"lpg": 127,
"egr": 65,
"lgr": 21,
"egd": 2,
"lgd": 2,
"ebd": 1,
"lbd": 0,
"epr": 7,
"lpr": 11,
"ems": 1,
"lms": 0,
"maxcombo": 223,
"notes": 568,
"passnotes": 568,
"minbp": 20,
"option": 2,
"assist": 0,
"gauge": -1,
"deviceType": "BM_CONTROLLER",
"judgeAlgorithm": "Combo",
"rule": "LR2",
"exscore": 1004
},
"client": "beatoraja 0.8.0"
}