Skip to content

Commit c61207e

Browse files
author
Devendra
committed
adding test case for wildcard subscribe
1 parent adae530 commit c61207e

11 files changed

Lines changed: 588 additions & 331 deletions

File tree

modern/pubnub.min.js

Lines changed: 50 additions & 51 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/* ---------------------------------------------------------------------------
2+
3+
Init PubNub and Get your PubNub API Keys:
4+
http://www.pubnub.com/account#api-keys
5+
6+
--------------------------------------------------------------------------- */
7+
8+
var pubnub = require("./../pubnub.js").init({
9+
publish_key : "pub-c-c077418d-f83c-4860-b213-2f6c77bde29a",
10+
subscribe_key : "sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe"
11+
});
12+
13+
14+
/* ---------------------------------------------------------------------------
15+
Listen for Messages
16+
--------------------------------------------------------------------------- */
17+
18+
19+
20+
function subscribe(channel) {
21+
pubnub.subscribe({
22+
'channel' : channel,
23+
'connect' : function(c) {
24+
console.log('CONNECTED to ' + c);
25+
},
26+
'disconnect' : function(c) {
27+
console.log('CONNECTED to ' + c);
28+
},
29+
'reconnect' : function(c) {
30+
console.log('CONNECTED to ' + c);
31+
},
32+
'error' : function(e) {
33+
console.log('ERROR ' + JSON.stringify(r));
34+
},
35+
'callback' : function(m,a,b,c,d) {
36+
console.log(JSON.stringify(m));
37+
console.log(JSON.stringify(b));
38+
console.log(JSON.stringify(d));
39+
}
40+
})
41+
}
42+
43+
subscribe('ab.*');

node.js/tests/test.js

Lines changed: 109 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,116 @@ describe('Pubnub', function () {
161161
});
162162

163163
describe('#subscribe()', function () {
164-
it('should pass plain text to callback on decryption error', function (done) {
165-
var ch = channel + '-' + ++count;
166164

165+
it('should be able to handle wildcard, channel group and channel together', function (done) {
166+
var random = get_random();
167+
var ch = 'channel-' + random;
168+
var chg = 'channel-group-' + random;
169+
var chgc = 'channel-group-channel' + random
170+
var chw = ch + '.*';
171+
var chwc = ch + ".a";
172+
173+
pubnub.channel_group_add_channel({
174+
'channel_group' : chg,
175+
'channels' : chgc,
176+
'callback' : function(r) {
177+
pubnub.channel_group_list_channels({
178+
'channel_group' : chg,
179+
'callback' : function(r) {
180+
pubnub.subscribe({
181+
channel: ch,
182+
connect: function () {
183+
pubnub.subscribe({
184+
channel: chw,
185+
connect: function () {
186+
pubnub.subscribe({
187+
channel_group: chg,
188+
connect: function () {
189+
pubnub.publish({
190+
'channel' : ch,
191+
message : 'message' + ch,
192+
callback : function(r) {
193+
assert.ok(true, 'message published');
194+
pubnub.publish({
195+
'channel' : chwc,
196+
message : 'message' + chwc,
197+
callback : function(r) {
198+
assert.ok(true, 'message published');
199+
pubnub.publish({
200+
'channel' : chgc,
201+
message : 'message' + chgc,
202+
callback : function(r) {
203+
assert.ok(true, 'message published');
204+
205+
},
206+
error : function(r) {
207+
assert.ok(false, 'error occurred in publish');
208+
}
209+
210+
})
211+
},
212+
error : function(r) {
213+
assert.ok(false, 'error occurred in publish');
214+
}
215+
})
216+
},
217+
error : function(r) {
218+
assert.ok(false, 'error occurred in publish');
219+
}
220+
221+
})
222+
},
223+
callback: function (response) {
224+
assert.deepEqual(response, 'message' + chgc);
225+
pubnub.unsubscribe({channel: chgc});
226+
done();
227+
},
228+
error: function () {
229+
assert.ok(false);
230+
pubnub.unsubscribe({channel: ch});
231+
done();
232+
}
233+
});
234+
},
235+
callback: function (response) {
236+
assert.deepEqual(response, 'message' + chwc);
237+
//pubnub.unsubscribe({channel: chwc});
238+
},
239+
error: function () {
240+
assert.ok(false);
241+
pubnub.unsubscribe({channel: ch});
242+
done();
243+
}
244+
});
245+
},
246+
callback: function (response) {
247+
assert.deepEqual(response, 'message' + ch);
248+
pubnub.unsubscribe({channel: ch});
249+
},
250+
error: function () {
251+
assert.ok(false);
252+
pubnub.unsubscribe({channel: ch});
253+
done();
254+
}
255+
})
256+
},
257+
'error' : function(r) {
258+
assert.ok(false, "error occurred in adding channel to group");
259+
}
260+
261+
});
262+
},
263+
'error' : function(r) {
264+
ok(false, "error occurred");
265+
}
266+
})
267+
268+
269+
});
270+
271+
272+
it('should pass plain text to callback on decryption error', function (done) {
273+
var ch = channel + '-' + ++channel;
167274
pubnub_enc.subscribe({
168275
channel: ch,
169276
connect: function () {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "pubnub",
33
"preferGlobal": false,
4-
"version": "3.7.10",
4+
"version": "3.7.10foo",
55
"author": "PubNub <[email protected]>",
66
"description": "Publish & Subscribe Real-time Messaging with PubNub",
77
"contributors": [

0 commit comments

Comments
 (0)