Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/push-gateway-debug-logging.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Adds debug-level logging of the Cloud push gateway's response status and body when a push notification is accepted, making it possible to diagnose cases where the gateway accepts a push (HTTP 200) but it isn't delivered downstream to FCM/APNs.
1 change: 1 addition & 0 deletions apps/meteor/server/lib/notifications/push/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ class PushClass {
}

if (result.ok) {
logger.debug({ msg: 'push sent to gateway', service, status: result.status, response });
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import sinon from 'sinon';

const loggerStub = { debug: sinon.stub(), warn: sinon.stub(), error: sinon.stub(), info: sinon.stub(), log: sinon.stub() };
const settingsStub = { get: sinon.stub().returns('') };
const fetchStub = sinon.stub();

const { Push } = proxyquire.noCallThru().load('../../../../../../server/lib/notifications/push/push', {
'./logger': { logger: loggerStub },
'../../../settings': { settings: settingsStub },
'@rocket.chat/tools': { pick, truncateString },
'@rocket.chat/server-fetch': { serverFetch: fetchStub },
'meteor/check': {
check: sinon.stub(),
Match: {
Expand Down Expand Up @@ -109,4 +111,29 @@ describe('Push Notifications [PushClass]', () => {
expect(sendNotificationStub.called).to.be.false;
});
});

describe('sendGatewayPush()', () => {
afterEach(() => {
fetchStub.reset();
loggerStub.debug.reset();
});

it('should log the gateway response at debug level when the push is accepted (200)', async () => {
fetchStub.resolves({ status: 200, ok: true, text: sinon.stub().resolves('') });

await Push.sendGatewayPush('https://gateway.rocket.chat', 'apn', 'token123', {
createdAt: new Date(),
});

expect(fetchStub.calledOnce).to.be.true;

const debugCall = loggerStub.debug
.getCalls()
.map((call) => call.args[0])
.find((arg) => arg?.msg === 'push sent to gateway');

expect(debugCall).to.not.be.undefined;
expect(debugCall).to.include({ service: 'apn', status: 200, response: '' });
});
});
});