2014-10-31 18:47:18 +00:00
|
|
|
expect = require('chai').expect
|
|
|
|
nock = require('nock')
|
|
|
|
auth = require('./auth')
|
|
|
|
config = require('../../config')
|
2014-10-31 19:19:16 +00:00
|
|
|
johnDoeFixture = require('../../../tests/fixtures/johndoe')
|
2014-10-31 18:47:18 +00:00
|
|
|
|
2014-11-07 16:43:10 +00:00
|
|
|
describe 'Auth:', ->
|
2014-10-31 18:47:18 +00:00
|
|
|
|
|
|
|
describe 'given valid credentials', ->
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
nock(config.baseUrl)
|
|
|
|
.post('/login_', johnDoeFixture.credentials)
|
|
|
|
.reply(200, johnDoeFixture.token)
|
|
|
|
|
|
|
|
describe '#getToken()', ->
|
|
|
|
|
|
|
|
it 'should return a token string', (done) ->
|
|
|
|
auth.getToken johnDoeFixture.credentials, (error, token) ->
|
|
|
|
return done(error) if error?
|
|
|
|
expect(token).to.be.a('string')
|
|
|
|
expect(token).to.equal(johnDoeFixture.token)
|
|
|
|
done()
|
|
|
|
|
|
|
|
describe 'given invalid credentials', ->
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
nock(config.baseUrl)
|
|
|
|
.post('/login_')
|
|
|
|
.reply(401)
|
|
|
|
|
|
|
|
describe '#getToken()', ->
|
|
|
|
|
|
|
|
it 'should return an error', (done) ->
|
|
|
|
auth.getToken johnDoeFixture.credentials, (error, token) ->
|
|
|
|
expect(error).to.exist
|
|
|
|
expect(error).to.be.an.instanceof(Error)
|
|
|
|
done()
|