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, UGPTSettingsDocument, UserGameStats, GPTString, ScoreData, } from "tachi-common"; import type { DeepPartial } from "utils/types"; /** * 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: DeepPartial): T { // @ts-expect-error LOLDEEPMERGETYPES 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: DeepPartial = {}) { return dmf(FakeOtherUser, { id: userID, username: `user${userID}`, usernameLowercase: `user${userID}`, ...modifant, }); } export function mkFakeGameSettings( userID: integer, game: Game, playtype: Playtype, modifant: DeepPartial = {} ) { return dmf(FakeGameSettings, { userID, game, playtype, ...modifant, }); } export function mkFakeImport(modifant: DeepPartial = {}) { return dmf(FakeImport, modifant); } export function mkFakeScoreIIDXSP(modifant: DeepPartial> = {}) { return dmf(TestingIIDXSPScore, modifant); } export function mkFakeScoreSDVX(modifant: DeepPartial> = {}) { return dmf(TestingSDVXScore, modifant); } export function mkFakePBIIDXSP(modifant: DeepPartial> = {}) { return dmf(TestingIIDXSPScorePB, modifant); } export function mkFakePBJubeat(modifant: DeepPartial> = {}) { return dmf(TestingJubeatPB, modifant); } export function mkFakeNotification(modifant: DeepPartial = {}) { return dmf(FakeNotification, modifant); } export function mkFakeGoal(modifant: DeepPartial = {}) { return dmf(HC511Goal, modifant); } export function mkFakeGoalSub(modifant: DeepPartial = {}) { return dmf(HC511UserGoal, modifant); } export function mkFakeGameStats( userID: integer, modifant: DeepPartial = {} ): UserGameStats { return dmf( { userID, game: "iidx", playtype: "SP", classes: {}, ratings: {}, }, // @ts-expect-error idk lol types modifant ); } export function mkFakeSDVXChart( chartID: string, modifant: DeepPartial> = {} ) { return dmf(TestingSDVXAlbidaChart, { chartID, ...modifant, }); } export function mkFakeSDVXPB(modifant: DeepPartial> = {}) { return dmf(TestingSDVXPB, modifant); } export function mkMockPB( game: Game, playtype: Playtype, chart: ChartDocument, scoreData: ScoreData ): PBScoreDocument { return { userID: 1, composedFrom: [{ name: "Best Percent", scoreID: `TEST_${game}:${playtype}_SCORE` }], game, playtype, highlight: false, isPrimary: true, rankingData: { outOf: 1, rank: 1, rivalRank: null }, songID: chart.songID, chartID: chart.chartID, calculatedData: {}, scoreData, timeAchieved: null, }; } export function mkMockScore( game: Game, playtype: Playtype, chart: ChartDocument, scoreData: ScoreData ): ScoreDocument { // @ts-expect-error whatever lol return { userID: 1, game, playtype, highlight: false, isPrimary: true, songID: chart.songID, chartID: chart.chartID, calculatedData: {}, scoreData, timeAchieved: null, comment: null, importType: null, scoreID: `TEST_${game}:${playtype}_SCORE`, scoreMeta: {}, service: "TESTING", timeAdded: 1, }; }