Skip to content

Commit

Permalink
Merge pull request NangoHQ#40 from Bearer/fix/make-proxy-request-work…
Browse files Browse the repository at this point in the history
…-correctly

Fix/make proxy request work correctly
  • Loading branch information
tanguyantoine authored May 29, 2020
2 parents 8e88edc + 85bdf4e commit d298f76
Show file tree
Hide file tree
Showing 18 changed files with 330 additions and 445 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"editor.formatOnSave": true,
"javascript.format.enable": false,
"typescript.tsdk": "node_modules/typescript/lib",
}
1 change: 1 addition & 0 deletions config/config.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version: '3'
services:
database:
image: postgres
18 changes: 12 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"prepare": "npm run build",
"build": "rimraf dist/ && tsc -p tsconfig.json",
"start": "node dist/src",
"dev": "concurrently 'yarn dev:build' 'yarn dev:serve' ",
"dev:build": "yarn build --watch",
"dev:serve": "nodemon --delay 1 --watch dist/src node dist/src",
"db:setup": "npm run db:create && npm run db:migrate",
"db:create": "node dist/src/lib/database/config/create",
"db:migrate": "knex --cwd dist/src/lib/database/config migrate:latest",
Expand All @@ -30,6 +33,7 @@
"ejs": "^3.0.2",
"express": "^4.16.3",
"express-session": "^1.15.6",
"express-winston": "^4.0.3",
"js-cookie": "^2.2.0",
"jsonwebtoken": "^8.5.1",
"knex": "^0.21.1",
Expand All @@ -42,7 +46,8 @@
"passport-oauth1": "^1.1.0",
"pg": "^8.0.3",
"simple-oauth2": "^3.0.0",
"uuid": "^7.0.3"
"uuid": "^7.0.3",
"winston": "^3.2.1"
},
"devDependencies": {
"@commitlint/cli": "^7.2.1",
Expand All @@ -65,7 +70,7 @@
"@types/wreck": "^14.0.0",
"babel-loader": "^8.0.5",
"commitlint": "^7.2.1",
"concurrently": "^5.1.0",
"concurrently": "^5.2.0",
"cz-conventional-changelog": "^2.1.0",
"file-loader": "^3.0.1",
"html-loader": "^1.1.0",
Expand All @@ -83,7 +88,7 @@
"ts-jest": "^23.10.5",
"ts-loader": "^5.3.3",
"ts-node": "^8.10.1",
"typescript": "^3.2.2"
"typescript": "^3.9.3"
},
"jest": {
"collectCoverageFrom": [
Expand All @@ -97,7 +102,7 @@
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testRegex": "(.*/views/.*)((test|spec))\\.(jsx?|tsx?)$",
"testRegex": "(.*/clients/.*)((test|spec))\\.(jsx?|tsx?)$",
"moduleFileExtensions": [
"ts",
"tsx",
Expand All @@ -123,13 +128,14 @@
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"testRegex": "(.*/src/lib/.*)(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"modulePathIgnorePatterns": [
"<rootDir>/dist/"
],
"testPathIgnorePatterns": [
"/node_modules/",
"/views/"
"/views/",
"legacy"
],
"moduleFileExtensions": [
"ts",
Expand Down
64 changes: 0 additions & 64 deletions src/clients/javascript/test/connect.test.js

This file was deleted.

76 changes: 76 additions & 0 deletions src/clients/javascript/test/connect.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import Pizzly from '../src/index'

describe('Connect', () => {
beforeAll(() => {
window.addEventListener = jest.fn()
// @ts-ignore
window.open = jest.fn(() => {
return { closed: false }
})
})

const publishableKey = 'foo'
const integration = 'github'

function setup() {
return new Pizzly(publishableKey)
}

describe('connect', () => {
it('is a function', () => {
const pizzly = setup()

expect(pizzly.connect).toBeInstanceOf(Function)
})

it('accepts an integration argument', () => {
const pizzly = setup()

expect(pizzly.connect(integration)).toBeInstanceOf(Promise)
})

it('must have an integration argument', () => {
const pizzly = setup()
expect(() => {
// @ts-expect-error
return pizzly.connect()
}).toThrowError()
})

it('accepts an (optional) options argument', () => {
const pizzly = setup()

expect(pizzly.connect(integration, {})).toBeInstanceOf(Promise)
})
})

it('opens a popup (window modal)', () => {
const pizzly = setup()
expect.assertions(1)

pizzly.connect(integration).catch()

expect(window.open).toHaveBeenCalled()
})

// More tests to add on that:
// - it opens a popup with this URL
// - it opens a popup with this size
// - it opens a popup with this position

it('listens to message', () => {
const pizzly = setup()
expect.assertions(1)

pizzly.connect(integration).catch()

expect(window.addEventListener).toHaveBeenCalledWith('message', expect.any(Function), false)
})

describe('Return values', () => {
// More test to add here:
// it returns a promise
// it returns an object on promise.resolve
// it returns an error on promise.reject
})
})
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const Pizzly = require('../dist/index.umd.js')
import Pizzly from '../src/index'

describe('Pizzly class', () => {
const publishableKey = 'foo'
Expand All @@ -13,6 +13,7 @@ describe('Pizzly class', () => {

it('accepts no arguments', () => {
expect(() => {
// @ts-expect-error
new Pizzly()
}).not.toThrowError()
})
Expand All @@ -31,6 +32,7 @@ describe('Pizzly class', () => {

it('accepts invalid options', () => {
expect(() => {
// @ts-expect-error
new Pizzly(publishableKey, invalidOptions)
}).toBeInstanceOf(Function)
})
Expand Down
11 changes: 5 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import express from 'express'

import * as routes from './routes'
import { requestLogger, errorLogger } from './lib/utils/logger'

export const BUID = 'bearerUid' // TODO - What is this for?
export const PORT = process.env.PORT || 8080
Expand All @@ -12,13 +14,9 @@ app.set('trust proxy', 1)
app.use('/assets', express.static('./views/assets'))

/**
* Logging request
* Request log
*/

app.use((req, res, next) => {
console.log(new Date().toISOString(), req.method, req.originalUrl)
next()
})
app.use(requestLogger)

/**
* Project homepage
Expand Down Expand Up @@ -67,6 +65,7 @@ app.use('/api/v4/functions', routes.legacy.proxy)
* Error handling
*/

app.use(errorLogger)
app.use((req, res, next) => {
res.status(404).render('404')
})
Expand Down
22 changes: 0 additions & 22 deletions src/legacy/auth/v3/strategies/__snapshots__/api-key.test.ts.snap

This file was deleted.

22 changes: 0 additions & 22 deletions src/legacy/auth/v3/strategies/__snapshots__/basic.test.ts.snap

This file was deleted.

44 changes: 0 additions & 44 deletions src/legacy/functions/__snapshots__/lambda-request.test.ts.snap

This file was deleted.

Loading

0 comments on commit d298f76

Please sign in to comment.