Skip to content
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

Update connect-user.ts #22

Merged
merged 2 commits into from
Sep 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/eventhandlers/connect-user.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Config from "../objects/config"
import User from "../objects/user"
import FirebaseClient from "../clients/firebase-client"

export default async (req: any): Promise<string> => {
const request = require("request-promise")
const functions = require("firebase-functions")
const FirebaseClient = require("../clients/firebase-client")
const firebaseConfig =
(global as any).peppermintFirebaseConfig || functions.config()

Expand Down
26 changes: 4 additions & 22 deletions test/eventhandlers/connect-user.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Peppermint from "../../src/peppermint"
import StubCreator from "../helpers/stub-creator"
import { assert } from "chai"

describe("Peppermint.connectUser", () => {
Expand All @@ -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" }
Expand Down
4 changes: 3 additions & 1 deletion test/helpers/stub-creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down