diff --git a/server/src/lib/score-import/import-types/converters.ts b/server/src/lib/score-import/import-types/converters.ts index fc3b375c3..7ef1ed9fb 100644 --- a/server/src/lib/score-import/import-types/converters.ts +++ b/server/src/lib/score-import/import-types/converters.ts @@ -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, }; diff --git a/server/src/server/router/ir/chunitachi/router.test.ts b/server/src/server/router/ir/chunitachi/router.test.ts deleted file mode 100644 index 8786ab3c4..000000000 --- a/server/src/server/router/ir/chunitachi/router.test.ts +++ /dev/null @@ -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(); -}); diff --git a/server/src/server/router/ir/chunitachi/router.ts b/server/src/server/router/ir/chunitachi/router.ts deleted file mode 100644 index 81e6b6668..000000000 --- a/server/src/server/router/ir/chunitachi/router.ts +++ /dev/null @@ -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; diff --git a/server/src/server/router/ir/direct-manual/router.test.ts b/server/src/server/router/ir/direct-manual/router.test.ts index c65598947..4e61c439d 100644 --- a/server/src/server/router/ir/direct-manual/router.test.ts +++ b/server/src/server/router/ir/direct-manual/router.test.ts @@ -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(); });