Created
March 2, 2019 07:50
-
-
Save grantcarthew/9a13cf1f12bda28a1c4257cf15af0e10 to your computer and use it in GitHub Desktop.
medium-http-setup.js
This file contains hidden or 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
// 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: '[email protected]', 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