1 | _ = require 'lodash'
|
2 | shmock = require 'shmock'
|
3 | ConfigurationGenerator = require '../src/configuration-generator'
|
4 | ConfigurationUtilities = require '../src/configuration-utilities'
|
5 |
|
6 | metadataRequestFlow = require './data/metadata-request-flow.json'
|
7 | metadataRequestFlow2 = require './data/metadata-request-flow-2.json'
|
8 |
|
9 | nodeRegistry = require './data/node-registry'
|
10 |
|
11 |
|
12 | describe 'Configuring EngineOutput to insert metadata into messages', ->
|
13 | beforeEach (done) ->
|
14 | @meshblu = shmock done
|
15 | @searchRequest = @meshblu.post '/search/devices'
|
16 |
|
17 | afterEach (done) ->
|
18 | @meshblu.close done
|
19 |
|
20 | beforeEach ->
|
21 | @meshbluJSON =
|
22 | server: 'localhost'
|
23 | port: @meshblu.address().port
|
24 | uuid: 'brave-user'
|
25 | token: 'who-fears-no-breaking-changes'
|
26 |
|
27 | @request = get: sinon.stub().yields null, {}, nodeRegistry
|
28 | @channelConfig =
|
29 | update: sinon.stub().yields null
|
30 | get: sinon.stub().returns {}
|
31 |
|
32 | describe '->configure', ->
|
33 | beforeEach ->
|
34 | options = meshbluJSON: @meshbluJSON
|
35 | dependencies =
|
36 | request: @request
|
37 | channelConfig: @channelConfig
|
38 |
|
39 | @sut = new ConfigurationGenerator options, dependencies
|
40 |
|
41 | context 'generating configuration with devices that want metadata', ->
|
42 | beforeEach ->
|
43 | @searchRequest.send
|
44 | uuid:
|
45 | $in: ['gimme-metadata', 'no-metadata-plz']
|
46 | 'octoblu.flow.forwardMetadata': true
|
47 | .reply(200, [uuid: 'gimme-metadata'])
|
48 |
|
49 | beforeEach (done) ->
|
50 | @channelConfig.update.yields null
|
51 | options =
|
52 | flowData: metadataRequestFlow
|
53 | flowToken: 'some-token'
|
54 | deploymentUuid: 'the-deployment-uuid'
|
55 |
|
56 | @sut.configure options, (@error, @flowConfig, flowStopConfig) =>
|
57 | {@forwardMetadataTo} = @flowConfig['engine-output'].config
|
58 | done()
|
59 |
|
60 | it 'should configure engine-output with the uuids of devices that want metadata injected into their messages', ->
|
61 | expect(@forwardMetadataTo).to.deep.equal ['gimme-metadata']
|
62 |
|
63 | context 'generating a configuration for a different flow', ->
|
64 | beforeEach ->
|
65 | @searchRequest.send
|
66 | uuid:
|
67 | $in: ['new-channel-as-device-overlord', 'metadata-luddite', 'fifth-element']
|
68 | 'octoblu.flow.forwardMetadata': true
|
69 | .reply(200, [{uuid: 'new-channel-as-device-overlord'}, {uuid: 'fifth-element'}])
|
70 |
|
71 | beforeEach (done) ->
|
72 | @channelConfig.update.yields null
|
73 | options =
|
74 | flowData: metadataRequestFlow2
|
75 | flowToken: 'some-token'
|
76 | deploymentUuid: 'the-deployment-uuid'
|
77 |
|
78 | @sut.configure options, (@error, @flowConfig, flowStopConfig) =>
|
79 | {@forwardMetadataTo} = @flowConfig['engine-output'].config
|
80 | done()
|
81 |
|
82 | it 'should configure engine-output with the uuids of devices that want metadata injected into their messages', ->
|
83 | expect(@forwardMetadataTo).to.deep.equal ['new-channel-as-device-overlord', 'fifth-element']
|
84 |
|
85 | context 'generating a configuration and something goes wrong with meshblu', ->
|
86 | beforeEach ->
|
87 | @searchRequest.reply(422)
|
88 |
|
89 | beforeEach (done) ->
|
90 | @channelConfig.update.yields null
|
91 | options =
|
92 | flowData: metadataRequestFlow2
|
93 | flowToken: 'some-token'
|
94 | deploymentUuid: 'the-deployment-uuid'
|
95 |
|
96 | @sut.configure options, (@error) => done()
|
97 |
|
98 | it 'should configure engine-output with the uuids of devices that want metadata injected into their messages', ->
|
99 | expect(@error).to.exist
|