/
voice_dispatcher_spec.js
159 lines (129 loc) · 5.09 KB
/
voice_dispatcher_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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
var connFu = require('../index');
var https = require('https');
var spy_https_request = require('./spies/https_request');
var spy_https_get = require('./spies/https_get');
describe('Dispatching voice events', function(){
var app;
beforeEach(function() {
// Reset global options
connFu.setOptions();
app = connFu.createApp("1234");
// Create mock for getting the stream
spy_https_request.returnStream(null, '1234', 'connfu-stream-final');
});
it("should call the join handler when receiving a join event from the server", function(){
var events = [
'["join",{"appId":"connfu-stream-final","conferenceId":"connfu://channel-1/#conference","from":"4917663000001","to":"498966679151"}]'
];
spy_https_get.streamEvents(null, '1234', events);
app.on("voice", {
join: function(event) {
expect(event.channelType).toEqual('voice');
expect(event.messageType).toEqual('join');
expect(event.channelName).toEqual('channel-1');
expect(event.from).toEqual('4917663000001');
expect(event.to).toEqual('498966679151');
asyncSpecDone();
}
});
app.listen();
asyncSpecWait();
});
it("should call the leave handler when receiving a leave event from the server", function(){
var events = [
'["leave",{"appId":"connfu-stream-final","conferenceId":"connfu://channel-1/#conference","from":"4917663000001","to":"498966679151"}]'
];
spy_https_get.streamEvents(null, '1234', events);
app.on("voice", {
leave: function(event) {
expect(event.channelType).toEqual('voice');
expect(event.messageType).toEqual('leave');
expect(event.channelName).toEqual('channel-1');
expect(event.from).toEqual('4917663000001');
expect(event.to).toEqual('498966679151');
asyncSpecDone();
}
});
app.listen();
asyncSpecWait();
});
it("should call join and leave when receiving the two events", function(){
var events = [
'["join",{"appId":"connfu-stream-final","conferenceId":"connfu://channel-1/#conference","from":"4917663000001","to":"498966679151"}]',
'["leave",{"appId":"connfu-stream-final","conferenceId":"connfu://channel-1/#conference","from":"4917663000001","to":"498966679151"}]'
];
spy_https_get.streamEvents(null, '1234', events, 100);
var leave = false;
app.on("voice", {
join: function(event){
expect(event.channelType).toEqual('voice');
expect(event.messageType).toEqual('join');
expect(event.channelName).toEqual('channel-1');
expect(event.from).toEqual('4917663000001');
expect(event.to).toEqual('498966679151');
asyncSpecDone();
},
leave: function(event){
leave = true;
expect(event.channelType).toEqual('voice');
expect(event.messageType).toEqual('leave');
expect(event.channelName).toEqual('channel-1');
expect(event.from).toEqual('4917663000001');
expect(event.to).toEqual('498966679151');
}
});
app.listen();
asyncSpecWait();
waitsFor(function(){
return leave !== false;
}, "receiving the leave event from connFu", 1000);
});
it("should call join twice when receiving two join events", function(){
var events = [
'["join",{"appId":"connfu-stream-final","conferenceId":"connfu://channel-1/#conference","from":"4917663000001","to":"498966679151"}]',
'["join",{"appId":"connfu-stream-final","conferenceId":"connfu://channel-2/#conference","from":"4917663000011","to":"498966679152"}]'
];
spy_https_get.streamEvents(null, '1234', events, 100);
var numberJoins = 0;
app.on("voice", {
join: function(event){
expect(event.channelType).toEqual('voice');
expect(event.messageType).toEqual('join');
switch(numberJoins) {
case 0:
expect(event.channelName).toEqual('channel-1');
expect(event.from).toEqual('4917663000001');
expect(event.to).toEqual('498966679151');
break;
case 1:
expect(event.channelName).toEqual('channel-2');
expect(event.from).toEqual('4917663000011');
expect(event.to).toEqual('498966679152');
asyncSpecDone();
}
numberJoins++;
}
});
app.listen();
asyncSpecWait();
});
it("should not fail if receiving some spaces from server", function(){
var events = [
' ', // Empty string received from stream server
' ["join",{"appId":"connfu-stream-final","conferenceId":"connfu://channel-1/#conference","from":"4917663000001","to":"498966679151"}] '
];
spy_https_get.streamEvents(null, '1234', events, 100);
app.on("voice", {
join: function(event){
expect(event.channelType).toEqual('voice');
expect(event.messageType).toEqual('join');
expect(event.channelName).toEqual('channel-1');
expect(event.from).toEqual('4917663000001');
expect(event.to).toEqual('498966679151');
asyncSpecDone();
}
});
app.listen();
asyncSpecWait();
});
});