mirror of
https://github.com/zkldi/Tachi.git
synced 2026-09-30 02:48:01 +03:00
PLI-IIDX-CSV support (that took like, 2 minutes)
This commit is contained in:
@@ -2,7 +2,6 @@ import t from "tap";
|
||||
import mockApi from "../../test-utils/mock-api";
|
||||
import {
|
||||
GetKTDataBuffer,
|
||||
GetKTDataJSON,
|
||||
LoadKTBlackIIDXData,
|
||||
TestingIIDXEamusementCSV26,
|
||||
TestingIIDXEamusementCSV27,
|
||||
@@ -109,6 +108,94 @@ t.test("POST /api/import/file", async (t) => {
|
||||
t.end();
|
||||
});
|
||||
|
||||
// thats right i literally just copied it
|
||||
t.test("file/pli-iidx-csv", (t) => {
|
||||
t.beforeEach(LoadKTBlackIIDXData);
|
||||
|
||||
t.test("Mini HV import", async (t) => {
|
||||
const res = await mockApi
|
||||
.post("/api/import/file")
|
||||
.set("Cookie", cookie)
|
||||
.attach(
|
||||
"scoreData",
|
||||
GetKTDataBuffer("./eamusement-iidx-csv/small-hv-file.csv"),
|
||||
"my_csv.csv"
|
||||
)
|
||||
.field("importType", "file/pli-iidx-csv")
|
||||
.field("playtype", "SP");
|
||||
|
||||
t.equal(res.body.success, true, "Should be successful.");
|
||||
|
||||
t.equal(res.body.body.errors.length, 0, "Mini HV Import Should have 0 failed scores.");
|
||||
|
||||
t.equal(res.body.body.scoreIDs.length, 2, "Should have 2 successful scores.");
|
||||
|
||||
const 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("Valid Rootage CSV import", async (t) => {
|
||||
const res = await mockApi
|
||||
.post("/api/import/file")
|
||||
.set("Cookie", cookie)
|
||||
.attach("scoreData", TestingIIDXEamusementCSV26, "my_csv.csv")
|
||||
.field("importType", "file/pli-iidx-csv")
|
||||
.field("playtype", "SP");
|
||||
|
||||
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.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("Valid Heroic Verse CSV import", async (t) => {
|
||||
const res = await mockApi
|
||||
.post("/api/import/file")
|
||||
.set("Cookie", cookie)
|
||||
.attach("scoreData", TestingIIDXEamusementCSV27, "my_csv.csv")
|
||||
.field("importType", "file/pli-iidx-csv")
|
||||
.field("playtype", "SP");
|
||||
|
||||
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.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.test("file/batch-manual", (t) => {
|
||||
t.test("Empty import", async (t) => {
|
||||
const res = await mockApi
|
||||
|
||||
@@ -91,6 +91,7 @@ import ParseEamusementIIDXCSV from "../../score-import/import-types/file/eamusem
|
||||
import ParseBatchManual from "../../score-import/import-types/file/batch-manual/parser";
|
||||
import { ParseSolidStateXML } from "../../score-import/import-types/file/solid-state-squad/parser";
|
||||
import { ParseMerIIDX } from "../../score-import/import-types/file/mer-iidx/parser";
|
||||
import ParsePLIIIDXCSV from "../../score-import/import-types/file/pli-iidx-csv/parser";
|
||||
|
||||
/**
|
||||
* Resolves the data from a file upload into an iterable,
|
||||
@@ -111,6 +112,8 @@ export function ResolveFileUploadData(
|
||||
switch (importType) {
|
||||
case "file/eamusement-iidx-csv":
|
||||
return ParseEamusementIIDXCSV(fileData, body, logger);
|
||||
case "file/pli-iidx-csv":
|
||||
return ParsePLIIIDXCSV(fileData, body, logger);
|
||||
case "file/batch-manual":
|
||||
return ParseBatchManual(fileData, body, logger);
|
||||
case "file/solid-state-squad":
|
||||
|
||||
@@ -5,11 +5,6 @@ import {
|
||||
IIDXEamusementCSVData,
|
||||
} from "../../common/eamusement-iidx-csv/types";
|
||||
|
||||
/**
|
||||
* Parses a buffer of EamusementCSV data.
|
||||
* @param fileData - The buffer to parse.
|
||||
* @param body - The request body that made this file import request. Used to infer playtype.
|
||||
*/
|
||||
function ParseEamusementIIDXCSV(
|
||||
fileData: Express.Multer.File,
|
||||
body: Record<string, unknown>,
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { KtLogger, ParserFunctionReturnsSync } from "../../../../types";
|
||||
import GenericParseEamIIDXCSV from "../../common/eamusement-iidx-csv/parser";
|
||||
import {
|
||||
IIDXEamusementCSVContext,
|
||||
IIDXEamusementCSVData,
|
||||
} from "../../common/eamusement-iidx-csv/types";
|
||||
|
||||
function ParsePLIIIDXCSV(
|
||||
fileData: Express.Multer.File,
|
||||
body: Record<string, unknown>,
|
||||
logger: KtLogger
|
||||
): ParserFunctionReturnsSync<IIDXEamusementCSVData, IIDXEamusementCSVContext> {
|
||||
return GenericParseEamIIDXCSV(fileData, body, "PLI", logger);
|
||||
}
|
||||
|
||||
export default ParsePLIIIDXCSV;
|
||||
+2
-2
@@ -19,7 +19,7 @@ import {
|
||||
import {
|
||||
IIDXEamusementCSVContext,
|
||||
IIDXEamusementCSVData,
|
||||
} from "./score-import/import-types/file/eamusement-iidx-csv/types";
|
||||
} from "./score-import/import-types/common/eamusement-iidx-csv/types";
|
||||
import { MerScore } from "./score-import/import-types/file/mer-iidx/types";
|
||||
import { S3Score } from "./score-import/import-types/file/solid-state-squad/types";
|
||||
import { BarbatosScore } from "./score-import/import-types/ir/barbatos/types";
|
||||
@@ -137,7 +137,7 @@ export interface ImportTypeDataMap {
|
||||
"file/batch-manual": BatchManualScore;
|
||||
"file/solid-state-squad": S3Score;
|
||||
"file/mer-iidx": MerScore;
|
||||
"file/pli-iidx-csv": EmptyObject;
|
||||
"file/pli-iidx-csv": IIDXEamusementCSVData;
|
||||
|
||||
"ir/direct-manual": BatchManualScore;
|
||||
"ir/barbatos": BarbatosScore;
|
||||
|
||||
Reference in New Issue
Block a user