Created
December 25, 2018 06:10
-
-
Save leejh3224/c3713de00e0c7e4612ada0b3e4a8679d to your computer and use it in GitHub Desktop.
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
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