Skip to content

Commit

Permalink
added test for custom timetoken with subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
mohitpubnub committed Jun 17, 2024
1 parent 90f21d0 commit d472653
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions test/integration/endpoints/subscribe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import utils from '../../utils';
describe('subscribe endpoints', () => {
let pubnubWithFiltering: PubNub;
let pubnub: PubNub;
let pubnubWithEE: PubNub;

before(() => {
nock.disableNetConnect();
Expand Down Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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' });
}) ;
});

0 comments on commit d472653

Please sign in to comment.