Skip to content

Commit 40d1274

Browse files
Mohit TejaniMohit Tejani
authored andcommitted
update subscription_manager: to disable ee, because those tests are subscription_manager component specific,
update subscribe tests to in corporate ee changes where EE discard `m` field for handshake, and make presence heartbeat whenever subscribe call made, additional mock request infering to EE http requests
1 parent 24f42e4 commit 40d1274

2 files changed

Lines changed: 150 additions & 13 deletions

File tree

test/integration/components/subscription_manager.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ describe('#components/subscription_manager', () => {
2929
// @ts-expect-error Force override default value.
3030
useRequestId: false,
3131
autoNetworkDetection: false,
32+
enableEventEngine: false,
3233
heartbeatInterval: 149,
3334
});
3435
pubnubWithLimitedDeduplicationQueue = new PubNub({
@@ -41,6 +42,7 @@ describe('#components/subscription_manager', () => {
4142
autoNetworkDetection: false,
4243
maximumCacheSize: 1,
4344
dedupeOnSubscribe: true,
45+
enableEventEngine: false,
4446
heartbeatInterval: 149,
4547
});
4648
pubnubWithPassingHeartbeats = new PubNub({
@@ -52,6 +54,7 @@ describe('#components/subscription_manager', () => {
5254
announceSuccessfulHeartbeats: true,
5355
useRequestId: false,
5456
autoNetworkDetection: false,
57+
enableEventEngine: false,
5558
heartbeatInterval: 149,
5659
});
5760
pubnubWithLimitedQueue = new PubNub({
@@ -63,13 +66,15 @@ describe('#components/subscription_manager', () => {
6366
useRequestId: false,
6467
requestMessageCountThreshold: 1,
6568
autoNetworkDetection: false,
69+
enableEventEngine: false,
6670
heartbeatInterval: 149,
6771
});
6872
pubnubWithCrypto = new PubNub({
6973
subscribeKey: 'mySubKey',
7074
publishKey: 'myPublishKey',
7175
origin: 'ps.pndsn.com',
7276
uuid: 'myUUID',
77+
enableEventEngine: false,
7378
// @ts-expect-error Force override default value.
7479
useRequestId: false,
7580
cryptoModule: PubNub.CryptoModule.aesCbcCryptoModule({ cipherKey: 'cipherKey' }),

test/integration/endpoints/subscribe.test.ts

Lines changed: 145 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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(/heartbeat$/)
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(/heartbeat$/)
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(/heartbeat$/)
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(/heartbeat$/)
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(/heartbeat$/)
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

Comments
 (0)