mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-07-30 15:53:59 -05:00
66 lines
1.9 KiB
TypeScript
66 lines
1.9 KiB
TypeScript
import { beforeEach, describe, expect, test } from "vitest";
|
|
import * as UserFactory from "~/db/seed/factories/UserFactory";
|
|
import type { UserMapModePreferences } from "~/db/tables-json";
|
|
import { withUserId } from "~/utils/Test";
|
|
import * as MatchProfileRepository from "./MatchProfileRepository.server";
|
|
|
|
let userId: number;
|
|
|
|
const PREFERENCES: UserMapModePreferences = {
|
|
modes: [{ mode: "SZ", preference: "PREFER" }],
|
|
pool: [{ mode: "SZ", stages: [1, 2, 3, 4] }],
|
|
};
|
|
|
|
const OTHER_PREFERENCES: UserMapModePreferences = {
|
|
modes: [{ mode: "SZ", preference: "PREFER" }],
|
|
pool: [{ mode: "SZ", stages: [5, 6, 7, 8] }],
|
|
};
|
|
|
|
const updateProfile = (
|
|
args: Partial<
|
|
Parameters<typeof MatchProfileRepository.updateOwnMatchProfile>[0]
|
|
> = {},
|
|
) =>
|
|
withUserId(userId, () =>
|
|
MatchProfileRepository.updateOwnMatchProfile({
|
|
mapModePreferences: PREFERENCES,
|
|
vc: "NO",
|
|
languages: [],
|
|
weaponPool: [],
|
|
noScreen: 0,
|
|
...args,
|
|
}),
|
|
);
|
|
|
|
describe("updateOwnMatchProfile", () => {
|
|
beforeEach(async () => {
|
|
const user = await UserFactory.create(null, {
|
|
matchProfile: { mapModePreferences: PREFERENCES, noScreen: 0 },
|
|
});
|
|
userId = user.id;
|
|
});
|
|
|
|
test("reports no change when nothing matchmaking-relevant changed", async () => {
|
|
const result = await updateProfile({ vc: "YES", languages: ["en"] });
|
|
|
|
expect(result.mapModePreferencesChanged).toBe(false);
|
|
expect(result.noScreenChanged).toBe(false);
|
|
});
|
|
|
|
test("detects a noScreen change", async () => {
|
|
const result = await updateProfile({ noScreen: 1 });
|
|
|
|
expect(result.noScreenChanged).toBe(true);
|
|
expect(result.mapModePreferencesChanged).toBe(false);
|
|
});
|
|
|
|
test("detects a map/mode preferences change", async () => {
|
|
const result = await updateProfile({
|
|
mapModePreferences: OTHER_PREFERENCES,
|
|
});
|
|
|
|
expect(result.mapModePreferencesChanged).toBe(true);
|
|
expect(result.noScreenChanged).toBe(false);
|
|
});
|
|
});
|