triggers-service
Version:
Service to list and activate Octoblu triggers within running flows
144 lines (109 loc) • 3.85 kB
text/coffeescript
http = require 'http'
request = require 'request'
shmock = require 'shmock'
Server = require '../../src/server'
fs = require 'fs'
fakeFlow = require './fake-flow.json'
enableDestroy = require 'server-destroy'
describe 'POST /flows/:flowId/triggers/:triggerId', ->
beforeEach (done) ->
= shmock done
enableDestroy
afterEach (done) ->
.destroy done
beforeEach (done) ->
meshbluConfig =
hostname: 'localhost'
port: .address().port
protocol: 'http'
uuid: 'trigger-service-uuid'
token: 'trigger-service-token'
serverOptions =
port: undefined,
disableLogging: true
meshbluConfig: meshbluConfig
= new Server serverOptions
.run =>
= .address().port
done()
afterEach (done) ->
.stop => done()
context 'when authed', ->
context 'when posting json', ->
beforeEach (done) ->
auth =
username: 'ai-turns-hostile'
password: 'team-token'
options =
auth: auth
json: true
.post('/authenticate')
.reply 200, uuid: 'ai-turns-hostile', token: 'team-token'
= .post('/messages')
.reply 201
request.post "http://localhost:#{@serverPort}/flows/foo/triggers/bar", options, (error, , ) =>
done error
it 'should return the triggers', ->
expect(.statusCode).to.equal 201
it 'should post the message', ->
.done()
it 'should respond with the triggered: true', ->
expect(.triggered).to.be.true
context 'when posting a multipart form', ->
beforeEach (done) ->
auth =
username: 'ai-turns-hostile'
password: 'team-token'
formData =
custom_file:
value: new Buffer('{foo: bar}')
options:
filename: 'somefile',
contentType: 'application/json'
options =
auth: auth
formData: formData
.post('/authenticate')
.reply 200, uuid: 'ai-turns-hostile', token: 'team-token'
message =
devices: [ 'foo' ]
topic: 'triggers-service'
payload:
from: 'bar'
params: {}
payload: {}
files:
somefile:
mimeType: 'application/json'
data: '{foo: bar}'
fieldName: 'custom_file'
originalName: 'somefile'
encoding: '7bit'
size: 10
= .post('/messages')
.send message
.reply 201
request.post "http://localhost:#{@serverPort}/flows/foo/triggers/bar", options, (error, , ) =>
done error
it 'should return the triggers', ->
expect(.statusCode).to.equal 201
it 'should post the message', ->
.done()
it 'should respond with the triggered: true', ->
expect().to.equal '{"triggered":true}'
context 'when not authed', ->
beforeEach (done) ->
options =
json: true
.post('/authenticate')
.reply 200, uuid: 'ai-turns-hostile', token: 'team-token'
= .post('/messages')
.reply 201
request.post "http://localhost:#{@serverPort}/flows/foo/triggers/bar", options, (error, , ) =>
done error
it 'should return the triggers', ->
expect(.statusCode).to.equal 201
it 'should post the message', ->
.done()
it 'should respond with the triggered: true', ->
expect(.triggered).to.be.true