forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiBc35a83aBurak Boduroğlu4 months ago440 commits

meals.test.ts37 lines, 1.4 KiBHistoryRawDownload
1import { describe, expect, it } from "vitest";
2import type { SchoolSettings } from "@/api/client";
3import { dirtySettingsPatch, formatTry, mealCutoffAt, minuteToUtcTime, nextCourseWork, utcTimeToMinute } from "./meals";
4
5describe("meal helpers", () => {
6 it("formats minor units as TRY", () => {
7 expect(formatTry(4550, "tr-TR")).toContain("45,50");
8 });
9
10 it("converts UTC minute values", () => {
11 expect(minuteToUtcTime(540)).toBe("09:00");
12 expect(utcTimeToMinute("23:59")).toBe(1439);
13 expect(utcTimeToMinute("24:00")).toBeNull();
14 });
15
16 it("calculates the booking cutoff in UTC", () => {
17 expect(mealCutoffAt("2026-07-28", { name: "lunch", serving_minute: 720 }, 120))
18 .toBe(Date.parse("2026-07-28T10:00:00Z"));
19 });
20
21 it("selects nearest course work", () => {
22 expect(nextCourseWork(
23 "c1",
24 [{ course: "c1", title: "Exam", starts_at: 30 } as never],
25 [{ course: "c1", title: "Homework", due_at: 20 } as never],
26 )?.title).toBe("Homework");
27 });
28
29 it("builds a field-only settings patch", () => {
30 const before = {
31 exam_kinds: [], attendance_statuses: [], grade_bands: [], max_file_bytes: 1,
32 chatbot_history_turns: 1, max_chatbot_threads: 1, max_chatbot_message_len: 100,
33 meal_slots: [], dietary_tags: [], meal_cancel_cutoff_minutes: null,
34 } satisfies SchoolSettings;
35 expect(dirtySettingsPatch(before, { ...before, max_chatbot_threads: 2 })).toEqual({ max_chatbot_threads: 2 });
36 });
37});