UNPKG

2.53 kBtext/coffeescriptView Raw
1{afterEach, beforeEach, describe, it} = global
2{expect} = require 'chai'
3sinon = require 'sinon'
4
5_ = require 'lodash'
6enableDestroy = require 'server-destroy'
7shmock = require 'shmock'
8SocketIO = require 'socket.io'
9
10
11Inquisitor = require '..'
12
13describe 'getMonitoredDevices', ->
14 beforeEach ->
15
16 meshbluConfig =
17 uuid: 'user-uuid'
18 token: 'user-token'
19 hostname: 'localhost'
20 port: 0xd00d
21 protocol: 'http'
22
23 uuid = 'inquisitor-uuid'
24
25 @userAuth = new Buffer('user-uuid:user-token').toString 'base64'
26 @sut = new Inquisitor {meshbluConfig, uuid}
27
28 it 'should exist', ->
29 expect(@sut).to.exist
30
31 describe '->getMonitoredDevices', ->
32 beforeEach 'meshblu', ->
33 @meshblu = shmock 0xd00d
34 enableDestroy(@meshblu)
35
36 afterEach (done) ->
37 @meshblu.destroy done
38
39 beforeEach ->
40 @meshblu
41 .get "/v2/devices/inquisitor-uuid/subscriptions"
42 .set 'Authorization', "Basic #{@userAuth}"
43 .reply 200, [
44 {subscriberUuid: 'inquisitor-uuid', emitterUuid: 'device-1', type: 'configure.received'}
45 {subscriberUuid: 'inquisitor-uuid', emitterUuid: 'inquisitor-uuid', type: 'configure.received'}
46 {subscriberUuid: 'inquisitor-uuid', emitterUuid: 'device-2', type: 'configure.received'}
47 {subscriberUuid: 'inquisitor-uuid', emitterUuid: 'status-device', type: 'configure.received'}
48 ]
49
50 beforeEach 'search', ->
51 @meshblu
52 .post '/search/devices'
53 .set 'Authorization', "Basic #{@userAuth}"
54 .send uuid: $in: ['device-1', 'device-2', 'status-device']
55 .reply 200, [
56 {uuid: 'status-device', errors: ['look-an-error']}
57 {uuid: 'device-1', statusDevice: 'status-device'}
58 {uuid: 'device-2', errors: ['yet-another-error']}
59 ]
60
61 beforeEach (done) ->
62 @sut.getMonitoredDevices (error, @devicesAndErrors) => done()
63 return null
64
65 it 'should return an array of objects containing errors associated with devices', ->
66 expected = [
67 {
68 uuid: 'device-1'
69 device: { uuid: 'device-1', statusDevice: 'status-device' }
70 statusDevice: 'status-device'
71 errors: ['look-an-error']
72 }
73 {
74 uuid: 'device-2'
75 device: { uuid: 'device-2', errors: ['yet-another-error'] }
76 statusDevice: 'device-2'
77 errors: ['yet-another-error']
78 }
79 ]
80 expect(@devicesAndErrors).to.deep.equal expected