sendou.ink/app/features/team/actions/t.$customUrl.edit.server.test.ts
Kalle aea1e9ce35
Toasts (#2132)
* Fix unexpected server error when trying to access non-existing tournament team page

* Fix Catcher textarea usage

* Fix unexpected server error on LFG page

* Validator for duplicate tournament team name

* initial

* Fix tests

* Success toast

* Done?

* Fix leftover
2025-03-07 22:20:29 +02:00

77 lines
1.9 KiB
TypeScript

import { afterEach, beforeEach, describe, expect, it } from "vitest";
import {
assertResponseErrored,
dbInsertUsers,
dbReset,
wrappedAction,
} from "~/utils/Test";
import { action as teamIndexPageAction } from "../actions/t.server";
import type { editTeamSchema } from "../team-schemas.server";
import type { createTeamSchema } from "../team-schemas.server";
import { action as _editTeamProfileAction } from "./t.$customUrl.edit.server";
const createTeamAction = wrappedAction<typeof createTeamSchema>({
action: teamIndexPageAction,
});
const editTeamProfileAction = wrappedAction<typeof editTeamSchema>({
action: _editTeamProfileAction,
});
const DEFAULT_FIELDS = {
_action: "EDIT",
name: "Team 1",
bio: "",
bsky: "",
} as const;
describe("team page editing", () => {
beforeEach(async () => {
await dbInsertUsers();
await createTeamAction({ name: "Team 1" }, { user: "regular" });
});
afterEach(() => {
dbReset();
});
it("adds valid custom css vars", async () => {
const response = await editTeamProfileAction(
{
css: JSON.stringify({ bg: "#fff" }),
...DEFAULT_FIELDS,
},
{ user: "regular", params: { customUrl: "team-1" } },
);
expect(response.status).toBe(302);
});
it("prevents adding custom css var of unknown property", async () => {
const response = await editTeamProfileAction(
{
css: JSON.stringify({
"backdrop-filter": "#fff",
}),
...DEFAULT_FIELDS,
},
{ user: "regular", params: { customUrl: "team-1" } },
);
assertResponseErrored(response);
});
it("prevents adding custom css var of unknown value", async () => {
const response = await editTeamProfileAction(
{
css: JSON.stringify({
bg: "url(https://sendou.ink/u?q=1&_data=features%2Fuser-search%2Froutes%2Fu)",
}),
...DEFAULT_FIELDS,
},
{ user: "regular", params: { customUrl: "team-1" } },
);
assertResponseErrored(response);
});
});