Rename Head to Meta and Body to Scores

This commit is contained in:
zkldi
2021-07-21 16:00:10 +01:00
parent fcd68185f7
commit 99a3d64028
5 changed files with 30 additions and 30 deletions
@@ -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
@@ -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,
};
}
@@ -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 {
@@ -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");
@@ -1,10 +1,10 @@
{
"head": {
"meta": {
"game": "iidx",
"playtype": "SP",
"service": "foobar"
},
"body": [{
"scores": [{
"score": 500,
"lamp": "HARD CLEAR",
"matchType": "songTitle",