import { FakeGameSettings, FakeImport, FakeNotification, FakeOtherUser, HC511Goal, HC511UserGoal, TestingIIDXSPScore, TestingIIDXSPScorePB, TestingJubeatPB, TestingSDVXAlbidaChart, TestingSDVXPB, TestingSDVXScore, } from "./test-data"; import deepmerge from "deepmerge"; import type { ChartDocument, Game, GoalDocument, GoalSubscriptionDocument, ImportDocument, integer, NotificationDocument, PBScoreDocument, Playtype, UserDocument, ScoreDocument, UGPTSettings, UserGameStats, } from "tachi-common"; /** * Async Generator To Array */ export async function agta(ag: AsyncIterable | Iterable) { const a = []; for await (const el of ag) { a.push(el); } return a; } /** * Deep-modify an object. This is a wrapper around deepmerge that returns proper types. */ export function dmf(base: T, modifant: Partial): T { return deepmerge(base, modifant, { // The new array should replace the former one, instead of joining them together. arrayMerge: (originalArray, newArray) => newArray as Array, }); } /** * Make a fake user for testing. This automatically sets the username to something * unique (to avoid index collisions) * * @param userID - The userID this fake user should have. */ export function mkFakeUser(userID: integer, modifant: Partial = {}) { return dmf(FakeOtherUser, { id: userID, username: `user${userID}`, usernameLowercase: `user${userID}`, ...modifant, }); } export function mkFakeGameSettings( userID: integer, game: Game, playtype: Playtype, modifant: Partial = {} ) { return dmf(FakeGameSettings, { userID, game, playtype, ...modifant, }); } export function mkFakeImport(modifant: Partial = {}) { return dmf(FakeImport, modifant); } export function mkFakeScoreIIDXSP(modifant: Partial> = {}) { return dmf(TestingIIDXSPScore, modifant); } export function mkFakeScoreSDVX(modifant: Partial> = {}) { return dmf(TestingSDVXScore, modifant); } export function mkFakePBIIDXSP(modifant: Partial> = {}) { return dmf(TestingIIDXSPScorePB, modifant); } export function mkFakePBJubeat(modifant: Partial> = {}) { return dmf(TestingJubeatPB, modifant); } export function mkFakeNotification(modifant: Partial = {}) { return dmf(FakeNotification, modifant); } export function mkFakeGoal(modifant: Partial = {}) { return dmf(HC511Goal, modifant); } export function mkFakeGoalSub(modifant: Partial = {}) { return dmf(HC511UserGoal, modifant); } export function mkFakeGameStats(userID: integer, modifant: Partial = {}) { return dmf( { userID, game: "iidx", playtype: "SP", classes: {}, ratings: {}, }, modifant ); } export function mkFakeSDVXChart( chartID: string, modifant: Partial> = {} ) { return dmf(TestingSDVXAlbidaChart, { chartID, ...modifant, }); } export function mkFakeSDVXPB(modifant: Partial> = {}) { return dmf(TestingSDVXPB, modifant); }