Remove ir/chunitachi as an import type.

This commit is contained in:
zkldi
2021-11-12 01:36:50 +00:00
parent c859903be5
commit a5fda8fced
4 changed files with 72 additions and 129 deletions
@@ -40,6 +40,5 @@ export const Converters: ConverterMap = {
"ir/fervidex-static": ConverterIRFervidexStatic,
"ir/direct-manual": ConverterBatchManual,
"ir/usc": ConverterIRUSC,
"ir/chunitachi": ConverterBatchManual,
"ir/kshook-sv3c": ConverterIRKsHookSV3C,
};
@@ -1,86 +0,0 @@
import t from "tap";
import db from "external/mongo/db";
import { InsertFakeTokenWithAllPerms } from "test-utils/fake-auth";
import mockApi from "test-utils/mock-api";
import ResetDBState from "test-utils/resets";
import { GetKTDataJSON } from "test-utils/test-data";
import deepmerge from "deepmerge";
t.test("POST /ir/chunitachi/import", (t) => {
t.beforeEach(ResetDBState);
t.beforeEach(InsertFakeTokenWithAllPerms("mock_token"));
const chunitachiBody = GetKTDataJSON("./batch-manual/chunitachi.json");
t.test("Should work for CHUNITACHI requests", async (t) => {
const res = await mockApi
.post("/ir/chunitachi/import")
.set("Authorization", `Bearer mock_token`)
.send(chunitachiBody);
t.equal(res.body.success, true, "Should be successful");
t.equal(res.body.body.errors.length, 0, "Should have 0 failed scores.");
const scoreCount = await db.scores.count({ service: "ChunItachi" });
t.equal(scoreCount, 1, "Should import one score.");
t.end();
});
t.test("Should reject invalid batch-manual", async (t) => {
const res = await mockApi
.post("/ir/chunitachi/import")
.set("Authorization", `Bearer mock_token`)
.send({});
t.equal(res.body.success, false, "Should not be successful");
t.end();
});
t.test("Should reject batch-manual requests if game is not chunithm", async (t) => {
const res = await mockApi
.post("/ir/chunitachi/import")
.set("Authorization", `Bearer mock_token`)
.send(deepmerge(chunitachiBody, { meta: { game: "iidx" } }));
t.equal(res.body.success, false, "Should not be successful");
t.end();
});
t.test("Should reject batch-manual requests if service is not Chunitachi", async (t) => {
const res = await mockApi
.post("/ir/chunitachi/import")
.set("Authorization", `Bearer mock_token`)
.send(deepmerge(chunitachiBody, { meta: { service: "foo bar" } }));
t.equal(res.body.success, false, "Should not be successful");
t.end();
});
t.test("Should require authentication.", async (t) => {
const res = await mockApi.post("/ir/chunitachi/import").send(chunitachiBody);
t.equal(res.statusCode, 401);
t.end();
});
t.test("Should require a valid auth token.", async (t) => {
const res = await mockApi
.post("/ir/chunitachi/import")
.set("Authorization", "Bearer invalid_token")
.send(chunitachiBody);
t.equal(res.statusCode, 401);
t.end();
});
t.end();
});
@@ -1,41 +0,0 @@
import { Router } from "express";
import { GetUserWithIDGuaranteed } from "utils/user";
import { ExpressWrappedScoreImportMain } from "lib/score-import/framework/express-wrapper";
import ParseDirectManual from "lib/score-import/import-types/ir/direct-manual/parser";
import { RequirePermissions } from "server/middleware/auth";
import { SYMBOL_TachiAPIAuth } from "lib/constants/tachi";
const router: Router = Router({ mergeParams: true });
/**
* Submits a single score document from Chunitachi clients.
* @name POST /ir/chunitachi/import
*/
router.post("/import", RequirePermissions("submit_score"), async (req, res) => {
const userDoc = await GetUserWithIDGuaranteed(req[SYMBOL_TachiAPIAuth].userID!);
if (req.body?.meta?.game !== "chunithm") {
return res.status(400).json({
success: false,
description: `Invalid Game. Expected 'chunithm', but got ${req.body?.meta?.game}`,
});
}
if (req.body.meta.service !== "ChunItachi") {
return res.status(400).json({
success: false,
description: `Unexpected service ${req.body.head.service} -- expected 'Chunitachi'`,
});
}
const responseData = await ExpressWrappedScoreImportMain(
userDoc,
false,
"ir/chunitachi",
(logger) => ParseDirectManual(req.body, logger)
);
return res.status(responseData.statusCode).json(responseData.body);
});
export default router;
@@ -1,6 +1,6 @@
import t from "tap";
import db from "external/mongo/db";
import deepmerge from "deepmerge";
import { CreateFakeAuthCookie } from "test-utils/fake-auth";
import mockApi from "test-utils/mock-api";
import ResetDBState from "test-utils/resets";
@@ -78,5 +78,76 @@ t.test("POST /ir/direct-manual/import", async (t) => {
t.end();
});
const chunitachiBody = GetKTDataJSON("./batch-manual/chunitachi.json");
t.test("Should work for CHUNITACHI requests", async (t) => {
const res = await mockApi
.post("/ir/direct-manual/import")
.set("Authorization", `Bearer mock_token`)
.send(chunitachiBody);
t.equal(res.body.success, true, "Should be successful");
t.equal(res.body.body.errors.length, 0, "Should have 0 failed scores.");
const scoreCount = await db.scores.count({ service: "ChunItachi" });
t.equal(scoreCount, 1, "Should import one score.");
t.end();
});
t.test("Should reject invalid batch-manual", async (t) => {
const res = await mockApi
.post("/ir/direct-manual/import")
.set("Authorization", `Bearer mock_token`)
.send({});
t.equal(res.body.success, false, "Should not be successful");
t.end();
});
t.test("Should reject batch-manual requests if game is not chunithm", async (t) => {
const res = await mockApi
.post("/ir/direct-manual/import")
.set("Authorization", `Bearer mock_token`)
.send(deepmerge(chunitachiBody, { meta: { game: "iidx" } }));
t.equal(res.body.success, false, "Should not be successful");
t.end();
});
t.test("Should reject batch-manual requests if service is not Chunitachi", async (t) => {
const res = await mockApi
.post("/ir/direct-manual/import")
.set("Authorization", `Bearer mock_token`)
.send(deepmerge(chunitachiBody, { meta: { service: "foo bar" } }));
t.equal(res.body.success, false, "Should not be successful");
t.end();
});
t.test("Should require authentication.", async (t) => {
const res = await mockApi.post("/ir/direct-manual/import").send(chunitachiBody);
t.equal(res.statusCode, 401);
t.end();
});
t.test("Should require a valid auth token.", async (t) => {
const res = await mockApi
.post("/ir/direct-manual/import")
.set("Authorization", "Bearer invalid_token")
.send(chunitachiBody);
t.equal(res.statusCode, 401);
t.end();
});
t.end();
});