Skip to content

Commit c84ae00

Browse files
committed
fix(email): Copying test data over from sendTestEmail script to newly renovated NotifcationsDigest storybook stories
1 parent f692dcc commit c84ae00

File tree

1 file changed

+170
-116
lines changed

1 file changed

+170
-116
lines changed
Lines changed: 170 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
import { Meta, StoryObj } from "@storybook/react"
22
import digestEmail from "functions/src/email/digestEmail.handlebars"
33
import { EmailTemplateRenderer } from "./EmailTemplateRenderer"
4+
import {
5+
BillDigest,
6+
BillResult,
7+
NotificationEmailDigest,
8+
UserDigest
9+
} from "functions/src/notifications/emailTypes"
10+
import { Frequency } from "components/auth"
411

512
const meta: Meta = {
6-
title: "Email Templates/Digest",
13+
title: "Email Templates/Notifications Digest",
714
component: EmailTemplateRenderer,
815
decorators: [
916
Story => (
@@ -20,121 +27,168 @@ export default meta
2027

2128
type Story = StoryObj<typeof EmailTemplateRenderer>
2229

23-
export const DigestEmail: Story = {
24-
args: {
25-
templateSrcUrl: digestEmail,
26-
context: {
27-
notificationFrequency: "Monthly",
28-
startDate: "2/1/2023",
29-
endDate: "2/7/2023",
30-
bill: {
31-
1: {
32-
title: "H.1289",
33-
subtitle:
34-
"An Act to protect the civil rights and safety of all Massachusetts residents",
35-
testimonies: "12",
36-
cosponsors: "2",
37-
hearingDate: "Jan 31"
38-
},
39-
2: {
40-
title: "H.98",
41-
subtitle: "An Act to further govt. transparency",
42-
testimonies: "2",
43-
cosponsors: "0",
44-
hearingDate: "-"
45-
}
46-
},
47-
org: {
48-
1: {
49-
orgTitle: "Boston’s Teacher Union",
50-
userLookup: "Tfh1tp2faYbSWsYYsvUS4F23mtD2",
51-
counter: "3",
52-
item: {
53-
1: {
54-
title: "S.77",
55-
icon: "endorse"
56-
},
57-
2: {
58-
title: "S.77",
59-
icon: "neutral"
60-
},
61-
3: {
62-
title: "S.77",
63-
icon: "neutral"
64-
}
65-
}
66-
},
67-
2: {
68-
orgTitle: "Moms for Liberty",
69-
userLookup: "c31R5rjWG9eTUopP7yeA5tZQtJX2",
70-
counter: "6",
71-
item: {
72-
1: {
73-
title: "S.128",
74-
icon: "endorse"
75-
},
76-
2: {
77-
title: "S.1000",
78-
icon: "neutral"
79-
},
80-
3: {
81-
title: "S.543",
82-
icon: "oppose"
83-
},
84-
4: {
85-
title: "S.767",
86-
icon: "endorse"
87-
},
88-
5: {
89-
title: "S.992",
90-
icon: "neutral"
91-
},
92-
6: {
93-
title: "S.1",
94-
icon: "oppose"
95-
}
96-
}
97-
},
98-
3: {
99-
orgTitle: "La Le Lu Le Lo",
100-
userLookup: "8P5Ar8NyAcNEVJMTexezXvRbept2",
101-
counter: "8",
102-
item: {
103-
1: {
104-
title: "S.128",
105-
icon: "endorse"
106-
},
107-
2: {
108-
title: "S.1000",
109-
icon: "neutral"
110-
},
111-
3: {
112-
title: "S.543",
113-
icon: "oppose"
114-
},
115-
4: {
116-
title: "S.767",
117-
icon: "endorse"
118-
},
119-
5: {
120-
title: "S.992",
121-
icon: "neutral"
122-
},
123-
6: {
124-
title: "S.1",
125-
icon: "oppose"
126-
},
127-
7: {
128-
title: "S.22",
129-
icon: "oppose"
130-
},
131-
8: {
132-
title: "S.393",
133-
icon: "neutral"
134-
}
135-
}
136-
}
137-
}
30+
// Generate test data for the digest email
31+
32+
// Summary of Bills
33+
const bills: BillDigest[] = [
34+
{
35+
billId: "H868",
36+
billName:
37+
"An Act improving campaign finance reporting by state ballot question committees",
38+
billCourt: "194",
39+
endorseCount: 2,
40+
neutralCount: 0,
41+
opposeCount: 1
42+
},
43+
{
44+
billId: "H1436",
45+
billName: "An Act relative to debt-free public higher education",
46+
billCourt: "194",
47+
endorseCount: 2,
48+
neutralCount: 0,
49+
opposeCount: 0
50+
},
51+
{
52+
billId: "H533",
53+
billName: "An Act to expand the use of career and academic plans",
54+
billCourt: "194",
55+
endorseCount: 10,
56+
neutralCount: 2,
57+
opposeCount: 24
58+
},
59+
{
60+
billId: "H841",
61+
billName:
62+
"An Act granting the city of Boston the authority to endow legal voting rights in municipal elections for city of Boston residents aged 16 and 17 years old",
63+
billCourt: "194",
64+
endorseCount: 35,
65+
neutralCount: 20,
66+
opposeCount: 10
67+
},
68+
{
69+
billId: "H54",
70+
billName:
71+
"An Act to build resilient infrastructure to generate higher-ed transformation",
72+
billCourt: "194",
73+
endorseCount: 0,
74+
neutralCount: 0,
75+
opposeCount: 1
76+
}
77+
]
78+
79+
const billResults: BillResult[] = [
80+
{
81+
billId: "H868",
82+
court: "194",
83+
position: "endorse"
84+
},
85+
{
86+
billId: "H1436",
87+
court: "194",
88+
position: "neutral"
89+
},
90+
{
91+
billId: "H533",
92+
court: "194",
93+
position: "oppose"
94+
},
95+
{
96+
billId: "H841",
97+
court: "194",
98+
position: "endorse"
99+
},
100+
{
101+
billId: "H54",
102+
court: "194",
103+
position: "oppose"
104+
},
105+
{
106+
billId: "H66",
107+
court: "194",
108+
position: "neutral"
109+
},
110+
{
111+
billId: "H30",
112+
court: "194",
113+
position: "endorse"
114+
}
115+
]
116+
117+
const generateTestUserData = (
118+
userId: string,
119+
userName: string,
120+
numBillsWithTestimony: number
121+
): UserDigest => {
122+
return {
123+
userId,
124+
userName,
125+
bills: billResults.slice(0, Math.min(6, numBillsWithTestimony)),
126+
newTestimonyCount: numBillsWithTestimony
127+
}
128+
}
129+
130+
const users = [
131+
generateTestUserData("0BvO7rSlFjRVHuLfd7RlHRYg2DN1", "John Doe", 7),
132+
generateTestUserData("2jBTpZQ1kXVVSaJvLy2mxfduoc64", "Jane Roe", 6),
133+
generateTestUserData(
134+
"381slAnGbzP6atlF4Af4D9pYQT24",
135+
"Society for the Humane Prevention of Testimony",
136+
5
137+
),
138+
generateTestUserData("Nyvk23VDNQSoK9TQ9LK5xF1DwT64", "Person McPersonson", 4),
139+
generateTestUserData("QDPq42rNB0O6wqVzfMmDHmNE8sN3", "Iranout Ofnameideas", 3)
140+
]
141+
142+
const generateTestData = (
143+
frequency: Frequency,
144+
numBills: number,
145+
numUsers: number
146+
): NotificationEmailDigest => {
147+
return {
148+
notificationFrequency: frequency,
149+
startDate: new Date("2025-04-01T04:00:00Z"),
150+
endDate: new Date(
151+
`2025-04-${frequency === "Monthly" ? "30" : "07"}T04:00:00Z`
152+
),
153+
bills: bills.slice(0, Math.min(4, numBills)),
154+
users: users.slice(0, Math.min(4, numUsers)),
155+
numBillsWithNewTestimony: numBills,
156+
numUsersWithNewTestimony: numUsers
157+
}
158+
}
159+
160+
// Frequency is guaranteed to be Monthly or Weekly,
161+
// and there must be at least 1 bill OR 1 user with testimony
162+
// or else a digest wouldn't be generated
163+
const createDigestStory = (context: NotificationEmailDigest) => {
164+
return {
165+
args: {
166+
templateSrcUrl: digestEmail,
167+
context
138168
}
139169
}
140170
}
171+
172+
export const FullDigest: Story = createDigestStory(
173+
generateTestData("Monthly", 4, 4)
174+
)
175+
176+
export const OnlyBills: Story = createDigestStory(
177+
generateTestData("Weekly", 4, 0)
178+
)
179+
180+
export const OnlyUsers: Story = createDigestStory(
181+
generateTestData("Weekly", 0, 4)
182+
)
183+
184+
export const TooManyBills: Story = createDigestStory(
185+
generateTestData("Monthly", 100, 0)
186+
)
187+
188+
export const TooManyUsers: Story = createDigestStory(
189+
generateTestData("Monthly", 0, 100)
190+
)
191+
192+
export const TooManyBillsAndUsers: Story = createDigestStory(
193+
generateTestData("Monthly", 100, 100)
194+
)

0 commit comments

Comments
 (0)