From 5670efb042ced243e8145e23b10bc83be1e185c0 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Mon, 24 Mar 2025 10:05:10 -0700 Subject: [PATCH] move getAPNsFullUrlToUse method to the notification sender tests --- .../AppleNotificationSenderTests.test.ts | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/notifications/senders/AppleNotificationSenderTests.test.ts b/test/notifications/senders/AppleNotificationSenderTests.test.ts index c4fddb5..919f535 100644 --- a/test/notifications/senders/AppleNotificationSenderTests.test.ts +++ b/test/notifications/senders/AppleNotificationSenderTests.test.ts @@ -2,6 +2,7 @@ import { beforeEach, describe, expect, it, jest } from "@jest/globals"; import http2 from "http2"; import { EventEmitter } from "node:events"; import { AppleNotificationSender } from "../../../src/notifications/senders/AppleNotificationSender"; +import { ETANotificationScheduler } from "../../../src/notifications/schedulers/ETANotificationScheduler"; jest.mock("http2"); @@ -63,4 +64,31 @@ describe("AppleNotificationSender", () => { }); }); + describe('getAPNsFullUrlToUse', () => { + it('should return the production URL when APNS_IS_PRODUCTION is set to "1"', () => { + process.env.APNS_IS_PRODUCTION = "1"; + const deviceId = 'testDeviceId'; + const result = AppleNotificationSender.getAPNsFullUrlToUse(deviceId); + + const { fullUrl, host, path } = result; + expect(fullUrl).toBe(`https://api.push.apple.com/3/device/${deviceId}`); + expect(host).toBe("https://api.push.apple.com"); + expect(path).toBe(`/3/device/${deviceId}`); + }); + + it('should return the sandbox URL when APNS_IS_PRODUCTION is set to something other than 1', () => { + process.env.APNS_IS_PRODUCTION = "0"; + const deviceId = 'testDeviceId'; + const result = AppleNotificationSender.getAPNsFullUrlToUse(deviceId); + + const { fullUrl, host, path } = result; + expect(fullUrl).toBe(`https://api.development.push.apple.com/3/device/${deviceId}`); + expect(host).toBe("https://api.development.push.apple.com"); + expect(path).toBe(`/3/device/${deviceId}`); + }); + }); + + describe("sendNotificationImmediately", () => { + + }); });