From 0e2fb8c96c672e503561f28454fd6ec342c66fd6 Mon Sep 17 00:00:00 2001 From: Tim Perry Date: Wed, 28 Mar 2018 17:47:45 +0200 Subject: [PATCH] Promisify auth utils tests --- tests/auth/utils.spec.coffee | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/tests/auth/utils.spec.coffee b/tests/auth/utils.spec.coffee index 152b32c2..2c1ab637 100644 --- a/tests/auth/utils.spec.coffee +++ b/tests/auth/utils.spec.coffee @@ -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', ->