馃 distributed transcription service
thistle.dunkirk.sh
1import { describe, expect, test } from "bun:test";
2import {
3 findMatchingMeetingTime,
4 getDayName,
5 getDayOfWeek,
6 meetingTimeLabelMatchesDay,
7} from "./audio-metadata";
8
9describe("getDayOfWeek", () => {
10 test("returns correct day number", () => {
11 // January 1, 2024 is a Monday (day 1)
12 const monday = new Date("2024-01-01T12:00:00Z");
13 expect(getDayOfWeek(monday)).toBe(1);
14
15 // January 7, 2024 is a Sunday (day 0)
16 const sunday = new Date("2024-01-07T12:00:00Z");
17 expect(getDayOfWeek(sunday)).toBe(0);
18
19 // January 6, 2024 is a Saturday (day 6)
20 const saturday = new Date("2024-01-06T12:00:00Z");
21 expect(getDayOfWeek(saturday)).toBe(6);
22 });
23});
24
25describe("getDayName", () => {
26 test("returns correct day name", () => {
27 expect(getDayName(new Date("2024-01-01T12:00:00Z"))).toBe("Monday");
28 expect(getDayName(new Date("2024-01-02T12:00:00Z"))).toBe("Tuesday");
29 expect(getDayName(new Date("2024-01-03T12:00:00Z"))).toBe("Wednesday");
30 expect(getDayName(new Date("2024-01-04T12:00:00Z"))).toBe("Thursday");
31 expect(getDayName(new Date("2024-01-05T12:00:00Z"))).toBe("Friday");
32 expect(getDayName(new Date("2024-01-06T12:00:00Z"))).toBe("Saturday");
33 expect(getDayName(new Date("2024-01-07T12:00:00Z"))).toBe("Sunday");
34 });
35});
36
37describe("meetingTimeLabelMatchesDay", () => {
38 test("matches full day names", () => {
39 expect(meetingTimeLabelMatchesDay("Monday Lecture", "Monday")).toBe(true);
40 expect(meetingTimeLabelMatchesDay("Tuesday Lab", "Tuesday")).toBe(true);
41 expect(meetingTimeLabelMatchesDay("Wednesday Discussion", "Wednesday")).toBe(
42 true,
43 );
44 });
45
46 test("matches 3-letter abbreviations", () => {
47 expect(meetingTimeLabelMatchesDay("Mon Lecture", "Monday")).toBe(true);
48 expect(meetingTimeLabelMatchesDay("Tue Lab", "Tuesday")).toBe(true);
49 expect(meetingTimeLabelMatchesDay("Wed Discussion", "Wednesday")).toBe(
50 true,
51 );
52 expect(meetingTimeLabelMatchesDay("Thu Seminar", "Thursday")).toBe(true);
53 expect(meetingTimeLabelMatchesDay("Fri Workshop", "Friday")).toBe(true);
54 expect(meetingTimeLabelMatchesDay("Sat Review", "Saturday")).toBe(true);
55 expect(meetingTimeLabelMatchesDay("Sun Study", "Sunday")).toBe(true);
56 });
57
58 test("is case insensitive", () => {
59 expect(meetingTimeLabelMatchesDay("MONDAY LECTURE", "Monday")).toBe(true);
60 expect(meetingTimeLabelMatchesDay("monday lecture", "Monday")).toBe(true);
61 expect(meetingTimeLabelMatchesDay("MoNdAy LeCTuRe", "Monday")).toBe(true);
62 });
63
64 test("does not match wrong days", () => {
65 expect(meetingTimeLabelMatchesDay("Monday Lecture", "Tuesday")).toBe(false);
66 expect(meetingTimeLabelMatchesDay("Wednesday Lab", "Thursday")).toBe(false);
67 expect(meetingTimeLabelMatchesDay("Lecture Hall A", "Monday")).toBe(false);
68 });
69
70 test("handles labels without day names", () => {
71 expect(meetingTimeLabelMatchesDay("Lecture", "Monday")).toBe(false);
72 expect(meetingTimeLabelMatchesDay("Lab Session", "Tuesday")).toBe(false);
73 expect(meetingTimeLabelMatchesDay("Section A", "Wednesday")).toBe(false);
74 });
75});
76
77describe("findMatchingMeetingTime", () => {
78 const meetingTimes = [
79 { id: "mt1", label: "Monday Lecture" },
80 { id: "mt2", label: "Wednesday Discussion" },
81 { id: "mt3", label: "Friday Lab" },
82 ];
83
84 test("finds correct meeting time for full day name", () => {
85 const monday = new Date("2024-01-01T12:00:00Z"); // Monday
86 expect(findMatchingMeetingTime(monday, meetingTimes)).toBe("mt1");
87
88 const wednesday = new Date("2024-01-03T12:00:00Z"); // Wednesday
89 expect(findMatchingMeetingTime(wednesday, meetingTimes)).toBe("mt2");
90
91 const friday = new Date("2024-01-05T12:00:00Z"); // Friday
92 expect(findMatchingMeetingTime(friday, meetingTimes)).toBe("mt3");
93 });
94
95 test("finds correct meeting time for abbreviated day name", () => {
96 const abbrevMeetingTimes = [
97 { id: "mt1", label: "Mon Lecture" },
98 { id: "mt2", label: "Wed Discussion" },
99 { id: "mt3", label: "Fri Lab" },
100 ];
101
102 const monday = new Date("2024-01-01T12:00:00Z");
103 expect(findMatchingMeetingTime(monday, abbrevMeetingTimes)).toBe("mt1");
104 });
105
106 test("returns null when no match found", () => {
107 const tuesday = new Date("2024-01-02T12:00:00Z"); // Tuesday
108 expect(findMatchingMeetingTime(tuesday, meetingTimes)).toBe(null);
109
110 const saturday = new Date("2024-01-06T12:00:00Z"); // Saturday
111 expect(findMatchingMeetingTime(saturday, meetingTimes)).toBe(null);
112 });
113
114 test("returns null for empty meeting times", () => {
115 const monday = new Date("2024-01-01T12:00:00Z");
116 expect(findMatchingMeetingTime(monday, [])).toBe(null);
117 });
118
119 test("returns first match when multiple matches exist", () => {
120 const duplicateMeetingTimes = [
121 { id: "mt1", label: "Monday Lecture" },
122 { id: "mt2", label: "Monday Lab" },
123 ];
124
125 const monday = new Date("2024-01-01T12:00:00Z");
126 expect(findMatchingMeetingTime(monday, duplicateMeetingTimes)).toBe("mt1");
127 });
128});