Skip to content
Prev Previous commit
Next Next commit
test: appcontext response with 404
  • Loading branch information
mohitpubnub authored Jan 12, 2026
commit 570a6062a0b8a7cfcf0b24086628fa40b5972637
58 changes: 58 additions & 0 deletions test/integration/endpoints/objects/channel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import nock from 'nock';
import { asResponse, allChannels, channel1 } from './fixtures.js';
import PubNub from '../../../../src/node/index';
import utils from '../../../utils';
import { RetryPolicy } from '../../../../src/core/components/retry-policy.js';

describe('objects channel', () => {
const PUBLISH_KEY = 'myPublishKey';
Expand Down Expand Up @@ -727,4 +728,61 @@ describe('objects channel', () => {
expect(lastResult.data).to.have.length.lessThan(10);
});
});
describe('retry policy', () => {
it('should not retry on 404 Not Found error with linear retry policy', async () => {
const channelName = 'non-existent-channel';

// Set up nock mock before creating PubNub instance
const scope = utils
.createNock()
.get(`/v2/objects/${SUBSCRIBE_KEY}/channels/${channelName}`)
.query(true)
.reply(404, {
status: 404,
error: {
message: 'Requested object was not found.',
source: 'objects',
},
});

// Create a new PubNub instance with linear retry policy
const pubnubWithRetry = new PubNub({
subscribeKey: SUBSCRIBE_KEY,
publishKey: PUBLISH_KEY,
uuid: UUID,
// @ts-expect-error Force override default value.
useRequestId: false,
authKey: AUTH_KEY,
retryConfiguration: RetryPolicy.LinearRetryPolicy({
delay: 2,
maximumRetry: 2,
}),
});

let caughtError: any;
try {
await pubnubWithRetry.objects.getChannelMetadata({ channel: channelName });
} catch (error) {
caughtError = error;
}

// Verify that an error was thrown
expect(caughtError).to.exist;

// Verify the error status code is 404
expect(caughtError).to.have.property('status');
expect(caughtError.status.statusCode).to.equal(404);

// Verify the error message
expect(caughtError.status.errorData).to.exist;
expect(caughtError.status.errorData.error).to.exist;
expect(caughtError.status.errorData.error.message).to.equal('Requested object was not found.');
expect(caughtError.status.errorData.error.source).to.equal('objects');

// Verify the scope was called exactly once (no retries on 404
expect(scope.isDone()).to.be.true;

pubnubWithRetry.destroy(true);
});
});
});
Loading