Skip to content

Commit 4fe98a6

Browse files
committed
Adding test data, moving email types out of functions/src/email to avoid issues with copy-handlebars
1 parent 5d08304 commit 4fe98a6

File tree

4 files changed

+149
-12
lines changed

4 files changed

+149
-12
lines changed

functions/src/notifications/deliverNotifications.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
NotificationEmailDigest,
1212
Position,
1313
UserDigest
14-
} from "../email/types"
14+
} from "./emailTypes"
1515
import { prepareHandlebars } from "../email/handlebarsHelpers"
1616
import { getAuth } from "firebase-admin/auth"
1717
import { Frequency } from "../auth/types"

next-env.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
/// <reference types="next/image-types/global" />
33

44
// NOTE: This file should not be edited
5-
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.
5+
// see https://nextjs.org/docs/basic-features/typescript for more information.

scripts/firebase-admin/sendTestEmail.ts

Lines changed: 147 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@ import * as fs from "fs"
33
import { Script } from "./types"
44
import * as helpers from "../../functions/src/email/helpers"
55

6-
import { NotificationEmailDigest } from "functions/src/email/types"
6+
import {
7+
BillDigest,
8+
BillResult,
9+
NotificationEmailDigest,
10+
UserDigest
11+
} from "functions/src/notifications/emailTypes"
712
import { Record, String } from "runtypes"
813
import { Timestamp } from "functions/src/firebase"
14+
import { Frequency } from "components/auth"
915

1016
const path = require("path")
1117

@@ -55,21 +61,152 @@ const renderToHtmlString = (digestData: NotificationEmailDigest) => {
5561
return compiledTemplate({ digestData })
5662
}
5763

64+
// Summary of Bills
65+
const bills: BillDigest[] = [
66+
{
67+
billId: "H868",
68+
billName:
69+
"An Act improving campaign finance reporting by state ballot question committees",
70+
billCourt: "194",
71+
endorseCount: 2,
72+
neutralCount: 0,
73+
opposeCount: 1
74+
},
75+
{
76+
billId: "H1436",
77+
billName: "An Act relative to debt-free public higher education",
78+
billCourt: "194",
79+
endorseCount: 2,
80+
neutralCount: 0,
81+
opposeCount: 0
82+
},
83+
{
84+
billId: "H533",
85+
billName: "An Act to expand the use of career and academic plans",
86+
billCourt: "194",
87+
endorseCount: 10,
88+
neutralCount: 2,
89+
opposeCount: 24
90+
},
91+
{
92+
billId: "H841",
93+
billName:
94+
"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",
95+
billCourt: "194",
96+
endorseCount: 35,
97+
neutralCount: 20,
98+
opposeCount: 10
99+
},
100+
{
101+
billId: "H54",
102+
billName:
103+
"An Act to build resilient infrastructure to generate higher-ed transformation",
104+
billCourt: "194",
105+
endorseCount: 0,
106+
neutralCount: 0,
107+
opposeCount: 1
108+
}
109+
]
110+
111+
const billResults: BillResult[] = [
112+
{
113+
billId: "H868",
114+
court: "194",
115+
position: "endorse"
116+
},
117+
{
118+
billId: "H1436",
119+
court: "194",
120+
position: "neutral"
121+
},
122+
{
123+
billId: "H533",
124+
court: "194",
125+
position: "oppose"
126+
},
127+
{
128+
billId: "H841",
129+
court: "194",
130+
position: "endorse"
131+
},
132+
{
133+
billId: "H54",
134+
court: "194",
135+
position: "oppose"
136+
},
137+
{
138+
billId: "H66",
139+
court: "194",
140+
position: "neutral"
141+
},
142+
{
143+
billId: "H30",
144+
court: "194",
145+
position: "endorse"
146+
}
147+
]
148+
149+
const generateTestUserData = (
150+
userId: string,
151+
userName: string,
152+
numBillsWithTestimony: number
153+
): UserDigest => {
154+
return {
155+
userId,
156+
userName,
157+
bills: billResults.slice(0, Math.min(6, numBillsWithTestimony)),
158+
newTestimonyCount: numBillsWithTestimony
159+
}
160+
}
161+
162+
const users = [
163+
generateTestUserData("0BvO7rSlFjRVHuLfd7RlHRYg2DN1", "John Doe", 7),
164+
generateTestUserData("2jBTpZQ1kXVVSaJvLy2mxfduoc64", "Jane Roe", 6),
165+
generateTestUserData(
166+
"381slAnGbzP6atlF4Af4D9pYQT24",
167+
"Society for the Humane Prevention of Testimony",
168+
5
169+
),
170+
generateTestUserData("Nyvk23VDNQSoK9TQ9LK5xF1DwT64", "Person McPersonson", 4),
171+
generateTestUserData("QDPq42rNB0O6wqVzfMmDHmNE8sN3", "Iranout Ofnameideas", 3)
172+
]
173+
174+
const generateTestData = (
175+
frequency: Frequency,
176+
numBills: number,
177+
numUsers: number
178+
): NotificationEmailDigest => {
179+
return {
180+
notificationFrequency: frequency,
181+
startDate: new Date("2025-04-01T04:00:00Z"),
182+
endDate: new Date(
183+
`2025-04-${frequency === "Monthly" ? "30" : "07"}T04:00:00Z`
184+
),
185+
bills: bills.slice(0, Math.min(4, numBills)),
186+
users: users.slice(0, Math.min(4, numUsers)),
187+
numBillsWithNewTestimony: numBills,
188+
numUsersWithNewTestimony: numUsers
189+
}
190+
}
191+
58192
const Args = Record({ email: String })
59193

60194
// Send a test email with:
61195
// yarn firebase-admin -e dev run-script sendTestEmail --email="[email protected]"
62196
export const script: Script = async ({ db, args }) => {
63197
const { email } = Args.check(args)
64-
const digestData: NotificationEmailDigest = {
65-
notificationFrequency: "Monthly",
66-
startDate: new Date(),
67-
endDate: new Date(),
68-
bills: [],
69-
users: [],
70-
numBillsWithNewTestimony: 0,
71-
numUsersWithNewTestimony: 0
72-
}
198+
199+
// Frequency is guaranteed to be Monthly or Weekly,
200+
// and there must be at least 1 bill OR 1 user with testimony
201+
// or else a digest wouldn't be generated
202+
const digestData = generateTestData("Monthly", 4, 4)
203+
204+
// const onlyBills = generateTestData("Weekly", 4, 0)
205+
// const onlyUsers = generateTestData("Weekly", 0, 4)
206+
// const oddNumbers = generateTestData("Monthly", 1, 3)
207+
// const tooManyBills = generateTestData("Monthly", 100, 0)
208+
// const tooManyUsers = generateTestData("Monthly", 0, 100)
209+
// const tooManyBillsAndUsers = generateTestData("Monthly", 100, 100)
73210

74211
const htmlString = renderToHtmlString(digestData)
75212

0 commit comments

Comments
 (0)