UNPKG

1.03 kBtext/coffeescriptView Raw
1Exchange = require '../index'
2_ = require 'lodash'
3
4describe 'Connection', ->
5 randomQueue = "test queue #{ String(Math.random()).substring 1 }"
6 ex2 = null
7
8 ## make sure test queue is bound to test.exchange2 before running any tests
9 before (done)->
10 ex2 = new Exchange 'test.exchange2', {host:'localhost'}, {logLevel:'FATAL'}
11
12 ex2.exchangeReady
13 .then -> ex2.getQueue(randomQueue)
14 .then -> ex2.bindQueue(randomQueue, 'long.#.pattern')
15 .then -> done()
16
17 after ->
18 ex2.queues[randomQueue].destroy()
19
20 it 'should connect', (done)->
21 ex = new Exchange 'test.exchange', {host:'localhost'}, {logLevel:'WARN'}
22 ex.exchangeReady.then (ex) -> done()
23
24 it 'should be able to subscribe and push immediately', (done)->
25 ex = new Exchange 'test.exchange2', {host:'localhost'}, {logLevel:'WARN'}
26 ex.subscribe randomQueue, (message, headers, deliveryInfo, messageObj) ->
27 message.text.should.equal 'test message'
28 done()
29
30 ex.push {text: 'test message'}, {}, 'long.rabbitmq.pattern'