Skip to content
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

Update tests #1192

Merged
merged 30 commits into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
50ac9c9
updates integration tests:
sashamaryl Jun 9, 2023
f88e057
updates to tests
sashamaryl Jun 12, 2023
985c8ec
updates profile test for change from default private to default public
sashamaryl Jul 4, 2023
facb8a0
Merge branch 'main' into update-tests & address merge conflicts
sashamaryl Aug 20, 2023
7ab47ab
get testimony.test.ts passing
alexjball Oct 30, 2023
63919cc
Configure CI to run allow-list of test files
alexjball Oct 30, 2023
3562789
manually merge common.ts
alexjball Oct 30, 2023
f7faea7
Merge remote-tracking branch 'upstream/main' into update-tests
alexjball Oct 30, 2023
20fdc78
Merge branch 'update-tests' of https://github.com/sashamaryl/advocacy…
sashamaryl Oct 30, 2023
e3e2f33
fixing profile tests
sashamaryl Nov 9, 2023
81996c4
modify accounts passing
sashamaryl Nov 10, 2023
9d773ef
address PR comments re docs and tests
sashamaryl Nov 12, 2023
f1d266f
profile, moderation, modifyAccount test suites passing
sashamaryl Nov 12, 2023
690934b
cleans up modifyAccounts
sashamaryl Nov 12, 2023
88d4f27
moderation.tests passing
sashamaryl Nov 13, 2023
5dc6111
enabling/disabling tests to run
sashamaryl Nov 13, 2023
e58eb87
runs prettier
sashamaryl Nov 13, 2023
7512c3f
disables tests not passing ci env
sashamaryl Nov 13, 2023
76ad940
runs prettier
sashamaryl Nov 13, 2023
f45e5a0
updates moderation tests
sashamaryl Nov 13, 2023
33ab8d7
Merge branch 'main' of https://github.com/codeforboston/advocacy-maps…
sashamaryl Nov 13, 2023
c1509af
adds object validation to created bills and drafts/testimony
sashamaryl Nov 15, 2023
1f1698c
runs prettier
sashamaryl Nov 15, 2023
6449fd1
disables backfill tests
sashamaryl Nov 15, 2023
3a51de7
Fix formatting of workflow.
alexjball Nov 19, 2023
d3303ca
Remove log
alexjball Nov 19, 2023
9034eb2
Add a reporter to print all tests at the end of the run
alexjball Nov 19, 2023
ff760f5
fix user email backfill command
alexjball Nov 19, 2023
d699e47
Only run analytics in production.
alexjball Nov 19, 2023
b7605da
Remove logs and duplicate lines for configuring emulators.
alexjball Nov 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/repo-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ jobs:
name: Integration Tests
runs-on: ubuntu-latest
needs: check_code_quality
# TODO: re-enable
if: false

services:
typesense:
Expand All @@ -56,4 +54,9 @@ jobs:
path: /home/runner/.cache/firebase/emulators
key: ${{ runner.os }}-firebase-emulators-${{ hashFiles('~/.cache/firebase/emulators/**') }}
- name: Run Integration Tests
run: yarn test:integration-ci
run: >
yarn test:integration-ci
tests/integration/testimony.test.ts
tests/integration/auth.test.ts
tests/integration/moderation.test.ts
tests/integration/profile.test.ts
2 changes: 1 addition & 1 deletion components/api/maple-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ mapleClient.interceptors.response.use(
}
},
async error => {
console.log(error)
console.log(error.message)
}
)
2 changes: 1 addition & 1 deletion components/auth/hooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useCreateUserWithEmailAndPassword } from "./hooks"

afterAll(terminateFirebase)

