balena-cli/lib/helpers/helpers.spec.coffee

38 lines
1.1 KiB
CoffeeScript
Raw Normal View History

expect = require('chai').expect
2014-11-28 19:36:03 +00:00
sinon = require('sinon')
_ = require('lodash')
helpers = require('./helpers')
2015-01-08 12:04:37 +00:00
resin = require('resin-sdk')
describe 'Helpers:', ->
2014-12-22 19:48:11 +00:00
describe '#parseCredentials', ->
describe 'given colon separated credentials', ->
username = null
password = null
beforeEach ->
username = 'johndoe'
password = 'mysecret'
it 'should parse the credentials correctly', (done) ->
helpers.parseCredentials "#{username}:#{password}", (error, credentials) ->
expect(error).to.not.exist
expect(credentials.username).to.equal(username)
expect(credentials.password).to.equal(password)
done()
it 'should throw an error if it has two or more colons', (done) ->
helpers.parseCredentials "#{username}:#{password}:#{username}", (error, credentials) ->
expect(error).to.be.an.instanceof(Error)
expect(credentials).to.not.exist
done()
it 'should throw an error if only the username is passed', (done) ->
helpers.parseCredentials username, (error, credentials) ->
expect(error).to.be.an.instanceof(Error)
expect(credentials).to.not.exist
done()