Decouple resin sdk from it's surroundings

This commit is contained in:
Juan Cruz Viotti 2015-01-06 15:02:03 -03:00
parent 07c57d335b
commit 8ac36ced4d
6 changed files with 42 additions and 38 deletions

View File

@ -1,5 +1,4 @@
_ = require('lodash') _ = require('lodash')
isOnline = require('is-online')
CONNECTION_PARAMETERS = [ CONNECTION_PARAMETERS = [
'network' 'network'
@ -7,10 +6,6 @@ CONNECTION_PARAMETERS = [
'wifiKey' 'wifiKey'
] ]
# A wrapper around isOnline in order
# to be able to stub it with Sinon
exports.isOnline = isOnline
validateEthernetConnectionParameters = (parameters = {}) -> validateEthernetConnectionParameters = (parameters = {}) ->
return if not parameters.wifiSsid? and not parameters.wifiKey? return if not parameters.wifiSsid? and not parameters.wifiKey?
return new Error('You can only use wifi options if network is wifi') return new Error('You can only use wifi options if network is wifi')

View File

@ -5,37 +5,6 @@ connection = require('./connection')
describe 'Connection:', -> describe 'Connection:', ->
describe '#isOnline()', ->
stubIsOnline = (expectations, args...) ->
isOnlineStub = sinon.stub(connection, 'isOnline')
isOnlineStub.yields(args...)
connection.isOnline (error, isOnline) ->
expectations.apply(null, arguments)
isOnlineStub.restore()
it 'should be able to return true', (done) ->
stubIsOnline (error, isOnline) ->
expect(error).to.not.exist
expect(isOnline).to.be.true
done()
, null, true
it 'should be able to return false', (done) ->
stubIsOnline (error, isOnline) ->
expect(error).to.not.exist
expect(isOnline).to.be.false
done()
, null, false
it 'should be able to return an error', (done) ->
stubIsOnline (error, isOnline) ->
expect(error).to.be.an.instanceof(Error)
expect(isOnline).to.not.exist
done()
, new Error()
describe '#parseConnectionParameters()', -> describe '#parseConnectionParameters()', ->
checkParamsSuccess = (params, done) -> checkParamsSuccess = (params, done) ->

View File

@ -0,0 +1,3 @@
# A wrapper around isOnline in order
# to be able to stub it with Sinon
exports.isOnline = require('is-online')

View File

@ -0,0 +1,37 @@
expect = require('chai').expect
_ = require('lodash')
sinon = require('sinon')
connection = require('./connection')
describe 'Connection:', ->
describe '#isOnline()', ->
stubIsOnline = (expectations, args...) ->
isOnlineStub = sinon.stub(connection, 'isOnline')
isOnlineStub.yields(args...)
connection.isOnline (error, isOnline) ->
expectations.apply(null, arguments)
isOnlineStub.restore()
it 'should be able to return true', (done) ->
stubIsOnline (error, isOnline) ->
expect(error).to.not.exist
expect(isOnline).to.be.true
done()
, null, true
it 'should be able to return false', (done) ->
stubIsOnline (error, isOnline) ->
expect(error).to.not.exist
expect(isOnline).to.be.false
done()
, null, false
it 'should be able to return an error', (done) ->
stubIsOnline (error, isOnline) ->
expect(error).to.be.an.instanceof(Error)
expect(isOnline).to.not.exist
done()
, new Error()

View File

@ -2,7 +2,7 @@ _ = require('lodash')
request = require('request') request = require('request')
progress = require('request-progress') progress = require('request-progress')
async = require('async') async = require('async')
connection = require('../../connection/connection') connection = require('../_connection/connection')
settings = require('../settings') settings = require('../settings')
auth = require('../auth/auth') auth = require('../auth/auth')

View File

@ -1,7 +1,7 @@
mockFs = require('mock-fs') mockFs = require('mock-fs')
sinon = require('sinon') sinon = require('sinon')
resin = require('../../lib/resin') resin = require('../../lib/resin')
connection = require('../../lib/connection/connection') connection = require('../../lib/resin/_connection/connection')
exports.fs = exports.fs =