mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-01 19:38:13 +03:00
Merge pull request #302 from zkldi:zkldi/issue-285-Rewrite-all-tests-to-mocha
Optimise Tests
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
node_modules
|
||||
js
|
||||
logs
|
||||
.pnpm-debug.log
|
||||
|
||||
# Test stuffs
|
||||
.nyc_output
|
||||
|
||||
+1
-3
@@ -1,6 +1,5 @@
|
||||
files: "src/**/*.test.ts"
|
||||
files: "src/test-utils/single-process-tap.ts"
|
||||
test-env: [NODE_ENV=test, TCHIS_CONF_LOCATION=test.conf.json5]
|
||||
jobs: 1 # disable parallel to avoid db clashes
|
||||
timeout: 120 # might need to be increased
|
||||
ts: true
|
||||
before: "./src/test-utils/hack-setup.js"
|
||||
@@ -10,4 +9,3 @@ functions: 80
|
||||
lines: 80
|
||||
statements: 80
|
||||
reporter: terse
|
||||
save: "failed-tests.txt"
|
||||
@@ -1,14 +0,0 @@
|
||||
{
|
||||
"0 debug pnpm:scope": {
|
||||
"selected": 1
|
||||
},
|
||||
"1 error pnpm": {
|
||||
"code": "ERR_PNPM_CANNOT_REMOVE_MISSING_DEPS",
|
||||
"err": {
|
||||
"name": "Error",
|
||||
"message": "Cannot remove 'better-sqlite3': project has no dependencies of any kind",
|
||||
"code": "ERR_PNPM_CANNOT_REMOVE_MISSING_DEPS",
|
||||
"stack": "Error: Cannot remove 'better-sqlite3': project has no dependencies of any kind\n at Object.handler (/home/zkldi/pnpm-global/5/node_modules/.pnpm/pnpm@6.4.0/node_modules/pnpm/dist/pnpm.cjs:116381:15)\n at async Timeout._onTimeout (/home/zkldi/pnpm-global/5/node_modules/.pnpm/pnpm@6.4.0/node_modules/pnpm/dist/pnpm.cjs:124690:24)"
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
+2
-4
@@ -3,9 +3,9 @@ import { CloseAllConnections } from "test-utils/close-connections";
|
||||
import ResetDBState from "test-utils/resets";
|
||||
import db from "./db";
|
||||
|
||||
t.beforeEach(ResetDBState);
|
||||
|
||||
t.test("ID field autoprojection", async (t) => {
|
||||
await ResetDBState();
|
||||
|
||||
const res = await db.scores.findOne();
|
||||
t.equal(res!._id, undefined);
|
||||
|
||||
@@ -26,5 +26,3 @@ t.test("ID field autoprojection", async (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
Vendored
+15
@@ -81,6 +81,21 @@ const RemoveIDMiddleware: TMiddleware =
|
||||
return next(args, method);
|
||||
};
|
||||
|
||||
const StripIDMiddleware: TMiddleware = () => (next) => (args: any, method) => {
|
||||
if (method === "insert") {
|
||||
if (Array.isArray(args.data)) {
|
||||
for (const d of args.data) {
|
||||
delete d._id;
|
||||
}
|
||||
} else {
|
||||
delete args.data._id;
|
||||
}
|
||||
}
|
||||
|
||||
return next(args, method);
|
||||
};
|
||||
|
||||
monkDB.addMiddleware(StripIDMiddleware);
|
||||
monkDB.addMiddleware(RemoveIDMiddleware);
|
||||
|
||||
export async function CloseMongoConnection() {
|
||||
|
||||
-2
@@ -12,5 +12,3 @@ t.test("Basic PUB/SUB testing", (t) => {
|
||||
|
||||
RedisPub("test" as any, { userID: 1 } as any);
|
||||
});
|
||||
|
||||
t.teardown(CloseRedisPubSub);
|
||||
|
||||
@@ -310,4 +310,3 @@ t.test("#HumaniseGoalProgress", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -12,7 +12,7 @@ function getTestTxt() {
|
||||
return fs.readFileSync(path.join(CDN_FILE_ROOT, "test.txt"), "utf-8");
|
||||
}
|
||||
|
||||
t.beforeEach(() => {
|
||||
const ResetFileRoot = () => {
|
||||
if (process.env.NODE_ENV !== "test") {
|
||||
throw new Error(
|
||||
`Not in test, yet CDN.test.ts was triggered, which could rm -rf something important.`
|
||||
@@ -27,9 +27,11 @@ t.beforeEach(() => {
|
||||
|
||||
// isn't this terrifyingly risky?
|
||||
fs.rmSync(CDN_FILE_ROOT, { recursive: true, force: true });
|
||||
});
|
||||
};
|
||||
|
||||
t.test("#CDNStore", (t) => {
|
||||
t.beforeEach(ResetFileRoot);
|
||||
|
||||
t.test("Should store a value.", async (t) => {
|
||||
await CDNStore("test.txt", "hello world");
|
||||
|
||||
@@ -67,6 +69,8 @@ t.test("#CDNStore", (t) => {
|
||||
});
|
||||
|
||||
t.test("#CDNDelete", (t) => {
|
||||
t.beforeEach(ResetFileRoot);
|
||||
|
||||
t.test("Should delete the file at the given location.", async (t) => {
|
||||
await CDNStore("test.txt", "1");
|
||||
|
||||
@@ -85,6 +89,8 @@ t.test("#CDNDelete", (t) => {
|
||||
});
|
||||
|
||||
t.test("#CDNRetrieve", (t) => {
|
||||
t.beforeEach(ResetFileRoot);
|
||||
|
||||
t.test("Should retrieve the file at the given location.", async (t) => {
|
||||
await CDNStore("test.txt", "1");
|
||||
|
||||
@@ -105,6 +111,8 @@ t.test("#CDNRetrieve", (t) => {
|
||||
});
|
||||
|
||||
t.test("#CDNStoreOrOverwrite", (t) => {
|
||||
t.beforeEach(ResetFileRoot);
|
||||
|
||||
t.test("Should store a file if one doesn't exist", async (t) => {
|
||||
await CDNStoreOrOverwrite("test.txt", "1");
|
||||
|
||||
@@ -127,6 +135,8 @@ t.test("#CDNStoreOrOverwrite", (t) => {
|
||||
});
|
||||
|
||||
t.test("#CDNRedirect", (t) => {
|
||||
t.beforeEach(ResetFileRoot);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const mockMW = (req: any, res: any) => CDNRedirect(res, "/test.txt");
|
||||
|
||||
@@ -141,5 +151,3 @@ t.test("#CDNRedirect", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -4,9 +4,9 @@ import { CloseAllConnections } from "test-utils/close-connections";
|
||||
import ResetDBState from "test-utils/resets";
|
||||
import { CreateGameSettings } from "./create-game-settings";
|
||||
|
||||
t.beforeEach(ResetDBState);
|
||||
|
||||
t.test("#CreateGameSettings", (t) => {
|
||||
t.beforeEach(ResetDBState);
|
||||
|
||||
t.test("Should create a new user's settings.", async (t) => {
|
||||
await CreateGameSettings(1, "bms", "7K");
|
||||
|
||||
@@ -31,5 +31,3 @@ t.test("#CreateGameSettings", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -54,5 +54,3 @@ t.test("#ChangeRootLogLevel", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -105,11 +105,7 @@ let tports: (
|
||||
|
||||
/* istanbul ignore next */
|
||||
if (IN_TESTING) {
|
||||
tports = [
|
||||
new transports.Console({
|
||||
format: consoleFormatRoute,
|
||||
}),
|
||||
];
|
||||
tports = [new transports.File({ filename: "logs/tachi-test.log", format: defaultFormatRoute })];
|
||||
} else {
|
||||
tports = [
|
||||
new transports.File({
|
||||
|
||||
@@ -382,5 +382,3 @@ t.test("#CalculateDataForGamePT", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -509,5 +509,3 @@ t.test("#CalculateLampRating", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -18,5 +18,3 @@ t.test("#CreateImportLoggerAndID", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -421,5 +421,3 @@ t.test("#ProcessGoal", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -353,5 +353,3 @@ t.test("#UpdateUsersMilestones", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -242,5 +242,3 @@ t.test("#ReprocessOrphan", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -168,5 +168,3 @@ t.test("#CreatePBDoc", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -58,5 +58,3 @@ t.test("#ProcessPBs", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -44,8 +44,6 @@ t.test("#QueueScoreInsert, #InsertQueue", async (t) => {
|
||||
|
||||
let r = await InsertQueue(); // flush queue just incase former test fails.
|
||||
|
||||
t.equal(r, 0, "Queue should be empty after test.");
|
||||
|
||||
t.test("Queue Overflow Test", async (t) => {
|
||||
for (let i = 0; i < 499; i++) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
@@ -107,5 +105,3 @@ t.test("#QueueScoreInsert, #InsertQueue", async (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -5,8 +5,9 @@ import ResetDBState from "test-utils/resets";
|
||||
import { Testing511SPA, TestingIIDXSPDryScore } from "test-utils/test-data";
|
||||
import { CreateScoreID, GetWithScoreID } from "./score-id";
|
||||
|
||||
t.beforeEach(ResetDBState);
|
||||
t.test("#GetWithScoreID", async (t) => {
|
||||
await ResetDBState();
|
||||
|
||||
const sc = await GetWithScoreID("TESTING_SCORE_ID");
|
||||
|
||||
t.not(sc, null, "Return a score for a valid score id");
|
||||
@@ -92,5 +93,3 @@ t.test("#CreateScoreID", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -444,5 +444,3 @@ t.test("#LoadScoresIntoSessions", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -135,5 +135,3 @@ t.test("#CalculateClassDeltas", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -71,5 +71,3 @@ t.test("#CalculateRatings", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -205,5 +205,3 @@ t.test("#UpdateUsersGamePlaytypeStats", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -143,5 +143,3 @@ t.test("#CreateArcIIDXClassHandler", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -91,5 +91,3 @@ t.test("#ResolveARCIIDXLamp", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -66,5 +66,3 @@ t.test("#ParseArcIIDX", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -93,5 +93,3 @@ t.test("#ResolveARCSDVXLamp", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -66,5 +66,3 @@ t.test("#ParseArcSDVX", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -174,5 +174,3 @@ t.test("#CreateKaiIIDXClassHandler", async (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -91,5 +91,3 @@ t.test("#ConvertAPIKaiIIDX", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -83,5 +83,3 @@ t.test("#ParseKaiIIDX", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -127,5 +127,3 @@ t.test("#CreateKaiReauthFunction", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -145,5 +145,3 @@ t.test("#CreateKaiSDVXClassHandler", async (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -125,5 +125,3 @@ t.test("#ResolveKaiLamp", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -83,5 +83,3 @@ t.test("#ParseKaiSDVX", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -201,5 +201,3 @@ t.test("#TraverseKaiAPI", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -380,5 +380,3 @@ t.test("#ConverterFn", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -462,5 +462,3 @@ t.test("#ParserFn", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -30,5 +30,3 @@ t.todo("#ConverterFn", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -300,5 +300,3 @@ t.test("#ParseEamusementCSV", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -135,5 +135,3 @@ t.test("#ConvertFileMerIIDX", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -141,5 +141,3 @@ t.test("#ParseMerIIDX", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -226,5 +226,3 @@ t.test("#ResolveS3Lamp", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -223,5 +223,3 @@ t.test("#ParseSolidStateXML", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -112,5 +112,3 @@ t.test("#ConverterIRBarbatos", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -32,5 +32,3 @@ t.test("#ParseBarbatosSingle", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -63,5 +63,3 @@ t.test("#FerStaticClassHandler", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -180,5 +180,3 @@ t.test("#ParseFervidexStatic", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -245,5 +245,3 @@ t.test("#ConverterIRFervidex", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -122,5 +122,3 @@ t.test("#ConverterIRUSC", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -36,5 +36,3 @@ t.test("#ParseIRUSC", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -60,5 +60,3 @@ t.test("#SearchUsersRegExp", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -11,11 +11,13 @@ import db from "external/mongo/db";
|
||||
/* eslint-disable no-return-await */
|
||||
// causes a race condition otherwise due to weird tap interaction
|
||||
|
||||
t.beforeEach(ResetDBState);
|
||||
t.beforeEach(async () => await CreateFolderChartLookup(TestingIIDXFolderSP10));
|
||||
t.beforeEach(async () => await db["personal-bests"].insert(deepmerge(TestingIIDXSPScorePB, {})));
|
||||
|
||||
t.test("#EvaluateShowcaseStat", (t) => {
|
||||
t.beforeEach(ResetDBState);
|
||||
t.beforeEach(async () => await CreateFolderChartLookup(TestingIIDXFolderSP10));
|
||||
t.beforeEach(
|
||||
async () => await db["personal-bests"].insert(deepmerge(TestingIIDXSPScorePB, {}))
|
||||
);
|
||||
|
||||
t.test("Should evaluate a folder stat.", async (t) => {
|
||||
const data = await EvaluateShowcaseStat(
|
||||
{
|
||||
@@ -90,5 +92,3 @@ t.test("#EvaluateShowcaseStat", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -8,42 +8,42 @@ import { EvaluateUsersStatsShowcase } from "./get-stats";
|
||||
import deepmerge from "deepmerge";
|
||||
import { CreateFolderChartLookup } from "utils/folder";
|
||||
|
||||
t.beforeEach(ResetDBState);
|
||||
t.test("#EvalulateUsersStatsShowcase", (t) => {
|
||||
t.beforeEach(ResetDBState);
|
||||
|
||||
t.beforeEach(async () => {
|
||||
await db.folders.insert(TestingIIDXFolderSP10);
|
||||
await CreateFolderChartLookup(TestingIIDXFolderSP10);
|
||||
t.beforeEach(async () => {
|
||||
await db.folders.insert(TestingIIDXFolderSP10);
|
||||
await CreateFolderChartLookup(TestingIIDXFolderSP10);
|
||||
|
||||
await db["game-settings"].remove({});
|
||||
await db["game-settings"].remove({});
|
||||
|
||||
await db["game-settings"].insert({
|
||||
userID: 1,
|
||||
game: "iidx",
|
||||
playtype: "SP",
|
||||
preferences: {
|
||||
preferredProfileAlg: null,
|
||||
preferredScoreAlg: null,
|
||||
preferredSessionAlg: null,
|
||||
stats: [
|
||||
{
|
||||
folderID: TestingIIDXFolderSP10.folderID,
|
||||
mode: "folder",
|
||||
property: "lamp",
|
||||
gte: IIDX_LAMPS.HARD_CLEAR,
|
||||
},
|
||||
{
|
||||
chartID: Testing511SPA.chartID,
|
||||
mode: "chart",
|
||||
property: "score",
|
||||
},
|
||||
],
|
||||
},
|
||||
await db["game-settings"].insert({
|
||||
userID: 1,
|
||||
game: "iidx",
|
||||
playtype: "SP",
|
||||
preferences: {
|
||||
preferredProfileAlg: null,
|
||||
preferredScoreAlg: null,
|
||||
preferredSessionAlg: null,
|
||||
stats: [
|
||||
{
|
||||
folderID: TestingIIDXFolderSP10.folderID,
|
||||
mode: "folder",
|
||||
property: "lamp",
|
||||
gte: IIDX_LAMPS.HARD_CLEAR,
|
||||
},
|
||||
{
|
||||
chartID: Testing511SPA.chartID,
|
||||
mode: "chart",
|
||||
property: "score",
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
await db["personal-bests"].insert(deepmerge(TestingIIDXSPScorePB, {}));
|
||||
});
|
||||
|
||||
await db["personal-bests"].insert(deepmerge(TestingIIDXSPScorePB, {}));
|
||||
});
|
||||
|
||||
t.test("#EvalulateUsersStatsShowcase", (t) => {
|
||||
t.test("Should evaluate a user's preferred stats.", async (t) => {
|
||||
const res = await EvaluateUsersStatsShowcase(1, "iidx", "SP");
|
||||
|
||||
@@ -124,5 +124,3 @@ t.test("#EvalulateUsersStatsShowcase", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -6,9 +6,9 @@ import { SYMBOL_TachiAPIAuth } from "lib/constants/tachi";
|
||||
import { CloseAllConnections } from "test-utils/close-connections";
|
||||
import ResetDBState from "test-utils/resets";
|
||||
|
||||
t.beforeEach(ResetDBState);
|
||||
|
||||
t.test("#SetRequestPermissions", (t) => {
|
||||
t.beforeEach(ResetDBState);
|
||||
|
||||
t.test("Should assign valid APIKey information to req[SYMBOL_TachiAPIData]", async (t) => {
|
||||
await db["api-tokens"].insert({
|
||||
userID: 1,
|
||||
@@ -115,5 +115,3 @@ t.test("#SetRequestPermissions", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -58,5 +58,3 @@ t.test("POST /api/v1/admin/change-log-level", async (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -72,5 +72,3 @@ t.test("#ValidateCaptcha", async (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -274,5 +274,3 @@ t.test("POST /api/v1/auth/register", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -162,5 +162,3 @@ t.test("GET /api/v1/games/:game/:playtype/charts/:chartID/tierlist", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -70,5 +70,3 @@ t.test("GET /api/v1/games/:game/:playtype/charts", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -139,5 +139,3 @@ t.test("GET /api/v1/games/:game/:playtype/folders/:folderID/tierlist", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -98,5 +98,3 @@ t.test("GET /api/v1/games/:game/:playtype/leaderboard", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -40,5 +40,3 @@ t.test("GET /api/v1/games/:game/:playtype/songs/:songID", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -49,5 +49,3 @@ t.test("GET /api/v1/games/:game/:playtype/tables/:tableID", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -22,5 +22,3 @@ t.test("GET /api/v1/games/:game", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -16,5 +16,3 @@ t.test("GET /api/v1/games", async (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -331,5 +331,3 @@ t.test("POST /api/v1/import/file", async (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -3,16 +3,16 @@ import { CloseAllConnections } from "test-utils/close-connections";
|
||||
import mockApi from "test-utils/mock-api";
|
||||
import { ClearTestingRateLimitCache } from "server/middleware/rate-limiter";
|
||||
|
||||
t.beforeEach(ClearTestingRateLimitCache);
|
||||
|
||||
// just a rudimentary test for rate-limiting. We fire 150 requests at GET /api/v1
|
||||
// (which does a server status check)
|
||||
// and then check any of them return 429.
|
||||
t.test("Rate Limiting Test", async (t) => {
|
||||
ClearTestingRateLimitCache();
|
||||
|
||||
const promises = [];
|
||||
|
||||
// default rate limit is 500, so lets go a bit over
|
||||
for (let i = 0; i < 600; i++) {
|
||||
for (let i = 0; i < 520; i++) {
|
||||
promises.push(mockApi.get("/api/v1/status"));
|
||||
}
|
||||
|
||||
@@ -26,6 +26,8 @@ t.test("Rate Limiting Test", async (t) => {
|
||||
});
|
||||
|
||||
t.test("404 Handler", async (t) => {
|
||||
ClearTestingRateLimitCache();
|
||||
|
||||
const res = await mockApi.get("/api/v1/invalid_route_that_will_never_exist");
|
||||
|
||||
t.equal(res.statusCode, 404);
|
||||
@@ -36,5 +38,3 @@ t.test("404 Handler", async (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -175,5 +175,3 @@ t.test("PATCH /api/v1/scores/:scoreID", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -41,5 +41,3 @@ t.test("GET /api/v1/search", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -201,5 +201,3 @@ t.test("PATCH /api/v1/sessions/:sessionID", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -79,5 +79,3 @@ t.test("POST /api/v1/status", async (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -73,5 +73,3 @@ t.test("PUT /api/v1/users/:userID/banner", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
-2
@@ -123,5 +123,3 @@ t.test("GET /api/v1/users/:userID/games/:game/:playtype/folders/:folderID/timeli
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -175,5 +175,3 @@ t.test("GET /api/v1/users/:userID/games/:game/:playtype/pbs/:chartID", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -328,5 +328,3 @@ t.test("GET /api/v1/users/:userID/games/:game/:playtype/most-played", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
-2
@@ -202,5 +202,3 @@ t.test("GET /api/v1/users/:userID/games/:game/:playtype/scores/:chartID", (t) =>
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
-2
@@ -180,5 +180,3 @@ t.test("GET /api/v1/users/:userID/games/:game/:playtype/sessions/recent", (t) =>
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
+4
-4
@@ -5,9 +5,9 @@ import { CloseAllConnections } from "test-utils/close-connections";
|
||||
import mockApi from "test-utils/mock-api";
|
||||
import ResetDBState from "test-utils/resets";
|
||||
|
||||
t.beforeEach(ResetDBState);
|
||||
|
||||
t.test("GET /api/v1/users/:userID/games/:game/:playtype/settings", (t) => {
|
||||
t.beforeEach(ResetDBState);
|
||||
|
||||
t.test("Should return a user's settings.", async (t) => {
|
||||
const res = await mockApi.get("/api/v1/users/1/games/iidx/SP/settings");
|
||||
|
||||
@@ -30,6 +30,8 @@ t.test("GET /api/v1/users/:userID/games/:game/:playtype/settings", (t) => {
|
||||
});
|
||||
|
||||
t.test("PATCH /api/v1/users/:userID/games/:game/:playtype/settings", (t) => {
|
||||
t.beforeEach(ResetDBState);
|
||||
|
||||
t.test("Should update a user's settings.", async (t) => {
|
||||
await db["api-tokens"].insert({
|
||||
userID: 1,
|
||||
@@ -150,5 +152,3 @@ t.test("PATCH /api/v1/users/:userID/games/:game/:playtype/settings", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
+11
-6
@@ -9,8 +9,7 @@ import { TestingIIDXFolderSP10, Testing511SPA, TestingIIDXSPScorePB } from "test
|
||||
import { CreateFolderChartLookup } from "utils/folder";
|
||||
import deepmerge from "deepmerge";
|
||||
|
||||
t.beforeEach(ResetDBState);
|
||||
t.beforeEach(async () => {
|
||||
const SetFolders = async () => {
|
||||
await db.folders.insert(TestingIIDXFolderSP10);
|
||||
await CreateFolderChartLookup(TestingIIDXFolderSP10);
|
||||
|
||||
@@ -41,9 +40,12 @@ t.beforeEach(async () => {
|
||||
});
|
||||
|
||||
await db["personal-bests"].insert(deepmerge(TestingIIDXSPScorePB, {}));
|
||||
});
|
||||
};
|
||||
|
||||
t.test("GET /api/v1/users/:userID/games/:game/:playtype/showcase", (t) => {
|
||||
t.beforeEach(ResetDBState);
|
||||
t.beforeEach(SetFolders);
|
||||
|
||||
t.test("Should return the evaluated stats for this user.", async (t) => {
|
||||
const res = await mockApi.get("/api/v1/users/1/games/iidx/SP/showcase");
|
||||
|
||||
@@ -127,6 +129,9 @@ t.test("GET /api/v1/users/:userID/games/:game/:playtype/showcase", (t) => {
|
||||
});
|
||||
|
||||
t.test("GET /api/v1/users/:userID/games/:game/:playtype/showcase/custom", (t) => {
|
||||
t.beforeEach(ResetDBState);
|
||||
t.beforeEach(SetFolders);
|
||||
|
||||
t.test("Should return a custom folder evaluated stat on a user.", async (t) => {
|
||||
const res = await mockApi.get(
|
||||
`/api/v1/users/1/games/iidx/SP/showcase/custom?mode=folder&prop=grade>e=3&folderID=${TestingIIDXFolderSP10.folderID}`
|
||||
@@ -236,8 +241,10 @@ t.test("GET /api/v1/users/:userID/games/:game/:playtype/showcase/custom", (t) =>
|
||||
t.end();
|
||||
});
|
||||
|
||||
// @todo #239 PUT UGPT-Stats needs some tests for input validation.
|
||||
t.test("PUT /api/v1/users/:userID/games/:game/:playtype/showcase", (t) => {
|
||||
t.beforeEach(ResetDBState);
|
||||
t.beforeEach(SetFolders);
|
||||
|
||||
t.beforeEach(
|
||||
async () =>
|
||||
// eslint-disable-next-line no-return-await
|
||||
@@ -401,5 +408,3 @@ t.test("PUT /api/v1/users/:userID/games/:game/:playtype/showcase", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
-2
@@ -43,5 +43,3 @@ t.test("GET /api/v1/users/:userID/games/:game/:playtype/tables/:tableID", (t) =>
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -176,5 +176,3 @@ t.test("PATCH /api/v1/users/:userID/integrations/arc", async (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -64,5 +64,3 @@ t.test("GET /api/v1/users/:userID/integrations/kai/:kaiType", async (t) => {
|
||||
|
||||
// test is currently undoable due to issues with mocking out real Fetch calls.
|
||||
t.todo("PATCH /api/v1/userse/:userID/integrations/kai/:kaiType/oauth2callback");
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -74,5 +74,3 @@ t.test("PUT /api/v1/users/:userID/pfp", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -312,5 +312,3 @@ t.test("GET /api/v1/users/:userID/game-stats", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -73,5 +73,3 @@ t.test("GET /api/v1/users", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -41,5 +41,3 @@ t.test("POST /ir/barbatos/score/submit", async (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -46,5 +46,3 @@ t.test("#ValidateIRClientVersion", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -187,5 +187,3 @@ t.test("#TachiPBScoreToBeatorajaFormat", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -55,5 +55,3 @@ t.test("GET /ir/beatoraja/charts/:chartSHA256/scores", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -392,5 +392,3 @@ t.test("POST /ir/beatoraja/submit-course", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -65,5 +65,3 @@ t.test("POST /ir/chunitachi/import", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -59,5 +59,3 @@ t.test("POST /ir/direct-manual/import", async (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -102,10 +102,10 @@ function TestHeaders(url: string, data: any) {
|
||||
});
|
||||
}
|
||||
|
||||
t.beforeEach(ResetDBState);
|
||||
t.beforeEach(InsertFakeTokenWithAllPerms("mock_token"));
|
||||
|
||||
t.test("POST /ir/fervidex/class/submit", (t) => {
|
||||
t.beforeEach(ResetDBState);
|
||||
t.beforeEach(InsertFakeTokenWithAllPerms("mock_token"));
|
||||
|
||||
TestHeaders("/ir/fervidex/class/submit", {});
|
||||
|
||||
t.test("Should update a users class.", async (t) => {
|
||||
@@ -220,6 +220,9 @@ t.test("POST /ir/fervidex/class/submit", (t) => {
|
||||
});
|
||||
|
||||
t.test("POST /ir/fervidex/score/submit", (t) => {
|
||||
t.beforeEach(ResetDBState);
|
||||
t.beforeEach(InsertFakeTokenWithAllPerms("mock_token"));
|
||||
|
||||
TestHeaders("/ir/fervidex/score/submit", GetKTDataJSON("./fervidex/base.json"));
|
||||
|
||||
t.test("Should import a valid score", async (t) => {
|
||||
@@ -280,6 +283,9 @@ t.test("POST /ir/fervidex/score/submit", (t) => {
|
||||
});
|
||||
|
||||
t.test("POST /ir/fervidex/profile/submit", (t) => {
|
||||
t.beforeEach(ResetDBState);
|
||||
t.beforeEach(InsertFakeTokenWithAllPerms("mock_token"));
|
||||
|
||||
TestHeaders("/ir/fervidex/class/submit", GetKTDataJSON("./fervidex-static/base.json"));
|
||||
|
||||
const ferStaticBody = GetKTDataJSON("./fervidex-static/base.json");
|
||||
@@ -333,5 +339,3 @@ t.test("POST /ir/fervidex/profile/submit", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -456,5 +456,3 @@ t.test("POST /replays", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -410,5 +410,3 @@ t.test("#CreatePOSTScoresResponseBody", async (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import glob from "glob";
|
||||
import path from "path";
|
||||
import t from "tap";
|
||||
import { CloseAllConnections } from "./close-connections";
|
||||
|
||||
const files = glob.sync(path.join(__dirname, "../../", "**/*.test.ts"));
|
||||
|
||||
process.env.NODE_PATH = path.join(__dirname, "../../");
|
||||
|
||||
for (const file of files) {
|
||||
require(file);
|
||||
}
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
@@ -52,5 +52,3 @@ t.test("#DecrementCounterValue", (t) => {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user