Skip to content

Commit 09084b6

Browse files
committed
Add tests for messages
1 parent 59296ed commit 09084b6

5 files changed

Lines changed: 220 additions & 1 deletion

File tree

test/items/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
filterOutStatus,
1010
filterUpcomingItems,
1111
} from "@src/items";
12-
import { itemFactory } from "./factories/itemFactory";
12+
import { itemFactory } from "../factories/itemFactory";
1313

1414
describe("filterByStatus", () => {
1515
it("will return items with the given status", () => {
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import { completeTaskReportMessage } from "@src/reminders/messages";
2+
import { itemFactory } from "../../factories/itemFactory";
3+
import { Item } from "@src/items";
4+
5+
describe("completeTaskReportMessage", () => {
6+
it("will show the default message when there are no urgent or unassigned items", () => {
7+
const urgentItems: Item[] = [];
8+
const unassignedItems: Item[] = [];
9+
const upcomingItems: Item[] = [itemFactory()];
10+
11+
const result = completeTaskReportMessage({
12+
urgentItems,
13+
unassignedItems,
14+
upcomingItems,
15+
});
16+
17+
expect(result.title).toBe("Biweekly Tasks Reminder ☀️🌱");
18+
expect(result.message).toBe("Nothing urgent or unassigned upcoming! 🐀🥂");
19+
expect(result.sections).toEqual([
20+
{
21+
title: "📅 Assigned Items",
22+
items: upcomingItems,
23+
includeLinks: false,
24+
},
25+
]);
26+
});
27+
28+
it("will include the urgent section when there are urgent items", () => {
29+
const urgentItems: Item[] = [itemFactory()];
30+
const unassignedItems: Item[] = [];
31+
const upcomingItems: Item[] = [];
32+
33+
const result = completeTaskReportMessage({
34+
urgentItems,
35+
unassignedItems,
36+
upcomingItems,
37+
});
38+
39+
expect(result.message).toContain("Check out all upcoming tasks");
40+
expect(result.sections).toEqual([
41+
{
42+
title: "🔥 Urgent & Overdue",
43+
items: urgentItems,
44+
includeLinks: true,
45+
},
46+
]);
47+
});
48+
49+
it("will include the unassigned section when there are unassigned items", () => {
50+
const urgentItems: Item[] = [];
51+
const unassignedItems: Item[] = [itemFactory()];
52+
const upcomingItems: Item[] = [];
53+
54+
const result = completeTaskReportMessage({
55+
urgentItems,
56+
unassignedItems,
57+
upcomingItems,
58+
});
59+
60+
expect(result.sections).toEqual([
61+
{
62+
title: "📥 Unassigned Items",
63+
items: unassignedItems,
64+
includeLinks: false,
65+
},
66+
]);
67+
});
68+
69+
it("includes all sections when all item types are present", () => {
70+
const urgentItems: Item[] = [itemFactory()];
71+
const unassignedItems: Item[] = [itemFactory()];
72+
const upcomingItems: Item[] = [itemFactory()];
73+
74+
const result = completeTaskReportMessage({
75+
urgentItems,
76+
unassignedItems,
77+
upcomingItems,
78+
});
79+
80+
expect(result.sections).toEqual([
81+
{
82+
title: "🔥 Urgent & Overdue",
83+
items: urgentItems,
84+
includeLinks: true,
85+
},
86+
{
87+
title: "📅 Assigned Items",
88+
items: upcomingItems,
89+
includeLinks: false,
90+
},
91+
{
92+
title: "📥 Unassigned Items",
93+
items: unassignedItems,
94+
includeLinks: false,
95+
},
96+
]);
97+
});
98+
99+
it("returns no sections and default message when all item arrays are empty", () => {
100+
const result = completeTaskReportMessage({
101+
urgentItems: [],
102+
unassignedItems: [],
103+
upcomingItems: [],
104+
});
105+
106+
expect(result.message).toBe(
107+
"Check out all upcoming tasks [here.](https://github.com/orgs/CarletonComputerScienceSociety/projects/18) 🐀🐀",
108+
);
109+
expect(result.sections).toEqual([]);
110+
});
111+
});
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import { describe, expect, it, jest } from "@jest/globals";
2+
import { simpleTaskReportMessage } from "@src/reminders/messages";
3+
import { itemFactory } from "../../factories/itemFactory";
4+
5+
// Mock @src/constants and override EMOJIS
6+
jest.mock("@src/constants", () => ({
7+
EMOJIS: ["🧪"],
8+
}));
9+
10+
describe("simpleTaskReportMessage", () => {
11+
it("will return default message when both urgent and unassigned are empty", () => {
12+
const result = simpleTaskReportMessage({
13+
urgentItems: [],
14+
unassignedItems: [],
15+
});
16+
17+
expect(result.title).toBe("Daily Task Reminder 🧪");
18+
expect(result.message).toBe("Nothing urgent or unassigned today! 🐀🥂");
19+
expect(result.sections).toEqual([]);
20+
});
21+
22+
it("will include urgent section when there are urgent items", () => {
23+
const urgent = [itemFactory()];
24+
25+
const result = simpleTaskReportMessage({
26+
urgentItems: urgent,
27+
unassignedItems: [],
28+
});
29+
30+
expect(result.message).toContain("Check out all upcoming tasks");
31+
expect(result.sections).toEqual([
32+
{
33+
title: "🔥 Urgent & Overdue",
34+
items: urgent,
35+
includeLinks: true,
36+
},
37+
]);
38+
});
39+
40+
it("will include unassigned section when there are unassigned items", () => {
41+
const unassigned = [itemFactory()];
42+
43+
const result = simpleTaskReportMessage({
44+
urgentItems: [],
45+
unassignedItems: unassigned,
46+
});
47+
48+
expect(result.sections).toEqual([
49+
{
50+
title: "📥 Unassigned Items",
51+
items: unassigned,
52+
includeLinks: false,
53+
},
54+
]);
55+
});
56+
57+
it("will include both sections when both item types are present", () => {
58+
const urgent = [itemFactory()];
59+
const unassigned = [itemFactory()];
60+
61+
const result = simpleTaskReportMessage({
62+
urgentItems: urgent,
63+
unassignedItems: unassigned,
64+
});
65+
66+
expect(result.sections).toEqual([
67+
{
68+
title: "🔥 Urgent & Overdue",
69+
items: urgent,
70+
includeLinks: true,
71+
},
72+
{
73+
title: "📥 Unassigned Items",
74+
items: unassigned,
75+
includeLinks: false,
76+
},
77+
]);
78+
});
79+
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { describe, expect, it } from "@jest/globals";
2+
import { urgentPromotionMessage } from "@src/reminders/messages";
3+
import { itemFactory } from "../../factories/itemFactory";
4+
5+
describe("urgentPromotionMessage", () => {
6+
it("will return message without sections when there are no promotion items", () => {
7+
const result = urgentPromotionMessage({ promotionItems: [] });
8+
9+
expect(result.title).toBe("Urgent Promotional Items Reminder 📬‼️");
10+
expect(result.message).toBe(
11+
"Check out all upcoming tasks [here.](https://github.com/orgs/CarletonComputerScienceSociety/projects/18) 🦆"
12+
);
13+
expect(result.sections).toEqual([]);
14+
});
15+
16+
it("will include promotion section when promotion items are present", () => {
17+
const promotionItems = [itemFactory(), itemFactory()];
18+
19+
const result = urgentPromotionMessage({ promotionItems });
20+
21+
expect(result.sections).toEqual([
22+
{
23+
title: "🔔 Urgent Promotion Items",
24+
items: promotionItems,
25+
includeLinks: true,
26+
},
27+
]);
28+
});
29+
});

0 commit comments

Comments
 (0)