Skip to content

Instantly share code, notes, and snippets.

@grantcarthew
Created March 2, 2019 07:50
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 grantcarthew/9a13cf1f12bda28a1c4257cf15af0e10 to your computer and use it in GitHub Desktop.
Save grantcarthew/9a13cf1f12bda28a1c4257cf15af0e10 to your computer and use it in GitHub Desktop.
medium-http-setup.js
// http-setup.js
const axios = require('axios')
const app = require('../../src/server')
const log = require('../../src/logger').child(module)
module.exports = async function httpSetup () {
log.info('HTTP test setup initiated')
const listener = app.listen()
const port = listener.address().port
const baseURL = `http://localhost:${port}/api`
axios.defaults.baseURL = baseURL
const authRes = await axios.post('/auth/signin', { email: 'test@test.com', password: 'secret' })
const cookie = authRes.headers['set-cookie']
axios.defaults.headers.common['Cookie'] = String(cookie)
log.info('HTTP test setup complete')
return listener
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment