Promisify auth utils tests

This commit is contained in:
Tim Perry 2018-03-28 17:47:45 +02:00
parent 2db1d84d3c
commit 0e2fb8c96c

View File

@ -9,39 +9,36 @@ describe 'Utils:', ->
describe '.getDashboardLoginURL()', ->
it 'should eventually be a valid url', (done) ->
it 'should eventually be a valid url', ->
utils.getDashboardLoginURL('https://127.0.0.1:3000/callback').then (loginUrl) ->
m.chai.expect ->
url.parse(loginUrl)
.to.not.throw(Error)
.nodeify(done)
it 'should eventually contain an https protocol', (done) ->
it 'should eventually contain an https protocol', ->
Promise.props
dashboardUrl: resin.settings.get('dashboardUrl')
loginUrl: utils.getDashboardLoginURL('https://127.0.0.1:3000/callback')
.then ({ dashboardUrl, loginUrl }) ->
protocol = url.parse(loginUrl).protocol
m.chai.expect(protocol).to.equal(url.parse(dashboardUrl).protocol)
.nodeify(done)
it 'should correctly escape a callback url without a path', (done) ->
it 'should correctly escape a callback url without a path', ->
Promise.props
dashboardUrl: resin.settings.get('dashboardUrl')
loginUrl: utils.getDashboardLoginURL('http://127.0.0.1:3000')
.then ({ dashboardUrl, loginUrl }) ->
expectedUrl = "#{dashboardUrl}/login/cli/http%253A%252F%252F127.0.0.1%253A3000"
m.chai.expect(loginUrl).to.equal(expectedUrl)
.nodeify(done)
it 'should correctly escape a callback url with a path', (done) ->
it 'should correctly escape a callback url with a path', ->
Promise.props
dashboardUrl: resin.settings.get('dashboardUrl')
loginUrl: utils.getDashboardLoginURL('http://127.0.0.1:3000/callback')
.then ({ dashboardUrl, loginUrl }) ->
expectedUrl = "#{dashboardUrl}/login/cli/http%253A%252F%252F127.0.0.1%253A3000%252Fcallback"
m.chai.expect(loginUrl).to.equal(expectedUrl)
.nodeify(done)
describe '.isTokenValid()', ->
@ -76,26 +73,24 @@ describe 'Utils:', ->
describe 'given there was a token already', ->
beforeEach (done) ->
resin.auth.loginWithToken(tokens.janedoe.token).nodeify(done)
beforeEach ->
resin.auth.loginWithToken(tokens.janedoe.token)
it 'should preserve the old token', (done) ->
it 'should preserve the old token', ->
resin.auth.getToken().then (originalToken) ->
m.chai.expect(originalToken).to.equal(tokens.janedoe.token)
return utils.isTokenValid(tokens.johndoe.token)
.then(resin.auth.getToken).then (currentToken) ->
m.chai.expect(currentToken).to.equal(tokens.janedoe.token)
.nodeify(done)
describe 'given there was no token', ->
beforeEach (done) ->
resin.auth.logout().nodeify(done)
beforeEach ->
resin.auth.logout()
it 'should stay without a token', (done) ->
it 'should stay without a token', ->
utils.isTokenValid(tokens.johndoe.token).then ->
m.chai.expect(resin.token.get()).to.eventually.not.exist
.nodeify(done)
describe 'given the token does authenticate with the server', ->