This repository has been archived by the owner on Aug 3, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathCQWebsocket.test.js
96 lines (79 loc) · 2.15 KB
/
CQWebsocket.test.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const CQWebSocket = require('../..')
const { WebsocketState } = CQWebSocket
const { test } = require('ava')
test('new Websocket() with default options', function (t) {
t.plan(8)
const bot = new CQWebSocket()
t.is(bot._monitor.EVENT.state, WebsocketState.INIT)
t.is(bot._monitor.API.state, WebsocketState.INIT)
t.is(bot._baseUrl, 'ws://127.0.0.1:6700')
t.is(bot._qq, -1)
t.is(bot._token, '')
t.deepEqual(bot._reconnectOptions, {
reconnection: true,
reconnectionAttempts: Infinity,
reconnectionDelay: 1000
})
t.deepEqual(bot._wsOptions, {
fragmentOutgoingMessages: false
})
t.deepEqual(bot._requestOptions, { })
})
test('new Websocket() with custom options', function (t) {
t.plan(8)
const bot = new CQWebSocket({
enableAPI: false,
enableEvent: true,
baseUrl: '8.8.8.8:8888/ws',
qq: 123456789,
access_token: 'qwerasdf',
reconnection: true,
reconnectionAttempts: 10,
reconnectionDelay: 5000,
fragmentOutgoingMessages: true,
fragmentationThreshold: 0x4000,
requestOptions: {
timeout: 2000
}
})
t.is(bot._monitor.EVENT.state, WebsocketState.INIT)
t.is(bot._monitor.API.state, WebsocketState.DISABLED)
t.is(bot._baseUrl, 'ws://8.8.8.8:8888/ws')
t.is(bot._qq, 123456789)
t.is(bot._token, 'qwerasdf')
t.deepEqual(bot._requestOptions, {
timeout: 2000
})
t.deepEqual(bot._reconnectOptions, {
reconnection: true,
reconnectionAttempts: 10,
reconnectionDelay: 5000
})
t.deepEqual(bot._wsOptions, {
fragmentOutgoingMessages: true,
fragmentationThreshold: 0x4000
})
})
test('new Websocket(): protocol', function (t) {
t.plan(2)
const bot1 = new CQWebSocket({
protocol: 'HTTP'
})
t.is(bot1._baseUrl, 'http://127.0.0.1:6700')
const bot2 = new CQWebSocket({
protocol: 'wss:',
port: 23456
})
t.is(bot2._baseUrl, 'wss://127.0.0.1:23456')
})
test('new Websocket(): base url', function (t) {
t.plan(2)
const bot1 = new CQWebSocket({
baseUrl: '127.0.0.1:22222'
})
t.is(bot1._baseUrl, 'ws://127.0.0.1:22222')
const bot2 = new CQWebSocket({
baseUrl: 'wss://my.dns/bot'
})
t.is(bot2._baseUrl, 'wss://my.dns/bot')
})