meshblu-server-http
Version:
Maybe. Unofficial. You know how it is.
108 lines (83 loc) • 3.45 kB
text/coffeescript
_ = require 'lodash'
request = require 'request'
Server = require '../../src/server'
async = require 'async'
redis = require 'redis'
RedisNS = require '@octoblu/redis-ns'
JobManager = require 'meshblu-core-job-manager'
describe 'POST /v2/devices/:subscriberUuid/subscriptions/:emitterUuid/:type', ->
beforeEach (done) ->
= 0xd00d
= new Server
port:
disableLogging: true
jobTimeoutSeconds: 1
namespace: 'meshblu:server:http:test'
jobLogQueue: 'meshblu:job-log'
jobLogRedisUri: 'redis://localhost:6379'
meshbluHost: 'localhost'
meshbluPort: 3000
.run done
afterEach (done) ->
.stop => done()
beforeEach ->
= _.bindAll new RedisNS 'meshblu:server:http:test', redis.createClient()
= new JobManager client: , timeoutSeconds: 1
context 'when the request is successful', ->
beforeEach ->
async.forever (next) =>
.getRequest ['request'], (error, request) =>
next request
return unless request?
= request
response =
metadata:
code: 201
responseId: request.metadata.responseId
data: {}
.createResponse 'response', response, (error) =>
throw error if error?
beforeEach (done) ->
options =
auth:
username: 'irritable-captian'
password: 'poop-deck'
request.post "http://localhost:#{@port}/v2/devices/irritable-captian/subscriptions/another-uuid/broadcast", options, (error, , ) =>
done error
it 'should have the correct jobType', ->
expect(.metadata.jobType).to.equal 'CreateSubscription'
it 'should have the right toUuid', ->
expect(.metadata.toUuid).to.equal 'irritable-captian'
it 'should have the correct data', ->
expect(JSON.parse .rawData).to.deep.equal {subscriberUuid:'irritable-captian', emitterUuid: 'another-uuid', type: 'broadcast'}
it 'should return a 204', ->
expect(.statusCode).to.equal 204
context 'when the subscription already exists', ->
beforeEach ->
async.forever (next) =>
.getRequest ['request'], (error, request) =>
next request
return unless request?
= request
response =
metadata:
code: 304
responseId: request.metadata.responseId
data: {}
.createResponse 'response', response, (error) =>
throw error if error?
beforeEach (done) ->
options =
auth:
username: 'irritable-captian'
password: 'poop-deck'
request.post "http://localhost:#{@port}/v2/devices/irritable-captian/subscriptions/another-uuid/broadcast", options, (error, , ) =>
done error
it 'should have the correct jobType', ->
expect(.metadata.jobType).to.equal 'CreateSubscription'
it 'should have the right toUuid', ->
expect(.metadata.toUuid).to.equal 'irritable-captian'
it 'should have the correct data', ->
expect(JSON.parse .rawData).to.deep.equal {subscriberUuid:'irritable-captian', emitterUuid: 'another-uuid', type: 'broadcast'}
it 'should return a 204', ->
expect(.statusCode).to.equal 204