hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits
| 1 | import type { Appointment, AppointmentStatus } from "@/api/client"; |
| 2 | import { appointmentActions, hasStandingProposal } from "./appointment-actions"; |
| 3 | |
| 4 | const NOW = 1_800_000_000_000; |
| 5 | const FUTURE = NOW + 60 * 60 * 1000; |
| 6 | const PAST = NOW - 60 * 60 * 1000; |
| 7 | |
| 8 | const appt = (status: AppointmentStatus, opts: { proposed?: boolean; startsAt?: number | null } = {}): Appointment => |
| 9 | ({ |
| 10 | id: "a1", |
| 11 | slot: "s1", |
| 12 | teacher: null, |
| 13 | requester: { id: "u1", username: "ali", display_name: null }, |
| 14 | status, |
| 15 | reason: "ödev", |
| 16 | starts_at: opts.startsAt === undefined ? FUTURE : opts.startsAt, |
| 17 | ends_at: FUTURE + 1000, |
| 18 | proposed_starts_at: opts.proposed ? FUTURE : null, |
| 19 | proposed_ends_at: opts.proposed ? FUTURE + 1000 : null, |
| 20 | proposed_by: null, |
| 21 | decided_by: null, |
| 22 | cancelled_by: null, |
| 23 | cancel_reason: null, |
| 24 | reject_reason: null, |
| 25 | created_at: PAST, |
| 26 | }) as Appointment; |
| 27 | |
| 28 | it("counts a proposal as standing only while the row is still pending", () => { |
| 29 | expect(hasStandingProposal(appt("pending", { proposed: true }))).toBe(true); |
| 30 | // The backend never clears proposed_* on accept — an approved row with a |
| 31 | // proposal is an ANSWERED one, so the teacher keeps their reschedule action. |
| 32 | expect(hasStandingProposal(appt("approved", { proposed: true }))).toBe(false); |
| 33 | expect(hasStandingProposal(appt("cancelled", { proposed: true }))).toBe(false); |
| 34 | }); |
| 35 | |
| 36 | it("offers staff exactly what the backend accepts", () => { |
| 37 | expect(appointmentActions(appt("pending"), "staff", NOW)).toEqual(["approve", "reject", "reschedule"]); |
| 38 | // Standing proposal: no self-approval of one's own counter-proposal, but the |
| 39 | // teacher can still withdraw it (reject) or propose again. |
| 40 | expect(appointmentActions(appt("pending", { proposed: true }), "staff", NOW)).toEqual(["reject", "reschedule"]); |
| 41 | // Answered proposal: reschedule must come back (the old `proposed_* != null` |
| 42 | // gate lost it forever after one accepted reschedule). |
| 43 | expect(appointmentActions(appt("approved", { proposed: true }), "staff", NOW)).toEqual(["reschedule"]); |
| 44 | expect(appointmentActions(appt("approved"), "staff", NOW)).toEqual(["reschedule"]); |
| 45 | // Window opened: approve 409s ("that time has already started"), reject does not. |
| 46 | expect(appointmentActions(appt("pending", { startsAt: PAST }), "staff", NOW)).toEqual(["reject", "reschedule"]); |
| 47 | expect(appointmentActions(appt("rejected"), "staff", NOW)).toEqual([]); |
| 48 | expect(appointmentActions(appt("cancelled"), "staff", NOW)).toEqual([]); |
| 49 | }); |
| 50 | |
| 51 | it("offers the requester exactly what the backend accepts", () => { |
| 52 | expect(appointmentActions(appt("pending"), "requester", NOW)).toEqual(["cancel"]); |
| 53 | expect(appointmentActions(appt("approved"), "requester", NOW)).toEqual(["cancel"]); |
| 54 | expect(appointmentActions(appt("pending", { proposed: true }), "requester", NOW)).toEqual([ |
| 55 | "acceptReschedule", |
| 56 | "declineReschedule", |
| 57 | ]); |
| 58 | // Started windows: cancel/accept/decline all 409. |
| 59 | expect(appointmentActions(appt("approved", { startsAt: PAST }), "requester", NOW)).toEqual([]); |
| 60 | expect(appointmentActions(appt("pending", { proposed: true, startsAt: PAST }), "requester", NOW)).toEqual([]); |
| 61 | // Slot vanished -> every call 404s. |
| 62 | expect(appointmentActions(appt("pending", { startsAt: null }), "requester", NOW)).toEqual([]); |
| 63 | expect(appointmentActions(appt("cancelled"), "requester", NOW)).toEqual([]); |
| 64 | expect(appointmentActions(appt("rejected"), "requester", NOW)).toEqual([]); |
| 65 | }); |