Skip to content

Instantly share code, notes, and snippets.

@leejh3224
Created December 25, 2018 06:10
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/c3713de00e0c7e4612ada0b3e4a8679d to your computer and use it in GitHub Desktop.
Save leejh3224/c3713de00e0c7e4612ada0b3e4a8679d to your computer and use it in GitHub Desktop.
describe("my functions", () => {
let adminStub, api;
beforeAll(() => {
// you can use `sinon.stub` instead
adminStub = jest.spyOn(admin, "initializeApp");
// after initializeApp call, we load our functions
api = require("../index");
});
afterAll(() => {
// clean things up
adminStub.mockRestore();
testEnv.cleanup();
// reset our database
admin
.database()
.ref("users")
.remove();
});
it("should store user in db on GoogleOAuth", async () => {
const wrapped = testEnv.wrap(api.onUserCreate);
const testUser = {
uid: "122",
displayName: "lee"
};
// wrap your `onUserCreate` method and pass parameter: user
// for the sake of brevity, I omitted other `UserRecord` properties.
// you can check https://firebase.google.com/docs/reference/js/firebase.User for more information
await wrapped(testUser);
// we read our user from database
const createdUser = await admin
.database()
.ref(`/users/${testUser.uid}`)
.once("value");
// we expect our newly created user to have zero points
expect(createdUser.val()).toHaveProperty("points", 0);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment