From 99a3d640283bbab7ebcb667bdda8a1c2419e2f6b Mon Sep 17 00:00:00 2001 From: zkldi Date: Wed, 21 Jul 2021 16:00:10 +0100 Subject: [PATCH] Rename Head to Meta and Body to Scores --- .../common/batch-manual/parser.test.ts | 30 +++++++++---------- .../common/batch-manual/parser.ts | 18 +++++------ .../import-types/common/batch-manual/types.ts | 4 +-- .../router/ir/chunitachi/router.test.ts | 4 +-- .../test-data/batch-manual/small-file.json | 4 +-- 5 files changed, 30 insertions(+), 30 deletions(-) diff --git a/server/src/lib/score-import/import-types/common/batch-manual/parser.test.ts b/server/src/lib/score-import/import-types/common/batch-manual/parser.test.ts index 7bc2114af..509768c32 100644 --- a/server/src/lib/score-import/import-types/common/batch-manual/parser.test.ts +++ b/server/src/lib/score-import/import-types/common/batch-manual/parser.test.ts @@ -17,8 +17,8 @@ const mockErr = (...msg: string[]) => const logger = CreateLogCtx(__filename); const baseBatchManual = { - body: [], - head: { service: "foo", game: "iidx", playtype: "SP" }, + scores: [], + meta: { service: "foo", game: "iidx", playtype: "SP" }, }; const baseBatchManualScore = { @@ -33,7 +33,7 @@ const baseBatchManualScore = { function dm(sc: any) { return deepmerge( baseBatchManual, - { body: [deepmerge(baseBatchManualScore, sc)] }, + { scores: [deepmerge(baseBatchManualScore, sc)] }, { arrayMerge: (r, c) => c } ); } @@ -54,7 +54,7 @@ t.test("#ParserFn", (t) => { t.test("No Header", (t) => { t.throws( - () => ParserFn({ body: [] }, "file/batch-manual", logger), + () => ParserFn({ scores: [] }, "file/batch-manual", logger), new ScoreImportFatalError( 400, "Could not retrieve head.game - is this valid BATCH-MANUAL?" @@ -69,7 +69,7 @@ t.test("#ParserFn", (t) => { t.throws( () => ParserFn( - { body: [], head: { service: "foo", playtype: "SP" } }, + { scores: [], meta: { service: "foo", playtype: "SP" } }, "file/batch-manual", logger ), @@ -87,7 +87,7 @@ t.test("#ParserFn", (t) => { t.throws( () => ParserFn( - { body: [], head: { service: "foo", game: "iidx" } }, + { scores: [], meta: { service: "foo", game: "iidx" } }, "file/batch-manual", logger ), @@ -105,7 +105,7 @@ t.test("#ParserFn", (t) => { t.throws( () => ParserFn( - { body: [], head: { service: "foo", game: "invalid_game", playtype: "SP" } }, + { scores: [], meta: { service: "foo", game: "invalid_game", playtype: "SP" } }, "file/batch-manual", logger ), @@ -115,7 +115,7 @@ t.test("#ParserFn", (t) => { t.throws( () => ParserFn( - { body: [], head: { service: "foo", game: 123, playtype: "SP" } }, + { scores: [], meta: { service: "foo", game: 123, playtype: "SP" } }, "file/batch-manual", logger ), @@ -129,7 +129,7 @@ t.test("#ParserFn", (t) => { t.throws( () => ParserFn( - { body: [], head: { service: "1", game: "iidx", playtype: "SP" } }, + { scores: [], meta: { service: "1", game: "iidx", playtype: "SP" } }, "file/batch-manual", logger ), @@ -143,7 +143,7 @@ t.test("#ParserFn", (t) => { t.throws( () => ParserFn( - { body: [], head: { service: 1, game: "iidx", playtype: "SP" } }, + { scores: [], meta: { service: 1, game: "iidx", playtype: "SP" } }, "file/batch-manual", logger ), @@ -159,7 +159,7 @@ t.test("#ParserFn", (t) => { t.test("Valid Empty BATCH-MANUAL", (t) => { const res = ParserFn( - { body: [], head: { service: "foo", game: "iidx", playtype: "SP" } }, + { scores: [], meta: { service: "foo", game: "iidx", playtype: "SP" } }, "file/batch-manual", logger ); @@ -181,7 +181,7 @@ t.test("#ParserFn", (t) => { t.test("Basic BATCH-MANUAL", (t) => { const res = ParserFn( { - body: [ + scores: [ { score: 1000, lamp: "HARD CLEAR", @@ -209,7 +209,7 @@ t.test("#ParserFn", (t) => { identifier: "5.1.1.", }, ], - head: { service: "foo", game: "iidx", playtype: "SP" }, + meta: { service: "foo", game: "iidx", playtype: "SP" }, } as BatchManual, "file/batch-manual", logger @@ -333,7 +333,7 @@ t.test("#ParserFn", (t) => { const fn = () => ParserFn( { - body: [ + scores: [ { score: 1000, lamp: "ALL JUSTICE", // not an iidx lamp @@ -342,7 +342,7 @@ t.test("#ParserFn", (t) => { difficulty: "ANOTHER", }, ], - head: { service: "foo", game: "iidx", playtype: "SP" }, + meta: { service: "foo", game: "iidx", playtype: "SP" }, }, "file/batch-manual", logger diff --git a/server/src/lib/score-import/import-types/common/batch-manual/parser.ts b/server/src/lib/score-import/import-types/common/batch-manual/parser.ts index 0e642999f..348536136 100644 --- a/server/src/lib/score-import/import-types/common/batch-manual/parser.ts +++ b/server/src/lib/score-import/import-types/common/batch-manual/parser.ts @@ -93,13 +93,13 @@ const PR_BatchManualScore = (game: Game, playtype: Playtypes[Game]): PrudenceSch }; const PR_BatchManual = (game: Game, playtype: Playtypes[Game]): PrudenceSchema => ({ - head: { + meta: { service: p.isBoundedString(3, 15), game: p.isIn(CONF_INFO.supportedGames), playtype: p.is(playtype), version: "*?string", }, - body: [PR_BatchManualScore(game, playtype)], + scores: [PR_BatchManualScore(game, playtype)], }); /** @@ -126,21 +126,21 @@ export function ParseBatchManualFromObject( // attempt to retrieve game // @ts-expect-error man. - const possiblyGame = object?.head?.game; + const possiblyGame = object?.meta?.game; // @ts-expect-error man. - const possiblyPlaytype = object?.head?.playtype; + const possiblyPlaytype = object?.meta?.playtype; if (!possiblyGame) { throw new ScoreImportFatalError( 400, - `Could not retrieve head.game - is this valid BATCH-MANUAL?` + `Could not retrieve meta.game - is this valid BATCH-MANUAL?` ); } if (!possiblyPlaytype) { throw new ScoreImportFatalError( 400, - `Could not retrieve head.playtype - is this valid BATCH-MANUAL?` + `Could not retrieve meta.playtype - is this valid BATCH-MANUAL?` ); } @@ -182,12 +182,12 @@ export function ParseBatchManualFromObject( return { game, context: { - service: batchManual.head.service, + service: batchManual.meta.service, game, playtype, - version: batchManual.head.version ?? null, + version: batchManual.meta.version ?? null, }, - iterable: batchManual.body, + iterable: batchManual.scores, classHandler: null, }; } diff --git a/server/src/lib/score-import/import-types/common/batch-manual/types.ts b/server/src/lib/score-import/import-types/common/batch-manual/types.ts index c2b8304dc..265c5c712 100644 --- a/server/src/lib/score-import/import-types/common/batch-manual/types.ts +++ b/server/src/lib/score-import/import-types/common/batch-manual/types.ts @@ -14,13 +14,13 @@ export type BatchManualScore = { }; export interface BatchManual { - head: { + meta: { service: string; game: Game; playtype: Playtypes[Game]; version?: string | null; }; - body: BatchManualScore[]; + scores: BatchManualScore[]; } export interface BatchManualContext { diff --git a/server/src/server/router/ir/chunitachi/router.test.ts b/server/src/server/router/ir/chunitachi/router.test.ts index a49f8cfbf..00cc772da 100644 --- a/server/src/server/router/ir/chunitachi/router.test.ts +++ b/server/src/server/router/ir/chunitachi/router.test.ts @@ -45,7 +45,7 @@ t.test("POST /ir/chunitachi/import", (t) => { const res = await mockApi .post("/ir/chunitachi/import") .set("Authorization", `Bearer mock_token`) - .send(deepmerge(chunitachiBody, { head: { game: "iidx" } })); + .send(deepmerge(chunitachiBody, { meta: { game: "iidx" } })); t.equal(res.body.success, false, "Should not be successful"); @@ -56,7 +56,7 @@ t.test("POST /ir/chunitachi/import", (t) => { const res = await mockApi .post("/ir/chunitachi/import") .set("Authorization", `Bearer mock_token`) - .send(deepmerge(chunitachiBody, { head: { service: "foo bar" } })); + .send(deepmerge(chunitachiBody, { meta: { service: "foo bar" } })); t.equal(res.body.success, false, "Should not be successful"); diff --git a/server/src/test-utils/test-data/batch-manual/small-file.json b/server/src/test-utils/test-data/batch-manual/small-file.json index 3b0c74b7c..7d54a890e 100644 --- a/server/src/test-utils/test-data/batch-manual/small-file.json +++ b/server/src/test-utils/test-data/batch-manual/small-file.json @@ -1,10 +1,10 @@ { - "head": { + "meta": { "game": "iidx", "playtype": "SP", "service": "foobar" }, - "body": [{ + "scores": [{ "score": 500, "lamp": "HARD CLEAR", "matchType": "songTitle",