-
Notifications
You must be signed in to change notification settings - Fork 73
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
fix: listen to user doc changes instead of fetching doc to check if exists #226
Closed
sripwoud
wants to merge
4
commits into
privacy-scaling-explorations:dev
from
sripwoud:sripwoud/issue-220
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4fd942f
fix(contribute command): listen to user doc changes instead of fetchi…
sripwoud a87f7b5
test(waitforuserdocumenttoexist): test new `waitForUserDocumentToExis…
sripwoud 8e238bd
revert changes in contribute.test.ts
sripwoud 1b41157
Merge branch 'dev' into sripwoud/issue-220
ctrlc03 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import { expect as jestExpect } from "@jest/globals" | ||
import chai, { expect } from "chai" | ||
import chaiAsPromised from "chai-as-promised" | ||
import { getAuth, signInWithEmailAndPassword, signOut } from "firebase/auth" | ||
import { where } from "firebase/firestore" | ||
import { onSnapshot, where } from "firebase/firestore" | ||
import * as firestore from "firebase/firestore" | ||
import { fakeCeremoniesData, fakeCircuitsData, fakeParticipantsData, fakeUsersData } from "../data/samples" | ||
import { | ||
getCurrentFirebaseAuthUser, | ||
|
@@ -16,7 +18,8 @@ import { | |
getCircuitsCollectionPath, | ||
getContributionsCollectionPath, | ||
getTimeoutsCollectionPath, | ||
commonTerms | ||
commonTerms, | ||
waitForUserDocumentToExist | ||
} from "../../src/index" | ||
import { | ||
deleteAdminApp, | ||
|
@@ -32,6 +35,11 @@ import { | |
} from "../utils/index" | ||
import { CeremonyState } from "../../src/types/enums" | ||
|
||
jest.mock("firebase/firestore", () => ({ | ||
__esModule: true, | ||
...jest.requireActual("firebase/firestore") | ||
})) | ||
|
||
chai.use(chaiAsPromised) | ||
|
||
/** | ||
|
@@ -150,6 +158,29 @@ describe("Database", () => { | |
}) | ||
}) | ||
|
||
describe("waitForUserDocumentToExist", () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. great stuff adding a test for it |
||
it("should wait for a user document to exist", async () => { | ||
await signInWithEmailAndPassword(userAuth, users[0].data.email, passwords[0]) | ||
|
||
let handleSnapshot: any | ||
jest.spyOn(firestore, "onSnapshot").mockImplementationOnce((...args) => { | ||
;[, handleSnapshot] = args | ||
return jest.fn() | ||
}) | ||
|
||
const promise = waitForUserDocumentToExist( | ||
userFirestore, | ||
commonTerms.collections.ceremonies.name, | ||
fakeCeremoniesData.fakeCeremonyOpenedFixed.uid | ||
) | ||
|
||
handleSnapshot({ exists: () => true }) // Simulate document creation | ||
await expect(promise).to.be.fulfilled | ||
jestExpect(onSnapshot).toHaveBeenCalledTimes(1) | ||
}) | ||
jest.clearAllMocks() | ||
}) | ||
|
||
describe("getCircuitContributionsFromContributor", () => { | ||
it("should return an empty array when a ceremony has not participants", async () => { | ||
const contributions = await getCircuitContributionsFromContributor( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while this would be a great solution, the code might hang forever if a user tried to auth and they did not pass the sybil checks. As discussed, a fetch and retry mechanism might work better for now until we find a more elegant solution