Skip to content

Commit

Permalink
Merge branch 'master' of github.com:5app/digital-hub-api
Browse files Browse the repository at this point in the history
  • Loading branch information
MrSwitch committed Mar 27, 2018
2 parents 6c18500 + 9afe22b commit ae5bd8d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
"chai": "^4.1.2",
"coveralls": "^3.0.0",
"csv-parse": "^2.0.0",
"dotenv": "^4.0.0",
"dotenv": "^5.0.0",
"eslint": "^4.11.0",
"eslint-config-5app": "^0.1.0",
"mocha": "^4.0.1",
"mocha": "^5.0.0",
"mockery": "^2.1.0",
"nyc": "^11.3.0",
"yamljs": "^0.3.0"
Expand Down
6 changes: 5 additions & 1 deletion src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ module.exports = class Hub {

// Get the token
const access_token = await this.login()
extend(options, {qs: {access_token}})
extend(options, {
headers: {
Authorization: `Bearer ${access_token}`
}
})

// Prefix the path
options.path = path.join('/v2/service/', options.path)
Expand Down
13 changes: 8 additions & 5 deletions test/specs/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('Digital Hub API', () => {
expect(hub).to.be.instanceof(Hub)
})

it('should trigger a request and append an access_token', done => {
it('should trigger a request and append an auth token to the headers', done => {

const hub = new Hub({
tenant,
Expand All @@ -55,7 +55,7 @@ describe('Digital Hub API', () => {
path: '/api'
})
.then(resp => {
expect(resp.qs).to.have.property('access_token', 'token')
expect(resp.headers).to.have.property('Authorization', 'Bearer token')
expect(resp).to.have.property('uri', `https://${tenant}/v2/service/api`)
done()
})
Expand Down Expand Up @@ -135,7 +135,7 @@ describe('Digital Hub API', () => {
path: '/api'
})
.then(resp => {
expect(resp.qs).to.have.property('access_token', hub.access_token)
expect(resp.headers).to.have.property('Authorization', 'Bearer inst_token')
done()
})
.catch(done)
Expand All @@ -156,15 +156,18 @@ describe('Digital Hub API', () => {
hub.api({
path: '/api',
qs: {
json
json,
a: 1
}
})
.then(resp => {
expect(resp.qs).to.have.property('json', '{"key":"value"}')
expect(resp.qs).to.have.property('a', 1)
expect(resp.qs).to.not.have.property('token')
expect(resp.qs).to.not.have.property('access_token')
done()
})
.catch(done)

})

})

0 comments on commit ae5bd8d

Please sign in to comment.