Skip to content

Notification Testing #1746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions .github/workflows/repo-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ jobs:
tests/integration/auth.test.ts
tests/integration/moderation.test.ts
tests/integration/profile.test.ts
tests/integration/notifications.test.ts
18 changes: 7 additions & 11 deletions components/db/bills.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import {
collection,
getDocs,
limit,
orderBy,
Timestamp,
where
} from "firebase/firestore"
import { collection, getDocs, limit, orderBy, where } from "firebase/firestore"
import { useAsync } from "react-async-hook"
import type {
BillHistory,
Expand All @@ -14,6 +7,7 @@ import type {
import { firestore } from "../firebase"
import { loadDoc, midnight, nullableQuery } from "./common"
import { currentGeneralCourt } from "functions/src/shared"
import { Timestamp } from "functions/src/firebase"
export type { BillHistory } from "../../functions/src/bills/types"

export type MemberReference = {
Expand All @@ -26,14 +20,14 @@ export type MemberReference = {

export type BillContent = {
Title: string
Pinslip: string | null
BillNumber: string
DocketNumber: string
GeneralCourtNumber: number
PrimarySponsor?: MemberReference
PrimarySponsor: MemberReference | null
Cosponsors: MemberReference[]
LegislationTypeName: string
Pinslip: string
DocumentText: string
DocumentText?: string | null
}

export type BillTopic = {
Expand All @@ -51,10 +45,12 @@ export type Bill = {
opposeCount: number
neutralCount: number
nextHearingAt?: Timestamp
nextHearingId?: string
latestTestimonyAt?: Timestamp
latestTestimonyId?: string
fetchedAt: Timestamp
history: BillHistory
similar: string[]
currentCommittee?: CurrentCommittee
city?: string
topics?: BillTopic[]
Expand Down
7 changes: 5 additions & 2 deletions components/shared/FollowingQueries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
getDocs,
query,
setDoc,
Timestamp,
where
} from "firebase/firestore"
import { Bill } from "../db"
Expand Down Expand Up @@ -89,15 +90,17 @@ export async function setFollow(
billId: billId,
court: courtId
},
type: "bill"
type: "bill",
nextDigestAt: Timestamp.fromDate(new Date())
})
: await setDoc(doc(subscriptionRef, topicName), {
topicName: topicName,
uid: uid,
userLookup: {
profileId: profileId
},
type: "testimony"
type: "testimony",
nextDigestAt: Timestamp.fromDate(new Date())
})
}

Expand Down
19 changes: 15 additions & 4 deletions functions/src/bills/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,24 @@ export const CommitteeMember = Record({
senateChair: Maybe(CommitteeMember)
})

export type MemberReference = Static<typeof MemberReference>
export const MemberReference = Record({
Id: String,
Name: String,
Type: Number
})

export type BillContent = Static<typeof BillContent>
export const BillContent = Record({
Pinslip: Nullable(String),
Title: String,
PrimarySponsor: Nullable(Record({ Name: String })),
DocumentText: Maybe(String),
Cosponsors: Array(Record({ Name: Maybe(String) }))
Pinslip: Nullable(String),
BillNumber: String,
DocketNumber: String,
GeneralCourtNumber: Number,
PrimarySponsor: Nullable(MemberReference),
Cosponsors: Array(MemberReference),
LegislationTypeName: String,
DocumentText: Maybe(String)
})

export type BillTopic = Static<typeof BillTopic>
Expand Down
6 changes: 5 additions & 1 deletion scripts/firebase-admin/generateBill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ export const script: Script = async ({ db, args }) => {
Title: "",
PrimarySponsor: null,
DocumentText: "",
Cosponsors: []
Cosponsors: [],
BillNumber: "",
DocketNumber: "",
GeneralCourtNumber: 0,
LegislationTypeName: ""
}

const newBill: Bill = {
Expand Down
5 changes: 3 additions & 2 deletions stories/organisms/SubmitTestimonyForm.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const FormStory = {
BillNumber: "",
DocketNumber: "",
GeneralCourtNumber: 0,
PrimarySponsor: undefined,
PrimarySponsor: null,
Cosponsors: [],
LegislationTypeName: "",
Pinslip: "",
Expand All @@ -84,7 +84,8 @@ export const FormStory = {
fetchedAt: Timestamp.fromDate(new Date()),
history: [],
currentCommittee: undefined,
city: undefined
city: undefined,
similar: []
}}
synced={false}
/>
Expand Down
3 changes: 2 additions & 1 deletion stories/organisms/billDetail/BillSponsorCard.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ const bill: Bill = {
email: "[email protected]"
}
},
city: "Boston"
city: "Boston",
similar: []
}

Primary.args = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ export const Primary: Story = {
Branch: "1",
Action: "1"
}
]
],
similar: []
}
},
name: "BillTestimonyListCard",
Expand Down
3 changes: 2 additions & 1 deletion stories/organisms/billDetail/MockBillData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,6 @@ export const bill: Bill = {
},
city: "Boston",
topics: newBillTopics,
summary: "This is the summary"
summary: "This is the summary",
similar: []
}
21 changes: 16 additions & 5 deletions tests/integration/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ export async function createNewBill(props?: Partial<Bill>) {
Pinslip: null,
Title: "fake",
PrimarySponsor: null,
Cosponsors: []
Cosponsors: [],
BillNumber: "",
DocketNumber: "",
GeneralCourtNumber: 0,
LegislationTypeName: ""
}
const bill: Bill = {
id: billId,
Expand Down Expand Up @@ -160,7 +164,11 @@ export const setNewProfile = (user: {
* Returns functions to get, remove, and check where the testimony is.
*/

export const createNewTestimony = async (uid: string, billId: string) => {
export const createNewTestimony = async (
uid: string,
billId: string,
court: number = 193
) => {
const tid = nanoid(6)

const currentUserEmail = auth.currentUser?.email
Expand All @@ -178,7 +186,7 @@ export const createNewTestimony = async (uid: string, billId: string) => {
billId,
publishedAt: testTimestamp.now(),
updatedAt: testTimestamp.now(),
court: 192,
court: court,
position: "oppose",
content: "testimony content",
public: true
Expand Down Expand Up @@ -332,8 +340,11 @@ export const testCreatePendingOrgWithEmailAndPassword = async (
return userCreds
}

export const deleteUser = async (user: { uid: string }) => {
await testAuth.deleteUser(user.uid)
export const deleteUser = async (uid: string) => {
const userDoc = await testDb.doc(`/users/${uid}`).get()
const userData = userDoc.data()
await testAuth.deleteUser(uid)
await testDb.doc(`/users/${uid}`).delete()
}

export const expectUser = async (
Expand Down
Loading
Loading