sendou.ink/app/features/user-page/routes/u.$identifier.edit.test.ts
Kalle 77978c450f
Some checks are pending
E2E Tests / e2e (push) Waiting to run
Tests and checks on push / run-checks-and-tests (push) Waiting to run
Updates translation progress / update-translation-progress-issue (push) Waiting to run
New user page (#2812)
Co-authored-by: hfcRed <hfcred@gmx.net>
2026-02-16 19:26:57 +02:00

81 lines
2.0 KiB
TypeScript

import { afterEach, beforeEach, describe, expect, it } from "vitest";
import type { MainWeaponId } from "~/modules/in-game-lists/types";
import { dbInsertUsers, dbReset, wrappedAction } from "~/utils/Test";
import type { userEditActionSchema } from "../user-page-schemas";
import { action as editUserProfileAction } from "./u.$identifier.edit";
const action = wrappedAction<typeof userEditActionSchema>({
action: editUserProfileAction,
});
const DEFAULT_FIELDS = {
battlefy: null,
bio: null,
commissionsOpen: 1,
commissionText: null,
country: "FI",
customName: null,
customUrl: null,
favoriteBadgeIds: null,
inGameNameDiscriminator: null,
inGameNameText: null,
motionSens: null,
showDiscordUniqueName: 1,
newProfileEnabled: 0,
stickSens: null,
subjectPronoun: null,
objectPronoun: null,
weapons: JSON.stringify([
{ weaponSplId: 1 as MainWeaponId, isFavorite: 0 },
]) as any,
};
describe("user page editing", () => {
beforeEach(async () => {
await dbInsertUsers();
});
afterEach(() => {
dbReset();
});
it("adds valid custom css vars", async () => {
const response = await action(
{
css: JSON.stringify({ bg: "#fff" }),
...DEFAULT_FIELDS,
},
{ user: "regular", params: { identifier: "2" } },
);
expect(response.status).toBe(302);
});
it("prevents adding custom css var of unknown property", async () => {
const res = await action(
{
css: JSON.stringify({
"backdrop-filter": "#fff",
}),
...DEFAULT_FIELDS,
},
{ user: "regular", params: { identifier: "2" } },
);
expect(res.errors[0]).toBe("Invalid custom CSS var object");
});
it("prevents adding custom css var of unknown value", async () => {
const res = await action(
{
css: JSON.stringify({
bg: "url(https://sendou.ink/u?q=1&_data=features%2Fuser-search%2Froutes%2Fu)",
}),
...DEFAULT_FIELDS,
},
{ user: "regular", params: { identifier: "2" } },
);
expect(res.errors[0]).toBe("Invalid custom CSS var object");
});
});