From d4726536a0819fa5abefebe1aa16af153aa21cd2 Mon Sep 17 00:00:00 2001 From: Mohit Tejani Date: Mon, 17 Jun 2024 17:21:31 +0530 Subject: [PATCH] added test for custom timetoken with subscription --- test/integration/endpoints/subscribe.test.ts | 57 ++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/test/integration/endpoints/subscribe.test.ts b/test/integration/endpoints/subscribe.test.ts index 9e4c6bd2f..49dc4fa71 100644 --- a/test/integration/endpoints/subscribe.test.ts +++ b/test/integration/endpoints/subscribe.test.ts @@ -10,6 +10,7 @@ import utils from '../../utils'; describe('subscribe endpoints', () => { let pubnubWithFiltering: PubNub; let pubnub: PubNub; + let pubnubWithEE: PubNub; before(() => { nock.disableNetConnect(); @@ -38,6 +39,15 @@ describe('subscribe endpoints', () => { filterExpression: 'hello!', autoNetworkDetection: false, }); + pubnubWithEE = new PubNub({ + subscribeKey: 'mySubKey', + publishKey: 'myPublishKey', + uuid: 'myUUID', + // @ts-expect-error Force override default value. + useRequestId: false, + enableEventEngine: true, + logVerbosity: true, + }); }); afterEach(() => { @@ -192,4 +202,51 @@ describe('subscribe endpoints', () => { channels: ['coolChannel', 'coolChannel2'], }); }); + + it('supports timetoken', (done) => { + const scope0 = utils + .createNock() + .get('/v2/subscribe/mySubKey/c1/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + ee: '', + tt: 0, + }) + .reply( + 200, + '{"t":{"t":"14523669555221452","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}', + { 'content-type': 'text/javascript' }, + ); + const scope = utils + .createNock() + .get('/v2/subscribe/mySubKey/c1/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + ee: '', + tt: '1234567890', + tr: 1, + }) + .reply( + 200, + '{"t":{"t":"146075779609322","r":1},"m":[{"a":"4","f":0,"i":"test","p":{"t":"14607577960925503","r":1},"k":"mySubKey","c":"c1","d":{"text":"customttresponse"},"b":"c1"}]}', + { 'content-type': 'text/javascript' }, + ); + + pubnubWithEE.addListener({ + message(message) { + try { + assert.deepEqual(message.message, { text: 'customttresponse' }); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }, + }); + const channel = pubnubWithEE.channel('c1'); + const subscription = channel.subscription(); + subscription.subscribe({ timetoken: '1234567890' }); + }) ; });