Skip to content

Commit dc49d87

Browse files
author
Devendra
committed
adding wildcard subscribe tests as per new spec
1 parent 8d27d30 commit dc49d87

File tree

1 file changed

+167
-0
lines changed

1 file changed

+167
-0
lines changed

node.js/tests/test.js

+167
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,173 @@ describe('Pubnub', function () {
162162

163163
describe('#subscribe()', function () {
164164

165+
it('should should message sent to a channel which matches wildcard', function (done) {
166+
167+
var random = get_random();
168+
var ch = 'channel-' + random;
169+
var chw = ch + '.*';
170+
var chwc = 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+
var count = 3;
203+
function d() {
204+
if (--count == 0) done();
205+
}
206+
var random = get_random();
207+
var ch = 'channel-' + random;
208+
var chw = ch + '.*';
209+
var chwc = ch + ".a";
210+
var pubnub2 = PUBNUB.init({
211+
publish_key: 'ds',
212+
subscribe_key: 'ds',
213+
origin: 'pubsub.pubnub.com',
214+
build_u: true
215+
});
216+
function f(x) {
217+
return JSON.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+
var count = 2;
270+
function d() {
271+
if (--count == 0) done();
272+
}
273+
var random = get_random();
274+
var ch = 'channel-' + random;
275+
var chw = ch + '.*';
276+
var chwc = ch + ".a";
277+
var pubnub2 = PUBNUB.init({
278+
publish_key: 'ds',
279+
subscribe_key: 'ds',
280+
origin: 'pubsub.pubnub.com',
281+
build_u: true
282+
});
283+
function f(x) {
284+
return JSON.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+
165332
it('should be able to handle wildcard, channel group and channel together', function (done) {
166333
var count = 3;
167334
function d() {

0 commit comments

Comments
 (0)