meshblu-server-http
Version:
Maybe. Unofficial. You know how it is.
63 lines (50 loc) • 1.8 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 'GET /v2/whoami', ->
beforeEach (done) ->
= 0xd00d
= new Server
port:
disableLogging: true
jobTimeoutSeconds: 1
namespace: 'meshblu:server:http:test'
.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?
response =
metadata:
code: 200
responseId: request.metadata.responseId
coffeeCake: "is delicious"
data:
uuid: 'irritable-captian'
.createResponse 'response', response
beforeEach (done) ->
options =
auth:
username: 'irritable-captian'
password: 'poop-deck'
request.get "http://localhost:#{@port}/v2/whoami", options, (error, , ) =>
done error
it 'should return a 200', ->
expect(.statusCode).to.equal 200
it 'should have the device in the body', ->
expect(JSON.parse()).to.contain uuid: 'irritable-captian'
it 'should have the metadata in the headers', ->
expect(.headers).to.containSubset
'x-meshblu-code': '200'
'x-meshblu-coffeecake': 'is delicious'