@@ -54,20 +54,47 @@ describe('subscribe endpoints', () => {
5454 } ) ;
5555
5656 it ( 'supports addition of multiple channels' , ( done ) => {
57+ // Event Engine: handshake returns only the cursor (payload `m` is ignored). A long-poll
58+ // (`receiveMessages`) follows immediately and must be mocked or the connection stalls.
59+ const cursorTimetoken = '14607577960932487' ;
60+
5761 const scope = utils
5862 . createNock ( )
5963 . get ( '/v2/subscribe/mySubKey/coolChannel,coolChannel2/0' )
6064 . query ( {
6165 pnsdk : `PubNub-JS-Nodejs/${ pubnub . getVersion ( ) } ` ,
6266 uuid : 'myUUID' ,
63- heartbeat : 300 ,
67+ ee : '' ,
6468 } )
6569 . reply (
6670 200 ,
67- ' {"t":{"t":"14607577960932487 ","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"mySubKey","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}' ,
71+ ` {"t":{"t":"${ cursorTimetoken } ","r":1},"m":[]}` ,
6872 { 'content-type' : 'text/javascript' } ,
6973 ) ;
7074
75+ utils
76+ . createNock ( )
77+ . get ( '/v2/subscribe/mySubKey/coolChannel,coolChannel2/0' )
78+ . query ( {
79+ pnsdk : `PubNub-JS-Nodejs/${ pubnub . getVersion ( ) } ` ,
80+ uuid : 'myUUID' ,
81+ ee : '' ,
82+ tt : cursorTimetoken ,
83+ tr : 1 ,
84+ } )
85+ . reply (
86+ 200 ,
87+ `{"t":{"t":"${ cursorTimetoken } ","r":1},"m":[]}` ,
88+ { 'content-type' : 'text/javascript' } ,
89+ )
90+ . persist ( ) ;
91+
92+ utils
93+ . createNock ( )
94+ . get ( / h e a r t b e a t $ / )
95+ . query ( true )
96+ . reply ( 200 , '{"status": 200,"message":"OK","service":"Presence"}' , { 'content-type' : 'text/javascript' } ) ;
97+
7198 pubnub . addListener ( {
7299 status ( status ) {
73100 if ( status . category === 'PNConnectedCategory' ) {
@@ -89,21 +116,49 @@ describe('subscribe endpoints', () => {
89116 } ) ;
90117
91118 it ( 'supports addition of multiple channels / channel groups' , ( done ) => {
119+ // Event Engine: handshake uses `ee` (no `heartbeat` on subscribe); `m` on handshake is ignored.
120+ // Long-poll receive must be mocked after handshake.
121+ const cursorTimetoken = '14607577960932487' ;
122+
92123 const scope = utils
93124 . createNock ( )
94125 . get ( '/v2/subscribe/mySubKey/coolChannel,coolChannel2/0' )
95126 . query ( {
96127 'channel-group' : 'cg1,cg2' ,
97128 pnsdk : `PubNub-JS-Nodejs/${ pubnub . getVersion ( ) } ` ,
98129 uuid : 'myUUID' ,
99- heartbeat : 300 ,
130+ ee : '' ,
100131 } )
101132 . reply (
102133 200 ,
103- ' {"t":{"t":"14607577960932487 ","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"mySubKey","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}' ,
134+ ` {"t":{"t":"${ cursorTimetoken } ","r":1},"m":[]}` ,
104135 { 'content-type' : 'text/javascript' } ,
105136 ) ;
106137
138+ utils
139+ . createNock ( )
140+ . get ( '/v2/subscribe/mySubKey/coolChannel,coolChannel2/0' )
141+ . query ( {
142+ 'channel-group' : 'cg1,cg2' ,
143+ pnsdk : `PubNub-JS-Nodejs/${ pubnub . getVersion ( ) } ` ,
144+ uuid : 'myUUID' ,
145+ ee : '' ,
146+ tt : cursorTimetoken ,
147+ tr : 1 ,
148+ } )
149+ . reply (
150+ 200 ,
151+ `{"t":{"t":"${ cursorTimetoken } ","r":1},"m":[]}` ,
152+ { 'content-type' : 'text/javascript' } ,
153+ )
154+ . persist ( ) ;
155+
156+ utils
157+ . createNock ( )
158+ . get ( / h e a r t b e a t $ / )
159+ . query ( true )
160+ . reply ( 200 , '{"status": 200,"message":"OK","service":"Presence"}' , { 'content-type' : 'text/javascript' } ) ;
161+
107162 pubnub . addListener ( {
108163 status ( status ) {
109164 if ( status . category === 'PNConnectedCategory' ) {
@@ -128,21 +183,47 @@ describe('subscribe endpoints', () => {
128183 } ) ;
129184
130185 it ( 'supports just channel group' , ( done ) => {
186+ const cursorTimetoken = '14607577960932487' ;
187+
131188 const scope = utils
132189 . createNock ( )
133190 . get ( '/v2/subscribe/mySubKey/,/0' )
134191 . query ( {
135192 'channel-group' : 'cg1,cg2' ,
136193 pnsdk : `PubNub-JS-Nodejs/${ pubnub . getVersion ( ) } ` ,
137194 uuid : 'myUUID' ,
138- heartbeat : 300 ,
195+ ee : '' ,
139196 } )
140197 . reply (
141198 200 ,
142- ' {"t":{"t":"14607577960932487 ","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"mySubKey","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}' ,
199+ ` {"t":{"t":"${ cursorTimetoken } ","r":1},"m":[]}` ,
143200 { 'content-type' : 'text/javascript' } ,
144201 ) ;
145202
203+ utils
204+ . createNock ( )
205+ . get ( '/v2/subscribe/mySubKey/,/0' )
206+ . query ( {
207+ 'channel-group' : 'cg1,cg2' ,
208+ pnsdk : `PubNub-JS-Nodejs/${ pubnub . getVersion ( ) } ` ,
209+ uuid : 'myUUID' ,
210+ ee : '' ,
211+ tt : cursorTimetoken ,
212+ tr : 1 ,
213+ } )
214+ . reply (
215+ 200 ,
216+ `{"t":{"t":"${ cursorTimetoken } ","r":1},"m":[]}` ,
217+ { 'content-type' : 'text/javascript' } ,
218+ )
219+ . persist ( ) ;
220+
221+ utils
222+ . createNock ( )
223+ . get ( / h e a r t b e a t $ / )
224+ . query ( true )
225+ . reply ( 200 , '{"status": 200,"message":"OK","service":"Presence"}' , { 'content-type' : 'text/javascript' } ) ;
226+
146227 pubnub . addListener ( {
147228 status ( status ) {
148229 if ( status . category === 'PNConnectedCategory' ) {
@@ -164,21 +245,47 @@ describe('subscribe endpoints', () => {
164245 } ) ;
165246
166247 it ( 'supports filter expression' , ( done ) => {
248+ const cursorTimetoken = '14607577960932487' ;
249+
167250 const scope = utils
168251 . createNock ( )
169252 . get ( '/v2/subscribe/mySubKey/coolChannel,coolChannel2/0' )
170253 . query ( {
171254 'filter-expr' : 'hello!' ,
172255 pnsdk : `PubNub-JS-Nodejs/${ pubnub . getVersion ( ) } ` ,
173256 uuid : 'myUUID' ,
174- heartbeat : 300 ,
257+ ee : '' ,
175258 } )
176259 . reply (
177260 200 ,
178- ' {"t":{"t":"14607577960932487 ","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"mySubKey","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}' ,
261+ ` {"t":{"t":"${ cursorTimetoken } ","r":1},"m":[]}` ,
179262 { 'content-type' : 'text/javascript' } ,
180263 ) ;
181264
265+ utils
266+ . createNock ( )
267+ . get ( '/v2/subscribe/mySubKey/coolChannel,coolChannel2/0' )
268+ . query ( {
269+ 'filter-expr' : 'hello!' ,
270+ pnsdk : `PubNub-JS-Nodejs/${ pubnub . getVersion ( ) } ` ,
271+ uuid : 'myUUID' ,
272+ ee : '' ,
273+ tt : cursorTimetoken ,
274+ tr : 1 ,
275+ } )
276+ . reply (
277+ 200 ,
278+ `{"t":{"t":"${ cursorTimetoken } ","r":1},"m":[]}` ,
279+ { 'content-type' : 'text/javascript' } ,
280+ )
281+ . persist ( ) ;
282+
283+ utils
284+ . createNock ( )
285+ . get ( / h e a r t b e a t $ / )
286+ . query ( true )
287+ . reply ( 200 , '{"status": 200,"message":"OK","service":"Presence"}' , { 'content-type' : 'text/javascript' } ) ;
288+
182289 pubnubWithFiltering . addListener ( {
183290 status ( status ) {
184291 if ( status . category === 'PNConnectedCategory' ) {
@@ -325,30 +432,55 @@ describe('subscribe endpoints', () => {
325432 } ) ;
326433
327434 it ( 'presence listener called for interval / delta update' , ( done ) => {
435+ const cursorHandshake = '14523669555221452' ;
436+ const cursorAfterInterval = '14523669555221453' ;
437+
328438 utils
329439 . createNock ( )
330440 . get ( '/v2/subscribe/mySubKey/c1,c1-pnpres/0' )
331441 . query ( {
332442 pnsdk : `PubNub-JS-Nodejs/${ pubnub . getVersion ( ) } ` ,
333443 uuid : 'myUUID' ,
334- heartbeat : 300 ,
444+ ee : '' ,
335445 } )
336- . reply ( 200 , '{"t":{"t":"14523669555221452","r":1},"m":[]}' , { 'content-type' : 'text/javascript' } ) ;
446+ . reply (
447+ 200 ,
448+ `{"t":{"t":"${ cursorHandshake } ","r":1},"m":[]}` ,
449+ { 'content-type' : 'text/javascript' } ,
450+ ) ;
337451 utils
338452 . createNock ( )
339453 . get ( '/v2/subscribe/mySubKey/c1,c1-pnpres/0' )
340454 . query ( {
341455 pnsdk : `PubNub-JS-Nodejs/${ pubnub . getVersion ( ) } ` ,
342456 uuid : 'myUUID' ,
343- tt : '14523669555221452' ,
457+ tt : cursorHandshake ,
344458 tr : 1 ,
345- heartbeat : 300 ,
459+ ee : '' ,
346460 } )
347461 . reply (
348462 200 ,
349- ' {"t":{"t":"14523669555221453 ","r":1},"m":[{"a":"3","f":0,"i":"myUniqueUserId","p":{"t":"17200339136465528","r":41},"k":"mySubKey","c":"c1-pnpres","d":{"action":"interval","timestamp":"1720033913","occupancy":0,"here_now_refresh":true}}]}' ,
463+ ` {"t":{"t":"${ cursorAfterInterval } ","r":1},"m":[{"a":"3","f":0,"i":"myUniqueUserId","p":{"t":"17200339136465528","r":41},"k":"mySubKey","c":"c1-pnpres","d":{"action":"interval","timestamp":"1720033913","occupancy":0,"here_now_refresh":true}}]}` ,
350464 { 'content-type' : 'text/javascript' } ,
351465 ) ;
466+ utils
467+ . createNock ( )
468+ . get ( '/v2/subscribe/mySubKey/c1,c1-pnpres/0' )
469+ . query ( {
470+ pnsdk : `PubNub-JS-Nodejs/${ pubnub . getVersion ( ) } ` ,
471+ uuid : 'myUUID' ,
472+ tt : cursorAfterInterval ,
473+ tr : 1 ,
474+ ee : '' ,
475+ } )
476+ . reply ( 200 , `{"t":{"t":"${ cursorAfterInterval } ","r":1},"m":[]}` , { 'content-type' : 'text/javascript' } )
477+ . persist ( ) ;
478+
479+ utils
480+ . createNock ( )
481+ . get ( / h e a r t b e a t $ / )
482+ . query ( true )
483+ . reply ( 200 , '{"status": 200,"message":"OK","service":"Presence"}' , { 'content-type' : 'text/javascript' } ) ;
352484
353485 pubnub . addListener ( {
354486 presence ( presence ) {
0 commit comments