1 | _ = require 'lodash'
|
2 | request = require 'request'
|
3 | Server = require '../../src/server'
|
4 | async = require 'async'
|
5 | redis = require 'redis'
|
6 | RedisNS = require '@octoblu/redis-ns'
|
7 | JobManager = require 'meshblu-core-job-manager'
|
8 |
|
9 | describe 'GET /v2/whoami', ->
|
10 | beforeEach (done) ->
|
11 | @port = 0xd00d
|
12 | @sut = new Server
|
13 | port: @port
|
14 | disableLogging: true
|
15 | jobTimeoutSeconds: 1
|
16 | namespace: 'meshblu:server:http:test'
|
17 | jobLogQueue: 'meshblu:job-log'
|
18 | jobLogRedisUri: 'redis://localhost:6379'
|
19 | meshbluHost: 'localhost'
|
20 | meshbluPort: 3000
|
21 |
|
22 | @sut.run done
|
23 |
|
24 | afterEach (done) ->
|
25 | @sut.stop => done()
|
26 |
|
27 | beforeEach ->
|
28 | @redis = _.bindAll new RedisNS 'meshblu:server:http:test', redis.createClient()
|
29 | @jobManager = new JobManager client: @redis, timeoutSeconds: 1
|
30 |
|
31 | context 'when the request is successful', ->
|
32 | beforeEach ->
|
33 | async.forever (next) =>
|
34 | @jobManager.getRequest ['request'], (error, request) =>
|
35 | next request
|
36 | return unless request?
|
37 |
|
38 | response =
|
39 | metadata:
|
40 | code: 200
|
41 | responseId: request.metadata.responseId
|
42 | coffeeCake: "is delicious"
|
43 | data:
|
44 | uuid: 'irritable-captian'
|
45 |
|
46 | @jobManager.createResponse 'response', response, (error) =>
|
47 | throw error if error?
|
48 |
|
49 | beforeEach (done) ->
|
50 | options =
|
51 | auth:
|
52 | username: 'irritable-captian'
|
53 | password: 'poop-deck'
|
54 |
|
55 | request.get "http://localhost:#{@port}/v2/whoami", options, (error, @response, @body) =>
|
56 | done error
|
57 |
|
58 | it 'should return a 200', ->
|
59 | expect(@response.statusCode).to.equal 200
|
60 |
|
61 | it 'should have the device in the body', ->
|
62 | expect(JSON.parse(@body)).to.contain uuid: 'irritable-captian'
|
63 |
|
64 | it 'should have the metadata in the headers', ->
|
65 | expect(@response.headers).to.containSubset
|
66 | 'x-meshblu-code': '200'
|
67 | 'x-meshblu-coffee-cake': 'is delicious'
|