batch manual test

This commit is contained in:
zkldi
2021-05-11 21:18:06 +01:00
parent 085859cb75
commit 27a746e6fc
2 changed files with 190 additions and 2 deletions
+65 -1
View File
@@ -40,7 +40,7 @@ t.test("POST /internal-api/import/file", async (t) => {
.set("Cookie", cookie)
.attach(
"scoreData",
GetKTDataBuffer("./csv-eamusement-iidx/small-hv-file.csv"),
GetKTDataBuffer("./csv_eamusement-iidx/small-hv-file.csv"),
"my_csv.csv"
)
.field("importType", "file/csv:eamusement-iidx")
@@ -118,6 +118,70 @@ t.test("POST /internal-api/import/file", async (t) => {
t.end();
});
t.test("file/json:batch-manual", (t) => {
t.test("Empty import", async (t) => {
let res = await mockApi
.post("/internal-api/import/file")
.set("Cookie", cookie)
.attach(
"scoreData",
GetKTDataBuffer("./json_batch-manual/empty-file.json"),
"empty-file.json"
)
.field("importType", "file/json:batch-manual");
t.equal(res.body.success, true, "Should be successful.");
t.equal(res.body.body.errors.length, 0, "Import Should have 0 failed scores.");
t.equal(res.body.body.scoreIDs.length, 0, "Should have 0 successful scores.");
let scoreCount = await db.scores.find({
scoreID: { $in: res.body.body.scoreIDs },
});
t.equal(
scoreCount.length,
res.body.body.scoreIDs.length,
"All returned scoreIDs should be inserted to the DB."
);
t.end();
});
t.test("Single import", async (t) => {
let res = await mockApi
.post("/internal-api/import/file")
.set("Cookie", cookie)
.attach(
"scoreData",
GetKTDataBuffer("./json_batch-manual/small-file.json"),
"small-file.json"
)
.field("importType", "file/json:batch-manual");
t.equal(res.body.success, true, "Should be successful.");
t.equal(res.body.body.errors.length, 0, "Import Should have 0 failed scores.");
t.equal(res.body.body.scoreIDs.length, 1, "Should have 1 successful score.");
let scoreCount = await db.scores.find({
scoreID: { $in: res.body.body.scoreIDs },
});
t.equal(
scoreCount.length,
res.body.body.scoreIDs.length,
"All returned scoreIDs should be inserted to the DB."
);
t.end();
});
t.end();
});
t.end();
});
@@ -1,6 +1,130 @@
import t from "tap";
import { CloseMongoConnection } from "../../../../db/db";
import CreateLogCtx from "../../../../logger";
import ScoreImportFatalError from "../../../framework/score-importing/score-import-error";
import ParserFn from "./parser";
t.todo("#ParserFn", (t) => {
const fileify = (obj: any) =>
({
buffer: Buffer.from(JSON.stringify(obj)),
filename: "fileify.json",
} as Express.Multer.File);
const logger = CreateLogCtx("parser.test.ts");
t.test("#ParserFn", (t) => {
t.test("Non-Object", (t) => {
t.throws(
() => ParserFn(fileify(false), {}, logger),
new ScoreImportFatalError(
400,
"Invalid BATCH-MANUAL (Not an object, recieved boolean.)"
),
"Should throw an error."
);
t.end();
});
t.test("No Header", (t) => {
t.throws(
() => ParserFn(fileify({ body: [] }), {}, logger),
new ScoreImportFatalError(
400,
"Could not retrieve head.game - is this valid BATCH-MANUAL?"
),
"Should throw an error."
);
t.end();
});
t.test("No Game", (t) => {
t.throws(
() => ParserFn(fileify({ body: [], head: { service: "foo" } }), {}, logger),
new ScoreImportFatalError(
400,
"Could not retrieve head.game - is this valid BATCH-MANUAL?"
),
"Should throw an error."
);
t.end();
});
t.test("Invalid Game", (t) => {
t.throws(
() =>
ParserFn(
fileify({ body: [], head: { service: "foo", game: "invalid_game" } }),
{},
logger
),
new ScoreImportFatalError(
400,
"Invalid game invalid_game - expected any of iidx, museca, maimai, jubeat, popn, sdvx, ddr, bms, chunithm, gitadora, usc"
),
"Should throw an error."
);
t.throws(
() => ParserFn(fileify({ body: [], head: { service: "foo", game: 123 } }), {}, logger),
new ScoreImportFatalError(
400,
"Invalid game 123 - expected any of iidx, museca, maimai, jubeat, popn, sdvx, ddr, bms, chunithm, gitadora, usc"
),
"Should throw an error."
);
t.end();
});
t.test("Invalid Service", (t) => {
t.throws(
() => ParserFn(fileify({ body: [], head: { service: "1", game: "iidx" } }), {}, logger),
new ScoreImportFatalError(
400,
"Invalid BATCH-MANUAL (head.service | Expected a string with length between 3 and 15. | Received 1)"
),
"Should throw an error."
);
t.throws(
() => ParserFn(fileify({ body: [], head: { service: 1, game: "iidx" } }), {}, logger),
new ScoreImportFatalError(
400,
"Invalid BATCH-MANUAL (head.service | Expected a string with length between 3 and 15. | Received 1)"
),
"Should throw an error."
);
t.end();
});
t.test("Valid Empty BATCH-MANUAL", (t) => {
let res = ParserFn(
fileify({ body: [], head: { service: "foo", game: "iidx" } }),
{},
logger
);
t.hasStrict(res, {
// @ts-expect-error asdf
game: "iidx",
context: {
// @ts-expect-error asdf
service: "foo",
game: "iidx",
version: null,
},
// @ts-expect-error asdf
iterable: [],
});
t.end();
});
t.end();
});
t.teardown(CloseMongoConnection);