nanocyte-configuration-generator
Version:
Generate Nanocyte configuration from an Octoblu flow
87 lines (67 loc) • 3.08 kB
text/coffeescript
ChannelConfig = require '../src/channel-config'
{EventEmitter} = require 'events'
describe 'ChannelConfig', ->
beforeEach ->
= new EventEmitter
= downloadFile: sinon.spy(=> )
= readFile: sinon.stub()
= new ChannelConfig {},
s3client:
jsonfile:
describe '-> fetch', ->
describe 'when called', ->
beforeEach ->
= sinon.spy()
.fetch
it 'should call s3.downloadFile', ->
expect(.downloadFile).to.have.been.calledWith
localFile: './channels.json'
s3Params:
Bucket: 'octoblu-channels'
Key: 'channels.json'
it 'should NOT YET call @jsonfile.readFile', ->
expect(.readFile).not.to.have.been.called #yet #soon
describe 'when the downloader emits an error', ->
beforeEach ->
= new Error 'download failure'
.emit 'error',
it 'should call the callback with the error', ->
expect().to.have.been.calledWith
describe 'when the downloader completes', ->
beforeEach ->
.emit 'end'
it 'should read the file', ->
expect(.readFile).to.have.been.calledWith './channels.json'
describe 'when readFile works', ->
beforeEach ->
.readFile.yield null, {"exasperation":"I-cannot-freaking-believe-this"}
it 'should set @sut._channels', ->
expect(._channels).to.deep.equal exasperation: "I-cannot-freaking-believe-this"
it 'should call the callback without an error', ->
expect().to.have.been.called
expect(.firstArg).not.to.exist
describe 'when readFile no worky', ->
beforeEach ->
= new Error 'Gored, then devoured'
.readFile.yield
it 'should yield the error', ->
expect().to.have.been.calledWith
describe '-> get', ->
describe 'when fetch has not been called', ->
beforeEach ->
delete ._channels
it 'should throw an exception', ->
func = => .get 'channel:red-dwarf'
expect(func).to.throw 'Cannot call get before fetch'
describe 'when fetch has been called', ->
beforeEach ->
._channels = [{stellar: 'body', type: 'channel:red-dwarf'}]
= .get 'channel:red-dwarf'
it 'should return a channel', ->
expect().to.deep.equal stellar: 'body', type: 'channel:red-dwarf'
describe 'when fetch has really been called', ->
beforeEach ->
._channels = [{'ice-cream': 'cone', type: 'channel:something-cold'}]
= .get 'channel:something-cold'
it 'should return a channel', ->
expect().to.deep.equal 'ice-cream': 'cone', type: 'channel:something-cold'