mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 16:00:32 +00:00
update tests and implementation ofr getAPNsFullUrlToUse
This commit is contained in:
@@ -11,6 +11,12 @@ export interface ScheduledNotificationData {
|
|||||||
stopId: string;
|
stopId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface APNsUrl {
|
||||||
|
fullUrl: string;
|
||||||
|
path: string;
|
||||||
|
host: string;
|
||||||
|
}
|
||||||
|
|
||||||
export class NotificationService {
|
export class NotificationService {
|
||||||
public readonly secondsThresholdForNotificationToFire = 300;
|
public readonly secondsThresholdForNotificationToFire = 300;
|
||||||
|
|
||||||
@@ -162,17 +168,25 @@ export class NotificationService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static getAPNsFullUrlToUse(deviceId: string) {
|
public static getAPNsFullUrlToUse(deviceId: string): APNsUrl {
|
||||||
// Construct the fetch request
|
// Construct the fetch request
|
||||||
const devBaseUrl = "https://api.development.push.apple.com"
|
const devBaseUrl = "https://api.development.push.apple.com"
|
||||||
const prodBaseUrl = "https://api.push.apple.com"
|
const prodBaseUrl = "https://api.push.apple.com"
|
||||||
const path = "/3/device/" + deviceId;
|
|
||||||
|
|
||||||
let urlToUse = prodBaseUrl + path;
|
let hostToUse = prodBaseUrl;
|
||||||
if (process.env.NODE_ENV !== "production") {
|
if (process.env.NODE_ENV !== "production") {
|
||||||
urlToUse = devBaseUrl + path;
|
hostToUse = devBaseUrl;
|
||||||
}
|
}
|
||||||
return urlToUse;
|
|
||||||
|
const path = "/3/device/" + deviceId;
|
||||||
|
const fullUrl = hostToUse + path;
|
||||||
|
|
||||||
|
const constructedObject = {
|
||||||
|
fullUrl,
|
||||||
|
host: hostToUse,
|
||||||
|
path,
|
||||||
|
}
|
||||||
|
return constructedObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async etaSubscriberCallback(eta: IEta) {
|
private async etaSubscriberCallback(eta: IEta) {
|
||||||
|
|||||||
@@ -185,21 +185,22 @@ describe("NotificationService", () => {
|
|||||||
process.env.NODE_ENV = 'production';
|
process.env.NODE_ENV = 'production';
|
||||||
const deviceId = 'testDeviceId';
|
const deviceId = 'testDeviceId';
|
||||||
const result = NotificationService.getAPNsFullUrlToUse(deviceId);
|
const result = NotificationService.getAPNsFullUrlToUse(deviceId);
|
||||||
expect(result).toBe(`https://api.push.apple.com/3/device/${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 NODE_ENV is not set to "production"', () => {
|
it('should return the sandbox URL when NODE_ENV is not set to "production"', () => {
|
||||||
process.env.NODE_ENV = 'development';
|
process.env.NODE_ENV = 'development';
|
||||||
const deviceId = 'testDeviceId';
|
const deviceId = 'testDeviceId';
|
||||||
const result = NotificationService.getAPNsFullUrlToUse(deviceId);
|
const result = NotificationService.getAPNsFullUrlToUse(deviceId);
|
||||||
expect(result).toBe(`https://api.sandbox.push.apple.com/3/device/${deviceId}`);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should append the correct device ID to the URL', () => {
|
const { fullUrl, host, path } = result;
|
||||||
process.env.NODE_ENV = 'production';
|
expect(fullUrl).toBe(`https://api.development.push.apple.com/3/device/${deviceId}`);
|
||||||
const deviceId = 'device123';
|
expect(host).toBe("https://api.development.push.apple.com");
|
||||||
const result = NotificationService.getAPNsFullUrlToUse(deviceId);
|
expect(path).toBe(`/3/device/${deviceId}`);
|
||||||
expect(result).toBe(`https://api.push.apple.com/3/device/${deviceId}`);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user