You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: node.js/tests/test.js
+167
Original file line number
Diff line number
Diff line change
@@ -162,6 +162,173 @@ describe('Pubnub', function () {
162
162
163
163
describe('#subscribe()',function(){
164
164
165
+
it('should should message sent to a channel which matches wildcard',function(done){
166
+
167
+
varrandom=get_random();
168
+
varch='channel-'+random;
169
+
varchw=ch+'.*';
170
+
varchwc=ch+".a";
171
+
172
+
173
+
pubnub.subscribe({
174
+
channel: chw,
175
+
connect: function(){
176
+
pubnub.publish({
177
+
'channel' : chwc,
178
+
message : 'message'+chwc,
179
+
callback : function(r){
180
+
assert.ok(true,'message published');
181
+
},
182
+
error : function(r){
183
+
assert.ok(false,'error occurred in publish');
184
+
}
185
+
});
186
+
187
+
},
188
+
callback: function(response){
189
+
assert.deepEqual(response,'message'+chwc);
190
+
pubnub.unsubscribe({channel: chw});
191
+
done();
192
+
},
193
+
error: function(){
194
+
assert.ok(false);
195
+
pubnub.unsubscribe({channel: ch});
196
+
done();
197
+
}
198
+
});
199
+
});
200
+
201
+
it('should be able to subscribe on foo.* and receive presence events on foo.bar-pnpres when presence callback is provided',function(done){
202
+
varcount=3;
203
+
functiond(){
204
+
if(--count==0)done();
205
+
}
206
+
varrandom=get_random();
207
+
varch='channel-'+random;
208
+
varchw=ch+'.*';
209
+
varchwc=ch+".a";
210
+
varpubnub2=PUBNUB.init({
211
+
publish_key: 'ds',
212
+
subscribe_key: 'ds',
213
+
origin: 'pubsub.pubnub.com',
214
+
build_u: true
215
+
});
216
+
functionf(x){
217
+
returnJSON.stringify(x)+' ';
218
+
}
219
+
pubnub.subscribe({
220
+
channel: chw,
221
+
presence : function(a,b,x,y,z){
222
+
assert.deepEqual(x,chw);
223
+
d();
224
+
},
225
+
connect: function(){
226
+
setTimeout(function(){
227
+
pubnub2.subscribe({
228
+
channel: chwc,
229
+
connect: function(){
230
+
pubnub2.publish({
231
+
'channel' : chwc,
232
+
message : 'message'+chwc,
233
+
callback : function(r){
234
+
assert.ok(true,'message published');
235
+
},
236
+
error : function(r){
237
+
assert.ok(false,'error occurred in publish');
238
+
}
239
+
});
240
+
241
+
},
242
+
callback: function(response){
243
+
assert.deepEqual(response,'message'+chwc);
244
+
pubnub2.unsubscribe({channel: chwc});
245
+
d();
246
+
},
247
+
error: function(){
248
+
assert.ok(false);
249
+
pubnub2.unsubscribe({channel: ch});
250
+
done();
251
+
}
252
+
});
253
+
},5000);
254
+
},
255
+
callback: function(response){
256
+
assert.deepEqual(response,'message'+chwc);
257
+
pubnub.unsubscribe({channel: chw});
258
+
d();
259
+
},
260
+
error: function(){
261
+
assert.ok(false);
262
+
pubnub.unsubscribe({channel: ch});
263
+
done();
264
+
}
265
+
});
266
+
});
267
+
268
+
it('should be able to subscribe on foo.* and should not receive presence events on foo.bar-pnpres when presence callback is not provided',function(done){
269
+
varcount=2;
270
+
functiond(){
271
+
if(--count==0)done();
272
+
}
273
+
varrandom=get_random();
274
+
varch='channel-'+random;
275
+
varchw=ch+'.*';
276
+
varchwc=ch+".a";
277
+
varpubnub2=PUBNUB.init({
278
+
publish_key: 'ds',
279
+
subscribe_key: 'ds',
280
+
origin: 'pubsub.pubnub.com',
281
+
build_u: true
282
+
});
283
+
functionf(x){
284
+
returnJSON.stringify(x)+' ';
285
+
}
286
+
pubnub.subscribe({
287
+
channel: chw,
288
+
connect: function(){
289
+
setTimeout(function(){
290
+
pubnub2.subscribe({
291
+
channel: chwc,
292
+
connect: function(){
293
+
pubnub2.publish({
294
+
'channel' : chwc,
295
+
message : 'message'+chwc,
296
+
callback : function(r){
297
+
assert.ok(true,'message published');
298
+
},
299
+
error : function(r){
300
+
assert.ok(false,'error occurred in publish');
301
+
}
302
+
});
303
+
304
+
},
305
+
callback: function(response){
306
+
assert.deepEqual(response,'message'+chwc);
307
+
pubnub2.unsubscribe({channel: chwc});
308
+
d();
309
+
},
310
+
error: function(){
311
+
assert.ok(false);
312
+
pubnub2.unsubscribe({channel: ch});
313
+
done();
314
+
}
315
+
});
316
+
},5000);
317
+
},
318
+
callback: function(response){
319
+
assert.deepEqual(response,'message'+chwc);
320
+
pubnub.unsubscribe({channel: chw});
321
+
d();
322
+
},
323
+
error: function(){
324
+
assert.ok(false);
325
+
pubnub.unsubscribe({channel: ch});
326
+
done();
327
+
}
328
+
});
329
+
});
330
+
331
+
165
332
it('should be able to handle wildcard, channel group and channel together',function(done){
0 commit comments