Files
sendou.ink/app/features/availability/availability-schemas.test.ts
Kalle 9b82d577e2
Some checks failed
E2E Tests / e2e (push) Has been cancelled
Tests and checks on push / run-checks-and-tests (push) Has been cancelled
Updates translation progress / update-translation-progress-issue (push) Has been cancelled
Availability tool (#3375)
2026-08-30 17:35:14 +03:00

48 lines
1.4 KiB
TypeScript

import * as R from "remeda";
import * as v from "valibot";
import { describe, expect, test } from "vitest";
import { saveWeekSchema } from "./availability-schemas";
const DAY_MINUTES = 24 * 60;
const weekWith = (ranges: Array<{ start: number; end: number }>) => ({
_action: "SAVE_WEEK" as const,
days: R.range(0, 7).map((dayIndex) => ({
date: `2026-08-${String(24 + dayIndex).padStart(2, "0")}`,
ranges: dayIndex === 0 ? ranges : [],
note: "",
})),
});
describe("saveWeekSchema", () => {
test.each([
{ why: "a range ending when it starts", start: 600, end: 600 },
{ why: "a range ending before it starts", start: 600, end: 540 },
{
why: "a range longer than a day",
start: 60,
end: 60 + DAY_MINUTES + 30,
},
{ why: "a range ending past the next day", start: 1380, end: 2881 },
])("rejects $why", ({ start, end }) => {
expect(
v.safeParse(saveWeekSchema, weekWith([{ start, end }])).success,
).toBe(false);
});
test.each([
{ why: "a range within one day", start: 600, end: 720 },
{ why: "a range crossing midnight", start: 1380, end: 1500 },
{ why: "a range exactly a day long", start: 0, end: DAY_MINUTES },
{
why: "the last minute a range can start",
start: DAY_MINUTES - 1,
end: DAY_MINUTES,
},
])("accepts $why", ({ start, end }) => {
expect(
v.safeParse(saveWeekSchema, weekWith([{ start, end }])).success,
).toBe(true);
});
});