describe("useCreateUserWithEmailAndPassword", () => {
describe.skip("useCreateUserWithEmailAndPassword", () => {
it("creates user and profile", async () => {
const { result } = renderHook(() =>
useCreateUserWithEmailAndPassword(false)
Expand Down
11 changes: 7 additions & 4 deletions components/db/testimony/useEditTestimony.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ describe("useEditTestimony", () => {
return result
}

it("Publishes testimony", async () => {
// new name/fullname/authorname pattern has been implemented
it.skip("Publishes testimony", async () => {
const result = await renderAndPublish()

expect(result.current.publication).toMatchObject(testimony)
Expand All @@ -172,7 +173,8 @@ describe("useEditTestimony", () => {
expect(result.current.draft?.publishedVersion).toBe(testimony.version)
})

it("Updates testimony", async () => {
// updating testimony now requires an edit reason
it.skip("Updates testimony", async () => {
const result = await renderAndPublish()

await act(() => result.current.saveDraft.execute(updatedDraft))
Expand All @@ -186,7 +188,7 @@ describe("useEditTestimony", () => {
)
})

it("Clears published version on drafts", async () => {
it.skip("Clears published version on drafts", async () => {
const result = await renderAndPublish()

expect(result.current.draft?.publishedVersion).toBeDefined()
Expand All @@ -197,7 +199,8 @@ describe("useEditTestimony", () => {
)
})

it("Deletes testimony", async () => {
// users can no longer delete their own testimony. only admins can delete testomony.
it.skip("Deletes testimony", async () => {
const result = await renderAndPublish()

await act(() => result.current.deleteTestimony.execute())
Expand Down
17 changes: 4 additions & 13 deletions components/firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ export const getAnalytics = (() => {
let value: undefined | null | analytics.Analytics
return async () => {
if (value === undefined) {
if (await analytics.isSupported()) {
if (
process.env.NODE_ENV === "production" &&
(await analytics.isSupported())
) {
value = analytics.getAnalytics(app)
} else {
value = null
Expand Down Expand Up @@ -74,7 +77,6 @@ export const storage = getStorage()
export const functions = getFunctions()

if (!initialized && process.env.NODE_ENV !== "production") {
console.log("env.NODE_ENV in firebase.ts", process.env.NODE_ENV)
const useEmulator = process.env.NEXT_PUBLIC_USE_EMULATOR
switch (useEmulator) {
case "1":
Expand Down Expand Up @@ -102,21 +104,10 @@ function connectEmulators() {
connectStorageEmulator(storage, host, 9199)
connectAuthEmulator(auth, `http://${host}:9099`, { disableWarnings: true })

app.firestore().useEmulator(host, 8080)
app.functions().useEmulator(host, 5001)
app.storage().useEmulator(host, 9199)
// ;(app.auth().useEmulator as any)(`http://${host}:9099`, {
// disableWarnings: true
// })
app.auth().useEmulator(`http://${host}:9099`)
if (process.env.NODE_ENV === "development")
console.log("Connected to emulators")
}

// auth.onAuthStateChanged(u => {
// console.log('onAuthStateChanged', u)
// })

if (typeof window !== "undefined") {
Object.assign(window as any, { auth, app, getApps })
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,44 @@
import React from "react"
import { RemoveTestimonyForm } from "components/moderation/RemoveTestimony"
import { createFakeTestimonyReport } from "../../components/moderation/setUp/MockRecords"
import { createFakeTestimonyReport } from "./setUp/MockRecords"
import { cleanup, render, act } from "@testing-library/react"
import { screen } from "@testing-library/dom"
import userEvent from "@testing-library/user-event"
import { AdminContext } from "react-admin"
import { ReportModal } from "components/TestimonyCard/ReportModal"
import { RequestDeleteOwnTestimonyModal } from "components/TestimonyCard/ReportModal"

describe("report testimony modal", () => {
const setIsReporting = jest.fn()
const mutateReport = jest.fn()
it("renders report modal", () => {
render(
<ReportModal
reasons={[
"Personal Information",
"Offensive",
"Violent",
"Spam",
"Phishing"
]}
onClose={setIsReporting}
onReport={mutateReport}
isLoading={false}
additionalInformationLabel={""}
/>
)
})

it("renders request delete own testimony modal", () => {
render(
<RequestDeleteOwnTestimonyModal
onClose={setIsReporting}
onReport={mutateReport}
isLoading={false}
/>
)
})
})

describe("remove testimony", () => {
const { user, testimony, report } = createFakeTestimonyReport()
Expand All @@ -15,6 +49,9 @@ describe("remove testimony", () => {
<RemoveTestimonyForm report={report} />
</AdminContext>
)
expect(screen.getByText(/remove/i)).toBeInstanceOf(HTMLLabelElement)

cleanup()
})

it("displays remove and allow options", async () => {
Expand All @@ -26,7 +63,6 @@ describe("remove testimony", () => {

expect(screen.getByLabelText(/remove/i)).toBeInstanceOf(HTMLInputElement)
expect(screen.getByLabelText(/allow/i)).toBeInstanceOf(HTMLInputElement)

cleanup()
})

Expand All @@ -53,5 +89,7 @@ describe("remove testimony", () => {

const textBox = screen.getByLabelText(/Reason/i)
userEvent.type(textBox, "this is a textBox")

cleanup()
})
})
26 changes: 13 additions & 13 deletions firestore.rules
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,33 @@ service cloud.firestore {
allow read: if true;
allow write: if false;
}
function isAdmin() {
return request.auth.token.get("role", "user") == "admin"
}
match /profiles/{uid} {
function validUser() {
function validUser() { // is the user the same as the profile?
return request.auth.uid == uid
}

function validRoleChange() {
function doesNotChangeRole() {
return !request.resource.data.diff(resource.data).affectedKeys().hasAny(['role'])
}

// either the change doesn't include the public field,
// or the user is a base user (i.e. not an org)
function validPublicChange() {
return !request.resource.data.diff(resource.data).affectedKeys().hasAny(['public'])
|| request.auth.token.get("role", "user") == "user"
}

// Always visible to the user and public if `public` is true.
// Always visible to admins.
// Only writable by the user & admin
// Do not allow users to delete their profile, set the role field.
// Only admins can delete a user profile, set the user role field.
// Only normal "user" roles & admins can toggle visibility.
allow read, write: if request.auth.token.get("role", "user") == "admin"
allow read: if resource.data.public || request.auth.uid == uid
// Only normal "user" roles & admins can toggle visibility.
allow create: if validUser() && request.resource.data.role == 'user' && request.resource.data.public == false
allow update: if validUser() && validRoleChange() && validPublicChange()


// Always readable and writable to admins
allow read, write: if request.auth.token.get("role", "user") == "admin"

// Allow users to make updates except to delete their profile or set the role field.
// Only admins can delete a user profile or set the user role field.
allow update: if validUser() && doesNotChangeRole() && validPublicChange()
}
// Allow querying publications individually or with a collection group.
match /{path=**}/publishedTestimony/{id} {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"build-storybook": "build-storybook",
"chromatic": "chromatic --project-token=f8618e690599",
"copy-handlebars": "echo 'Copying handlebars files to /lib/email/...' && ncp functions/src/email/ functions/lib/email/ && echo '...done!'",
"backfill-user-emails": "ts-node -P tsconfig.script.json scripts/firebase-admin//backfilluserEmails.ts --swc",
"backfill-user-emails": "ts-node -P tsconfig.script.json scripts/firebase-admin//backfillUserEmails.ts --swc",
"backfill-user-nf": "ts-node -P tsconfig.script.json scripts/firebase-admin/backfillNotificationFrequency.ts --swc"
},
"engines": {
Expand Down Expand Up @@ -171,6 +171,7 @@
"inquirer": "^6.5.1",
"jest": "^27.5.1",
"jest-environment-jsdom": "^27.5.1",
"jest-summary-reporter": "^0.0.2",
"js-yaml": "^4.1.0",
"lorem-ipsum": "^2.0.4",
"mustache": "^4.2.0",
Expand Down
2 changes: 1 addition & 1 deletion scripts/test-integration-ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ runOrExit(
"auth,functions,pubsub,firestore,storage",
"--import",
"tests/integration/exportedTestData",
"yarn test:integration --forceExit"
`yarn test:integration --forceExit ${process.argv.slice(2).join(" ")}`
],
{ stdio: "inherit", env }
)
17 changes: 14 additions & 3 deletions tests/integration/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const fakeUser = () => ({
password: "password"
})

afterAll(terminateFirebase)
// afterAll(terminateFirebase)
sashamaryl marked this conversation as resolved.
Show resolved Hide resolved

describe("setRole", () => {
const ctx = { auth: testAuth, db: testDb }
Expand Down Expand Up @@ -47,11 +47,22 @@ describe("setRole", () => {
expectUser(user, role, false)
})

it.each<[string, (u: any) => any]>([
["uid", u => ({ uid: u.uid })],
["email", u => ({ email: u.email })]
])("sets claims by %s", async (_, extract) => {
const user = await createUser()
const role = "organization"
await setRole({ ...extract(user), ...ctx, role })
expectUser(user, role, true)
})

it.each<[Role, boolean]>([
["user", false],
["admin", false],
["legislator", true],
["organization", true]
["legislator", false],
["organization", true],
["pendingUpgrade", false]
])("sets claims for %s", async (role, expectedPublic) => {
const user = await createUser()
await setRole({ uid: user.uid, ...ctx, role })
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/backfillTestimonyCounts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ beforeEach(async () => {

afterAll(terminateFirebase)

describe("backfillTestimonyCounts", () => {
describe.skip("backfillTestimonyCounts", () => {
it("Calculates testimony counts", async () => {
await setPublication("user-1", "t-1", {
position: "endorse",
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/billTracker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ const getBillTracker = (billId: string, court: number) =>
if (s.exists) return s.data() as BillTracker
})

describe("billTracker", () => {
describe.skip("billTracker", () => {
describe("calculate status", () => {
test("detects bill Introduced", () => {
const billIntroduced = predictBillStatus(noHistory)
Expand Down Expand Up @@ -263,7 +263,7 @@ describe("billTracker", () => {
})
})

describe("on bill document change", () => {
describe.skip("on bill document change", () => {
let court: number, billId: string, billPath: string
beforeAll(async () => {
court = 192
Expand Down
Loading
Loading