diff --git a/.github/workflows/deploy_ci.yml b/.github/workflows/deploy_ci.yml new file mode 100644 index 00000000..29a67167 --- /dev/null +++ b/.github/workflows/deploy_ci.yml @@ -0,0 +1,75 @@ +# This is a basic workflow to help you get started with Actions + +name: Firebase function deploy + +# Controls when the action will run. Triggers the workflow on push +# events but only for the master branch +on: + push: + branches: [ test/cleanup ] + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-22.04 + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + + # Runs a single command using the runners shell + # And of course we need to goto our functions folder to deploy + - name: Install npm packages and write env + run: | + yarn + echo "${{ secrets.ACTIONS_ENV_FILE }}" > ./packages/actions/.env + echo "${{ secrets.BACKEND_ENV_FILE }}" > ./packages/backend/.env + + # Deploying the functions to firebase + - name: Deploy to Firebase + uses: w9jds/firebase-action@master + with: + args: deploy --only functions --project prod + env: + FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }} + PROJECT_PATH: packages/backend/ + + test: + runs-on: ubuntu-22.04 + environment: p0tion-ci-environment + steps: + - name: checkout repo + uses: actions/checkout@v3 + + - uses: actions/setup-node@v3 + with: + node-version: 16 + cache: yarn + + - name: write env file for Firebase + run: | + echo "${{ secrets.ACTIONS_ENV_FILE }}" > ./packages/actions/.env + + - name: write Firebase service account key + id: create-json + uses: jsdaniell/create-json@v1.2.1 + with: + name: "serviceAccountKey.json" + json: ${{ secrets.SERVICE_ACCOUNT_KEY }} + dir: "./packages/backend/" + + - name: install dependencies + run: yarn install --frozen-lockfile + + - name: build packages + run: yarn build + env: + NODE_OPTIONS: "--max_old_space_size=4096" + + - name: run test (unit & e2e) + run: yarn test:ci-prod + env: + GOOGLE_APPLICATION_CREDENTIALS: ./packages/backend/serviceAccountKey.json \ No newline at end of file diff --git a/.github/workflows/test-ci-prod.yaml b/.github/workflows/test-ci-prod.yaml index ad45d1eb..4799542b 100644 --- a/.github/workflows/test-ci-prod.yaml +++ b/.github/workflows/test-ci-prod.yaml @@ -67,11 +67,14 @@ jobs: # Install Firebase-cli npm install -g firebase-tools - - name: deploy to Firebase - run: firebase deploy --only functions --project prod - working-directory: packages/backend + # Deploying the functions to firebase + - name: Deploy to Firebase + uses: w9jds/firebase-action@master + with: + args: deploy --only functions --project prod env: - GOOGLE_APPLICATION_CREDENTIALS: ./serviceAccountKey.json + FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }} + PROJECT_PATH: packages/backend/ unit-e2e-test: needs: deploy diff --git a/packages/actions/test/data/samples.ts b/packages/actions/test/data/samples.ts index cd744615..c23ee12d 100644 --- a/packages/actions/test/data/samples.ts +++ b/packages/actions/test/data/samples.ts @@ -164,7 +164,7 @@ const fakeCeremonyContributeTest = generateFakeCeremony({ }) const fakeCeremonyClosedDynamic = generateFakeCeremony({ - uid: "0000000000000000000D", + uid: "0000000000000000000F", data: { coordinatorId: fakeUser1.uid, title: "Ceremony Closed Dynamic", diff --git a/packages/actions/test/e2e/01-setup.test.ts b/packages/actions/test/e2e/01-setup.test.ts index 4c648268..73f76fcf 100644 --- a/packages/actions/test/e2e/01-setup.test.ts +++ b/packages/actions/test/e2e/01-setup.test.ts @@ -72,11 +72,11 @@ describe("Setup", () => { const potStorageFilePath = getPotStorageFilePath(potName) const r1csName = `${circuit.data.prefix}.r1cs` - const r1csLocalFilePath = `./${r1csName}` + const r1csLocalFilePath = `./${setupFolder}/${r1csName}` const r1csStorageFilePath = getR1csStorageFilePath(circuit.data.prefix!, r1csName) const wasmName = `${circuit.data.prefix}.wasm` - const wasmLocalFilePath = `./${wasmName}` + const wasmLocalFilePath = `./${setupFolder}/${wasmName}` const wasmStorageFilePath = getWasmStorageFilePath(circuit.data.prefix!, wasmName) let ceremonyId: string @@ -209,17 +209,6 @@ describe("Setup", () => { expect(await checkIfObjectExist(userFunctions, ceremonyBucket, r1csStorageFilePath)).to.be.true expect(await checkIfObjectExist(userFunctions, ceremonyBucket, wasmStorageFilePath)).to.be.true }) - it("should fail to create a new ceremony when the coordinator provides the wrong path to a file required for a ceremony setup (zkey)", async () => { - const objectName = "test_upload.zkey" - const nonExistentLocalPath = "./nonExistentPath.zkey" - // make sure we are logged in as coordinator - await signInWithEmailAndPassword(userAuth, users[1].data.email, passwords[1]) - - // 2. multi part upload - await expect( - multiPartUpload(userFunctions, ceremonyBucket, objectName, nonExistentLocalPath, streamChunkSizeInMb) - ).to.be.rejectedWith("ENOENT: no such file or directory") - }) } afterAll(async () => { diff --git a/packages/actions/test/e2e/02-contribution.test.ts b/packages/actions/test/e2e/02-contribution.test.ts index 031ec72c..9e6b6c83 100644 --- a/packages/actions/test/e2e/02-contribution.test.ts +++ b/packages/actions/test/e2e/02-contribution.test.ts @@ -32,7 +32,6 @@ import { fakeCeremoniesData, fakeCircuitsData, fakeUsersData } from "../data/sam import { initializeAdminServices, initializeUserServices, - generatePseudoRandomStringOfNumbers, deleteAdminApp, createMockCeremony, cleanUpMockUsers, @@ -46,7 +45,8 @@ import { envType, sleep, getTranscriptLocalFilePath, - cleanUpRecursively + cleanUpRecursively, + generateUserPasswords } from "../utils" import { generateFakeParticipant } from "../data/generators" import { ParticipantContributionStep, ParticipantStatus, TestingEnvironment } from "../../src/types/enums" @@ -61,11 +61,7 @@ describe("Contribution", () => { const userAuth = getAuth(userApp) const users = [fakeUsersData.fakeUser1, fakeUsersData.fakeUser2, fakeUsersData.fakeUser3] - const passwords = [ - generatePseudoRandomStringOfNumbers(24), - generatePseudoRandomStringOfNumbers(24), - generatePseudoRandomStringOfNumbers(24) - ] + const passwords = generateUserPasswords(users.length) let ceremonyBucketPostfix: string = "" let streamChunkSizeInMb: number = 0 @@ -108,6 +104,10 @@ describe("Contribution", () => { const objectsToDelete = [potStoragePath, storagePath] beforeAll(async () => { + // @note this test suite needs some delay if run after other + // test suites + await sleep(1000) + // Create users for (let i = 0; i < users.length; i++) { users[i].uid = await createMockUser( @@ -233,6 +233,7 @@ describe("Contribution", () => { await sleep(1000) objectsToDelete.push(nextZkeyStoragePath) + // Execute contribution verification. const { valid } = await verifyContribution( userFunctions, diff --git a/packages/actions/test/e2e/03-finalization.test.ts b/packages/actions/test/e2e/03-finalization.test.ts index fbbc31f3..520a9b8d 100644 --- a/packages/actions/test/e2e/03-finalization.test.ts +++ b/packages/actions/test/e2e/03-finalization.test.ts @@ -10,7 +10,6 @@ import { finalizeCeremony, finalizeCircuit, getBucketName, - getClosedCeremonies, getDocumentById, getParticipantsCollectionPath, getVerificationKeyStorageFilePath, @@ -168,11 +167,6 @@ describe("Finalization e2e", () => { finalizeCeremony(userFunctions, fakeCeremoniesData.fakeCeremonyClosedDynamic.uid) ).to.be.rejectedWith("You do not have privileges to perform this operation.") }) - it("should return all ceremonies that need finalizing", async () => { - const closedCeremonies = await getClosedCeremonies(userFirestore) - // make sure there is at least one ceremony that needs finalizing - expect(closedCeremonies.length).to.be.gt(0) - }) if (envType === TestingEnvironment.PRODUCTION) { it("should finalize a ceremony", async () => { await signInWithEmailAndPassword(userAuth, users[2].data.email, passwords[2]) @@ -213,6 +207,7 @@ describe("Finalization e2e", () => { if (envType === TestingEnvironment.PRODUCTION) { await deleteObjectFromS3(bucketName, verificationKeyStoragePath) await deleteObjectFromS3(bucketName, verifierContractStoragePath) + await sleep(500) await deleteBucket(bucketName) } diff --git a/packages/actions/test/e2e/04-clean.test.ts b/packages/actions/test/e2e/04-clean.test.ts deleted file mode 100644 index f2d4b1f8..00000000 --- a/packages/actions/test/e2e/04-clean.test.ts +++ /dev/null @@ -1,40 +0,0 @@ -import chai from "chai" -import chaiAsPromised from "chai-as-promised" - -// Config chai. -chai.use(chaiAsPromised) - -describe("Setup action", () => { - // Sample data for running the test. - // let userId: string - - // // Initialize user and admin services. - // const { userApp } = initializeUserServices() - // const { adminFirestore, adminAuth } = initializeAdminServices() - // const { userEmail, githubClientId } = getAuthenticationConfiguration() - - // beforeAll(async () => { - // // Authenticate user. - // const userFirebaseCredentials = envType === TestingEnvironment.DEVELOPMENT ? await createNewFirebaseUserWithEmailAndPw( - // userApp, - // userEmail, - // generatePseudoRandomStringOfNumbers(24) - // ) : await authenticateUserWithGithub(userApp, githubClientId) - // userId = userFirebaseCredentials.user.uid - // }) - - it("should delete all files related to a contribution", () => {}) - it("there should be some files in the output path for a ceremony", () => {}) - it("should not delete anything should there not be files in the specific director", () => {}) - - // afterAll(async () => { - // // Clean ceremony and user from DB. - // await adminFirestore.collection("users").doc(userId).delete() - - // // Remove Auth user. - // await adminAuth.deleteUser(userId) - - // // Delete admin app. - // await deleteAdminApp() - // }) -}) diff --git a/packages/actions/test/unit/authentication.test.ts b/packages/actions/test/unit/authentication.test.ts index 85c1ac44..935914cb 100644 --- a/packages/actions/test/unit/authentication.test.ts +++ b/packages/actions/test/unit/authentication.test.ts @@ -9,7 +9,8 @@ import { generatePseudoRandomStringOfNumbers, initializeAdminServices, initializeUserServices, - setCustomClaims + setCustomClaims, + sleep } from "../utils" import { fakeUsersData } from "../data/samples" import { commonTerms, getCurrentFirebaseAuthUser, isCoordinator, signInToFirebaseWithCredentials } from "../../src" @@ -57,8 +58,11 @@ describe("Authentication", () => { userPassword ) + await sleep(500) userFromCredential = userFirebaseCredentials.user - userUID = userFromCredential.uid + + const authUser = getCurrentFirebaseAuthUser(userApp) + userUID = authUser.uid }) it("should return the current Firebase user authenticated for a given application", async () => { diff --git a/packages/actions/test/unit/contribute.test.ts b/packages/actions/test/unit/contribute.test.ts index 05d694b6..68b44493 100644 --- a/packages/actions/test/unit/contribute.test.ts +++ b/packages/actions/test/unit/contribute.test.ts @@ -156,15 +156,6 @@ describe("Contribute", () => { "Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore" ) }) - it("should return the same data to coordinators and participants", async () => { - // auth - await signInWithEmailAndPassword(userAuth, users[0].data.email, passwords[0]) - const circuits = await getCeremonyCircuits(userFirestore, fakeCeremoniesData.fakeCeremonyOpenedFixed.uid) - // auth - await signInWithEmailAndPassword(userAuth, users[2].data.email, passwords[2]) - const circuits2 = await getCeremonyCircuits(userFirestore, fakeCeremoniesData.fakeCeremonyOpenedFixed.uid) - expect(circuits2).to.deep.equal(circuits) - }) afterAll(async () => { await cleanUpRecursively(adminFirestore, fakeCeremoniesData.fakeCeremonyOpenedFixed.uid) }) @@ -679,7 +670,6 @@ describe("Contribute", () => { ).to.be.rejectedWith("internal") }) it("should store the contribution verification result", async () => {}) - it("should allow a coordinator to finalize a ceremony if in state CLOSED", async () => {}) afterAll(async () => { await cleanUpRecursively(adminFirestore, fakeCeremoniesData.fakeCeremonyContributeTest.uid) }) @@ -767,8 +757,8 @@ describe("Contribute", () => { ).to.be.fulfilled }) afterAll(async () => { - await cleanUpRecursively(adminFirestore, fakeCeremoniesData.fakeCeremonyOpenedDynamic.uid) await cleanUpRecursively(adminFirestore, fakeCeremoniesData.fakeCeremonyOpenedFixed.uid) + await cleanUpRecursively(adminFirestore, fakeCeremoniesData.fakeCeremonyOpenedDynamic.uid) }) }) @@ -914,6 +904,7 @@ describe("Contribute", () => { ) }) }) + describe("generateValidContributionsAttestation", () => {}) afterAll(async () => { diff --git a/packages/actions/test/unit/database.test.ts b/packages/actions/test/unit/database.test.ts index 98c03f56..98d33f21 100644 --- a/packages/actions/test/unit/database.test.ts +++ b/packages/actions/test/unit/database.test.ts @@ -1,4 +1,4 @@ -import chai, { expect, assert } from "chai" +import chai, { expect } from "chai" import chaiAsPromised from "chai-as-promised" import { getAuth, signInWithEmailAndPassword, signOut } from "firebase/auth" import { where } from "firebase/firestore" @@ -19,14 +19,15 @@ import { commonTerms } from "../../src" import { - setCustomClaims, - createNewFirebaseUserWithEmailAndPw, deleteAdminApp, - generatePseudoRandomStringOfNumbers, initializeAdminServices, initializeUserServices, - sleep, - cleanUpRecursively + cleanUpRecursively, + generateUserPasswords, + createMockUser, + createMockCeremony, + cleanUpMockUsers, + sleep } from "../utils" import { CeremonyState } from "../../src/types/enums" @@ -42,82 +43,50 @@ describe("Database", () => { const { userApp, userFirestore } = initializeUserServices() const userAuth = getAuth(userApp) - // Sample data for running the test. - const user = fakeUsersData.fakeUser2 - const coordinatorEmail = "coordinator@coordinator.com" - // storing the uid so we can delete the user after the test - let coordinatorUid: string - - // generate passwords for user and coordinator - const userPwd = generatePseudoRandomStringOfNumbers(24) - const coordinatorPwd = generatePseudoRandomStringOfNumbers(24) + // Generate users. + const users = [fakeUsersData.fakeUser1, fakeUsersData.fakeUser2] + const passwords = generateUserPasswords(users.length) beforeAll(async () => { - // create a new user without contributor privileges - await createNewFirebaseUserWithEmailAndPw(userApp, user.data.email, userPwd) - await sleep(5000) - - // Retrieve the current auth user in Firebase. - const currentAuthenticatedUser = getCurrentFirebaseAuthUser(userApp) - user.uid = currentAuthenticatedUser.uid - - // create account for coordinator - await createNewFirebaseUserWithEmailAndPw(userApp, coordinatorEmail, coordinatorPwd) - await sleep(5000) - - const currentAuthenticatedCoordinator = getCurrentFirebaseAuthUser(userApp) - coordinatorUid = currentAuthenticatedCoordinator.uid - - // add custom claims for coordinator privileges - await setCustomClaims(adminAuth, coordinatorUid, { coordinator: true }) - - // Create the mock data on Firestore. - await adminFirestore - .collection(commonTerms.collections.ceremonies.name) - .doc(fakeCeremoniesData.fakeCeremonyOpenedFixed.uid) - .set({ - ...fakeCeremoniesData.fakeCeremonyOpenedFixed.data - }) - - await adminFirestore - .collection(getCircuitsCollectionPath(fakeCeremoniesData.fakeCeremonyOpenedFixed.uid)) - .doc(fakeCircuitsData.fakeCircuitSmallNoContributors.uid) - .set({ - ...fakeCircuitsData.fakeCircuitSmallNoContributors.data - }) - - await adminFirestore - .collection(commonTerms.collections.ceremonies.name) - .doc(fakeCeremoniesData.fakeCeremonyClosedDynamic.uid) - .set({ - ...fakeCeremoniesData.fakeCeremonyClosedDynamic.data - }) - - await adminFirestore - .collection(getCircuitsCollectionPath(fakeCeremoniesData.fakeCeremonyClosedDynamic.uid)) - .doc(fakeCircuitsData.fakeCircuitSmallContributors.uid) - .set({ - ...fakeCircuitsData.fakeCircuitSmallContributors.data - }) + for (let i = 0; i < users.length; i++) { + const uid = await createMockUser( + userApp, + users[i].data.email, + passwords[i], + i === users.length - 1, + adminAuth + ) + users[i].uid = uid + await sleep(500) + } + + await createMockCeremony( + adminFirestore, + fakeCeremoniesData.fakeCeremonyOpenedFixed, + fakeCircuitsData.fakeCircuitSmallNoContributors + ) + await createMockCeremony( + adminFirestore, + fakeCeremoniesData.fakeCeremonyClosedDynamic, + fakeCircuitsData.fakeCircuitSmallContributors + ) }) describe("queryCollection", () => { it("should not allow the coordinator to query the users collection", async () => { // sign in as a coordinator - await signInWithEmailAndPassword(userAuth, coordinatorEmail, coordinatorPwd) - await setCustomClaims(adminAuth, coordinatorUid, { coordinator: true }) + await signInWithEmailAndPassword(userAuth, users[1].data.email, passwords[1]) const currentAuthenticatedCoordinator = getCurrentFirebaseAuthUser(userApp) // refresh target await currentAuthenticatedCoordinator.getIdToken(true) - assert.isRejected( + await expect( queryCollection(userFirestore, commonTerms.collections.users.name, [ - where(commonTerms.collections.users.fields.email, "==", user.data.email) + where(commonTerms.collections.users.fields.email, "==", users[1].data.email) ]) - ) + ).to.be.rejected }) it("should allow any authenticated user to query the ceremonies collection", async () => { - // Sign in as coordinator. - await signInWithEmailAndPassword(userAuth, user.data.email, userPwd) + await signInWithEmailAndPassword(userAuth, users[0].data.email, passwords[0]) const query = await queryCollection(userFirestore, commonTerms.collections.ceremonies.name, [ where(commonTerms.collections.ceremonies.fields.state, "==", CeremonyState.OPENED) ]) @@ -125,48 +94,47 @@ describe("Database", () => { }) it("should revert when not logged in", async () => { await signOut(userAuth) - assert.isRejected( + await expect( queryCollection(userFirestore, commonTerms.collections.ceremonies.name, [ where(commonTerms.collections.ceremonies.fields.state, "==", CeremonyState.OPENED) ]) - ) + ).to.be.rejected }) }) describe("getAllCollectionDocs", () => { it("should not allow the coordinator to query all the users collection", async () => { // sign in as a coordinator - await signInWithEmailAndPassword(userAuth, coordinatorEmail, coordinatorPwd) - assert.isRejected(getAllCollectionDocs(userFirestore, commonTerms.collections.users.name)) + await signInWithEmailAndPassword(userAuth, users[1].data.email, passwords[1]) + await expect(getAllCollectionDocs(userFirestore, commonTerms.collections.users.name)).to.be.rejected }) it("should revert when a non coordinator tries to query the users collection", async () => { // sign in as a participant - await signInWithEmailAndPassword(userAuth, user.data.email, userPwd) - assert.isRejected(getAllCollectionDocs(userFirestore, commonTerms.collections.users.name)) + await signInWithEmailAndPassword(userAuth, users[0].data.email, passwords[0]) + await expect(getAllCollectionDocs(userFirestore, commonTerms.collections.users.name)).to.be.rejected }) it("should allow any authenticated user to query the ceremonies collection", async () => { // Sign in as coordinator. - await signInWithEmailAndPassword(userAuth, user.data.email, userPwd) + await signInWithEmailAndPassword(userAuth, users[1].data.email, passwords[1]) const collection = await getAllCollectionDocs(userFirestore, commonTerms.collections.ceremonies.name) expect(collection.length).to.be.gt(0) }) it("should revert when not logged in", async () => { await signOut(userAuth) - assert.isRejected(getAllCollectionDocs(userFirestore, commonTerms.collections.ceremonies.name)) + await expect(getAllCollectionDocs(userFirestore, commonTerms.collections.ceremonies.name)).to.be.rejected }) }) describe("fromQueryToFirebaseDocumentInfo", () => { it("should return data for a valid collection", async () => { // sign in as a coordinator - await signInWithEmailAndPassword(userAuth, coordinatorEmail, coordinatorPwd) + await signInWithEmailAndPassword(userAuth, users[1].data.email, passwords[1]) const collection = await getAllCollectionDocs(userFirestore, commonTerms.collections.ceremonies.name) expect(collection.length).to.be.gt(0) const collectionInfo = fromQueryToFirebaseDocumentInfo(collection) expect(collectionInfo).to.not.be.null }) it("should not return any data when given an empty collection", async () => { - // Sign in as coordinator. const collectionInfo = fromQueryToFirebaseDocumentInfo([] as any) expect(collectionInfo.length).to.be.eq(0) }) @@ -174,16 +142,17 @@ describe("Database", () => { describe("getDocumentById", () => { it("should allow an authenticated user to get a document with their own data", async () => { - await signInWithEmailAndPassword(userAuth, user.data.email, userPwd) - const userDoc = await getDocumentById(userFirestore, commonTerms.collections.users.name, user.uid) + await signInWithEmailAndPassword(userAuth, users[0].data.email, passwords[0]) + const userDoc = await getDocumentById(userFirestore, commonTerms.collections.users.name, users[0].uid) expect(userDoc).to.not.be.null }) it("should revert when not logged in", async () => { await signOut(userAuth) - assert.isRejected(getDocumentById(userFirestore, commonTerms.collections.users.name, user.uid)) + await expect(getDocumentById(userFirestore, commonTerms.collections.users.name, users[0].uid)).to.be + .rejected }) it("should an authenticated user to get a ceremonies document", async () => { - await signInWithEmailAndPassword(userAuth, user.data.email, userPwd) + await signInWithEmailAndPassword(userAuth, users[0].data.email, passwords[0]) const userDoc = await getDocumentById( userFirestore, commonTerms.collections.ceremonies.name, @@ -199,7 +168,7 @@ describe("Database", () => { userFirestore, fakeCircuitsData.fakeCircuitSmallNoContributors.uid, fakeCeremoniesData.fakeCeremonyOpenedFixed.uid, - user.uid + users[0].uid ) expect(contributions.length).to.be.eq(0) }) @@ -213,15 +182,7 @@ describe("Database", () => { }) it("should not return any closed ceremonies after removing the data from the db", async () => { // here we delete the circuit and the ceremony so we run this test last - await adminFirestore - .collection(getCircuitsCollectionPath(fakeCeremoniesData.fakeCeremonyClosedDynamic.uid)) - .doc(fakeCircuitsData.fakeCircuitSmallNoContributors.uid) - .delete() - - await adminFirestore - .collection(commonTerms.collections.ceremonies.name) - .doc(fakeCeremoniesData.fakeCeremonyClosedDynamic.uid) - .delete() + await cleanUpRecursively(adminFirestore, fakeCeremoniesData.fakeCeremonyClosedDynamic.uid) const closedCeremonies = await getClosedCeremonies(userFirestore) expect(closedCeremonies.length).to.be.equal(0) @@ -234,7 +195,7 @@ describe("Database", () => { const timeout = await getCurrentActiveParticipantTimeout( userFirestore, fakeCeremoniesData.fakeCeremonyOpenedFixed.uid, - user.uid + users[0].uid ) expect(timeout.length).to.be.eq(0) }) @@ -279,12 +240,7 @@ describe("Database", () => { }) afterAll(async () => { - await adminFirestore.collection(commonTerms.collections.users.name).doc(user.uid).delete() - await adminFirestore.collection(commonTerms.collections.users.name).doc(coordinatorUid).delete() - // Remove Auth user. - await adminAuth.deleteUser(user.uid) - await adminAuth.deleteUser(coordinatorUid) - // Delete mock ceremony data. + await cleanUpMockUsers(adminAuth, adminFirestore, users) await cleanUpRecursively(adminFirestore, fakeCeremoniesData.fakeCeremonyOpenedFixed.uid) // Delete admin app. diff --git a/packages/actions/test/unit/setup.test.ts b/packages/actions/test/unit/setup.test.ts index fc0bb6ec..864ab58a 100644 --- a/packages/actions/test/unit/setup.test.ts +++ b/packages/actions/test/unit/setup.test.ts @@ -1,4 +1,4 @@ -import chai, { assert, expect } from "chai" +import chai, { expect } from "chai" import chaiAsPromised from "chai-as-promised" import { getAuth, signInWithEmailAndPassword, signOut } from "firebase/auth" import fs from "fs" @@ -57,11 +57,11 @@ describe("Setup", () => { it("should fail when called by an authenticated user without coordinator privileges", async () => { // Sign in as user. await signInWithEmailAndPassword(userAuth, users[0].data.email, passwords[0]) - assert.isRejected( + await expect( setupCeremony(userFunctions, fakeCeremoniesData.fakeCeremonyNotCreated, ceremonyBucketPostfix, [ fakeCircuitsData.fakeCircuitSmallNoContributors as any ]) - ) + ).to.be.rejected }) it("should succeed when called by an authenticated user with coordinator privileges", async () => { // Sign in as coordinator. @@ -93,11 +93,11 @@ describe("Setup", () => { it("should fail when called without being authenticated", async () => { // sign out await signOut(userAuth) - assert.isRejected( + await expect( setupCeremony(userFunctions, fakeCeremoniesData.fakeCeremonyNotCreated, ceremonyBucketPostfix, [ fakeCircuitsData.fakeCircuitSmallNoContributors as any ]) - ) + ).to.be.rejected }) })