Skip to content

Instantly share code, notes, and snippets.

@leejh3224
Created December 25, 2018 06:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leejh3224/f8cb80bbcbb85a5a2abc2d8b78319349 to your computer and use it in GitHub Desktop.
Save leejh3224/f8cb80bbcbb85a5a2abc2d8b78319349 to your computer and use it in GitHub Desktop.
it("should test `onUserCreate`", async () => {
const wrapped = testEnv.wrap(api.onUserCreate);
const testUser = {
uid: "122",
displayName: "lee"
};
await wrapped(testUser);
// generate user returns newUser object below
/*
const newUser = {
uid,
displayName,
points: 0,
questType: "view", // enum { view, sub }
questGoal: 30,
questActual: 10,
// valid for next 24 hours
questValidUntil: Date.now() + dayInMs
};
*/
const newUser = generateNewUser(testUser);
// check our db set function is called with expected parameter
expect(admin.database().ref(`/users/${testUser.uid}`).set).toBeCalledWith(newUser);
// check it returns mocked value as expected
expect(wrapped(testUser)).toBe(true);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment