Skip to content
This repository was archived by the owner on Dec 21, 2021. It is now read-only.

Commit 5f81f88

Browse files
author
Eric Andrews
committed
update tests
1 parent ac36358 commit 5f81f88

File tree

1 file changed

+42
-53
lines changed

1 file changed

+42
-53
lines changed

test/test.streamr-client.js

Lines changed: 42 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -181,54 +181,33 @@ describe('StreamrClient', function() {
181181
})
182182

183183
describe("connect", function() {
184-
it('should not pass transport details in io() call', function(done) {
185-
client.connect()
186-
client.connection.on("connect", function() {
187-
assert.strictEqual(client.connection.opts["transports"], null)
188-
done()
189-
})
190-
})
191-
192-
context('when client initialized with transport details', function () {
193-
beforeEach(function () {
194-
client = new StreamrClient({
195-
transports: ["websocket"]
196-
})
197-
})
198-
199-
it('should pass transport details in io() call', function(done) {
200-
client.connect()
201-
client.connection.on("connect", function() {
202-
assert.deepEqual(client.connection.opts["transports"], ["websocket"])
203-
done()
204-
})
205-
})
206-
})
207-
208-
it('should emit pending subscribes', function(done) {
184+
it('should send pending subscribes', function(done) {
209185
var subscription = client.subscribe("stream1", function(message) {})
210186
client.connect()
211187

212-
client.connection.on('subscribe', function(request) {
213-
if (request.channel==='stream1')
188+
client.connection.on('subscribed', function(request) {
189+
if (request.channel==='stream1') {
190+
socket.done = true
214191
done()
192+
}
215193
})
216194
})
217195

218-
it('should not emit anything on connect if not subscribed to anything', function(done) {
196+
it('should not send anything on connect if not subscribed to anything', function(done) {
219197
client.connect()
220198

221-
client.connection.emit = function() {
199+
client.connection.send = function() {
222200
if (this.event !== 'connect')
223-
throw "Unexpected emit: "+this.event
201+
throw "Unexpected send: "+this.event
224202
}
225203

204+
socket.done = true
226205
done()
227206
})
228207

229208
it('should report that it is connected and not connecting after connecting', function(done) {
230209
client.connect()
231-
client.connection.on('connect', function() {
210+
client.connection.on('connected', function() {
232211
assert(client.isConnected())
233212
assert(!client.connecting)
234213
done()
@@ -250,6 +229,7 @@ describe('StreamrClient', function() {
250229
client.subscribe("stream2", function(message) {})
251230

252231
assert.equal(ioMockCalls, 1)
232+
socket.done = true
253233
done()
254234
})
255235
})
@@ -260,20 +240,22 @@ describe('StreamrClient', function() {
260240
client.connect()
261241

262242
// connect-disconnect-connect
263-
client.connection.once('connect', function() {
264-
client.connection.once('disconnect', function() {
265-
client.connection.on('subscribe', function(request) {
243+
client.connection.once('connected', function() {
244+
client.connection.once('disconnected', function() {
245+
client.connection.on('subscribed', function(request) {
266246
console.log(request)
267-
if (request.channel==='stream1')
247+
if (request.channel==='stream1') {
248+
socket.done = true
268249
done()
250+
}
269251
})
270252

271253
console.log("Disconnected, now connecting!")
272-
client.connection.emit('connect')
254+
socket.connect()
273255
})
274256

275257
console.log("Connected, now disconnecting!")
276-
client.connection.emit('disconnect')
258+
socket.disconnect()
277259

278260
})
279261

@@ -289,15 +271,18 @@ describe('StreamrClient', function() {
289271
if (sub1.isSubscribed() && sub2.isSubscribed()) {
290272
client.unsubscribe(sub1)
291273
client.connection.once('unsubscribed', function(response) {
292-
client.connection.emit('disconnect')
274+
socket.disconnect()
293275

294-
client.connection.on('subscribe', function(request) {
295-
if (request.channel==="stream1")
276+
client.connection.on('subscribed', function(request) {
277+
if (request.channel==="stream1") {
296278
throw "Should not have subscribed to stream1 on reconnect!"
297-
if (request.channel==='stream2')
279+
}
280+
if (request.channel==='stream2') {
281+
socket.done = true
298282
done()
283+
}
299284
})
300-
client.connection.emit('connect')
285+
socket.connect()
301286
})
302287
}
303288
})
@@ -306,15 +291,17 @@ describe('StreamrClient', function() {
306291

307292
it('should emit a subscribe event on reconnect for topics subscribed after initial connect', function(done) {
308293
client.connect()
309-
client.connection.once('connect', function() {
294+
client.connection.once('connected', function() {
310295
client.subscribe("stream1", function(message) {})
311296
client.connection.once('subscribed', function() {
312-
client.connection.emit('disconnect')
313-
client.connection.once('subscribe', function(request) {
314-
if (request.channel==='stream1')
297+
socket.disconnect()
298+
client.connection.once('subscribed', function(request) {
299+
if (request.channel==='stream1') {
300+
socket.done = true
315301
done()
302+
}
316303
})
317-
client.connection.emit('connect')
304+
socket.connect()
318305
})
319306
})
320307
})
@@ -339,21 +326,23 @@ describe('StreamrClient', function() {
339326
})
340327
})
341328

342-
it('should emit a subscribe event when subscribing after connecting', function(done) {
329+
it('should emit a subscribed event when subscribing after connecting', function(done) {
343330
client.connect()
344-
client.connection.once('connect', function() {
345-
client.connection.once('subscribe', function(request) {
346-
if (request.channel==='stream1')
331+
client.connection.once('connected', function() {
332+
client.connection.once('subscribed', function(request) {
333+
if (request.channel==='stream1') {
334+
socket.done = true
347335
done()
336+
}
348337
})
349338
client.subscribe("stream1", function(message) {})
350339
})
351340
})
352341

353342
it('should add any subscription options to subscription request', function(done) {
354343
client.connect()
355-
client.connection.once('connect', function() {
356-
client.connection.once('subscribe', function(request) {
344+
client.connection.once('connected', function() {
345+
client.connection.once('subscribed', function(request) {
357346
if (request.foo === 'bar')
358347
done()
359348
})

0 commit comments

Comments
 (0)