From 91d0c2d5c82bbf7c78c00b6bba3f7b25cd457c16 Mon Sep 17 00:00:00 2001 From: Niels Maerten Date: Sun, 10 Sep 2017 10:25:29 +0200 Subject: [PATCH] fix(connect-user): Use StubCreator to mock firebasse during tests By using StubCreator, the connect-user module can properly import the FirebaseClient. Importing using require does not work once compiled. This fixes a 500 error on Firebase where the firebaseClient module could not be found in connectUser --- test/eventhandlers/connect-user.test.ts | 26 ++++--------------------- test/helpers/stub-creator.ts | 4 +++- 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/test/eventhandlers/connect-user.test.ts b/test/eventhandlers/connect-user.test.ts index aaf8176..2d7d8f3 100644 --- a/test/eventhandlers/connect-user.test.ts +++ b/test/eventhandlers/connect-user.test.ts @@ -1,4 +1,5 @@ import Peppermint from "../../src/peppermint" +import StubCreator from "../helpers/stub-creator" import { assert } from "chai" describe("Peppermint.connectUser", () => { @@ -8,30 +9,11 @@ describe("Peppermint.connectUser", () => { post: jest.fn().mockReturnValue({ access_token: "" }) } }) - jest.mock("firebase-functions", () => { - return { - config: () => { - return { - dropbox: { - client_id: "XXX", - client_secret: "XXX" - }, - oauth: { - redirect_after_connect: "https://google.com" - } - } - } - } - }) - jest.mock("../../src/clients/firebase-client", () => { - return { - getInstance: jest.fn().mockReturnValue({ - addUser: jest.fn() - }) - } - }) + StubCreator.stubFirebase() }) + afterEach(StubCreator.restoreFirebase) + it("should exchange an authCode for an access token", async () => { let authUrl = await Peppermint.connectUser({ query: { code: "FAKE_AUTH_CODE" } diff --git a/test/helpers/stub-creator.ts b/test/helpers/stub-creator.ts index b47560f..3fa12e7 100644 --- a/test/helpers/stub-creator.ts +++ b/test/helpers/stub-creator.ts @@ -30,7 +30,9 @@ export default class StubCreator { // Fake urls, because Firebase complains if we leave them undefined databaseURL: "https://mock-firebase.firebaseio.com", storageBucket: "mock-firebase.appspot.com" - } + }, + dropbox: {}, + oauth: {} }) // Create stub firebase database and enable autoflushing