forked from smooth80/bouncer.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient.spec.js
62 lines (49 loc) · 1.34 KB
/
client.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
'use strict'
const BouncerJs = require('.')
const UWebSocket = require('./client')
describe('GIVEN Client', () => {
describe('WHEN bouncer is initialized with plugin', () => {
let config
let send
let socket
beforeEach(() => {
const bouncer = new BouncerJs({
debug: false,
port: 3003,
plugins: {
chat: function (ws, message) {
send(ws, message)
}
}
})
config = bouncer.config
send = bouncer.send
socket = new UWebSocket('ws://localhost:3003')
socket.id = 'whatever'
})
it('THEN it should work on basic socket.emit message', (done) => {
socket.onmessage = ({ id, event, data }) => {
expect(data).toBeTruthy()
expect(id).toBeTruthy()
expect(event).toBe(config.join)
socket.close()
done()
}
socket.onopen = () => {
socket.emit({ event: config.join, data: 'chat' })
}
})
it('THEN it should work on basic socket.io-client-ish.emitEvent message', (done) => {
socket.onmessage = ({ id, event, data }) => {
expect(data).toBeTruthy()
expect(id).toBeTruthy()
expect(event).toBe(config.join)
socket.close()
done()
}
socket.onopen = () => {
socket.emitEvent(config.join, 'chat')
}
})
})
})