diff --git a/src/ServerContext.ts b/src/ServerContext.ts index 6579453..8dade11 100644 --- a/src/ServerContext.ts +++ b/src/ServerContext.ts @@ -1,7 +1,7 @@ -import { NotificationService } from "./services/NotificationService"; +import { ETANotificationScheduler } from "./notifications/schedulers/ETANotificationScheduler"; import { GetterSetterRepository } from "./repositories/GetterSetterRepository"; export interface ServerContext { repository: GetterSetterRepository; - notificationService: NotificationService; + notificationService: ETANotificationScheduler; } diff --git a/src/index.ts b/src/index.ts index 3cf1915..fb42543 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,7 +5,7 @@ import { MergedResolvers } from "./MergedResolvers"; import { ServerContext } from "./ServerContext"; import { UnoptimizedInMemoryRepository } from "./repositories/UnoptimizedInMemoryRepository"; import { TimedApiBasedRepositoryLoader } from "./loaders/TimedApiBasedRepositoryLoader"; -import { NotificationService } from "./services/NotificationService"; +import { ETANotificationScheduler } from "./notifications/schedulers/ETANotificationScheduler"; import { configDotenv } from "dotenv"; import { loadTestData } from "./loaders/loadTestData"; @@ -21,16 +21,16 @@ async function main() { }); const repository = new UnoptimizedInMemoryRepository(); - let notificationService: NotificationService; + let notificationService: ETANotificationScheduler; if (process.argv.length > 2 && process.argv[2] == "integration-testing") { await loadTestData(repository); - notificationService = new NotificationService(repository, false); + notificationService = new ETANotificationScheduler(repository, false); } else { const repositoryDataUpdater = new TimedApiBasedRepositoryLoader( repository ); await repositoryDataUpdater.start(); - notificationService = new NotificationService(repository); + notificationService = new ETANotificationScheduler(repository); } notificationService.reloadAPNsTokenIfTimePassed(); diff --git a/src/services/NotificationService.ts b/src/notifications/schedulers/ETANotificationScheduler.ts similarity index 96% rename from src/services/NotificationService.ts rename to src/notifications/schedulers/ETANotificationScheduler.ts index bb15e46..16251da 100644 --- a/src/services/NotificationService.ts +++ b/src/notifications/schedulers/ETANotificationScheduler.ts @@ -1,8 +1,8 @@ -import { GetterRepository } from "../repositories/GetterRepository"; +import { GetterRepository } from "../../repositories/GetterRepository"; import jwt from "jsonwebtoken"; import fs from "fs"; -import { TupleKey } from "../types/TupleKey"; -import { IEta } from "../entities/entities"; +import { TupleKey } from "../../types/TupleKey"; +import { IEta } from "../../entities/entities"; import http2 from "http2"; export interface ScheduledNotificationData { @@ -17,7 +17,7 @@ interface APNsUrl { host: string; } -export class NotificationService { +export class ETANotificationScheduler { public readonly secondsThresholdForNotificationToFire = 180; private apnsToken: string | undefined = undefined; @@ -113,7 +113,7 @@ export class NotificationService { throw new Error("APNS_BUNDLE_ID environment variable is not set correctly"); } - const { path, host } = NotificationService.getAPNsFullUrlToUse(deviceId); + const { path, host } = ETANotificationScheduler.getAPNsFullUrlToUse(deviceId); const headers = { ':method': 'POST', diff --git a/src/notifications/senders/AppleNotificationSender.ts b/src/notifications/senders/AppleNotificationSender.ts new file mode 100644 index 0000000..e69de29 diff --git a/test/jsonSnapshots/fetchSystemData/fetchSystemDataSuccessfulResponse.ts b/test/jsonSnapshots/fetchSystemData/fetchSystemDataSuccessfulResponse.ts index 67b77e5..449c5c6 100644 --- a/test/jsonSnapshots/fetchSystemData/fetchSystemDataSuccessfulResponse.ts +++ b/test/jsonSnapshots/fetchSystemData/fetchSystemDataSuccessfulResponse.ts @@ -2094,9 +2094,9 @@ export const fetchSystemDataSuccessfulResponse = { "logo": 1, "goRoutePlannerEnabled": "0", "goColor": null, - "goSupportEmail": "transit.services@pepperdine.edu", + "goSupportEmail": "transit.schedulers@pepperdine.edu", "goAuthenticationType": "0", - "email": "transit.services@pepperdine.edu" + "email": "transit.schedulers@pepperdine.edu" }, { "fullname": "Perimeter Summit Shuttle", @@ -3347,4 +3347,4 @@ export const fetchSystemDataSuccessfulResponse = { "fromCache": 1, "myip": "206.211.154.147" } -}; \ No newline at end of file +}; diff --git a/test/services/NotificationServiceTests.test.ts b/test/notifications/schedulers/ETANotificationSchedulerTests.ts similarity index 93% rename from test/services/NotificationServiceTests.test.ts rename to test/notifications/schedulers/ETANotificationSchedulerTests.ts index 8517727..3fb738b 100644 --- a/test/services/NotificationServiceTests.test.ts +++ b/test/notifications/schedulers/ETANotificationSchedulerTests.ts @@ -1,9 +1,9 @@ import { beforeEach, describe, expect, it, jest } from "@jest/globals"; -import { NotificationService } from "../../src/services/NotificationService"; -import { UnoptimizedInMemoryRepository } from "../../src/repositories/UnoptimizedInMemoryRepository"; +import { ETANotificationScheduler } from "../../../src/notifications/schedulers/ETANotificationScheduler"; +import { UnoptimizedInMemoryRepository } from "../../../src/repositories/UnoptimizedInMemoryRepository"; import http2 from "http2"; -import { IEta, IShuttle, IStop } from "../../src/entities/entities"; -import { addMockShuttleToRepository, addMockStopToRepository } from "../testHelpers/repositorySetupHelpers"; +import { IEta, IShuttle, IStop } from "../../../src/entities/entities"; +import { addMockShuttleToRepository, addMockStopToRepository } from "../../testHelpers/repositorySetupHelpers"; import EventEmitter = require("node:events"); jest.mock("http2"); @@ -55,13 +55,13 @@ function mockHttp2Connect(status: number) { (http2.connect as jest.Mock) = jest.fn(() => new MockClient()); } -describe("NotificationService", () => { +describe("ETANotificationScheduler", () => { let repository: UnoptimizedInMemoryRepository - let notificationService: NotificationService; + let notificationService: ETANotificationScheduler; beforeEach(() => { repository = new UnoptimizedInMemoryRepository(); - notificationService = new NotificationService(repository); + notificationService = new ETANotificationScheduler(repository); // Ensure that tests don't hit the server process.env = { @@ -192,7 +192,7 @@ describe("NotificationService", () => { 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 = NotificationService.getAPNsFullUrlToUse(deviceId); + const result = ETANotificationScheduler.getAPNsFullUrlToUse(deviceId); const { fullUrl, host, path } = result; expect(fullUrl).toBe(`https://api.push.apple.com/3/device/${deviceId}`); @@ -203,7 +203,7 @@ describe("NotificationService", () => { 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 = NotificationService.getAPNsFullUrlToUse(deviceId); + const result = ETANotificationScheduler.getAPNsFullUrlToUse(deviceId); const { fullUrl, host, path } = result; expect(fullUrl).toBe(`https://api.development.push.apple.com/3/device/${deviceId}`); diff --git a/test/resolvers/QueryResolverTests.test.ts b/test/resolvers/QueryResolverTests.test.ts index bb53d5b..8b0b60e 100644 --- a/test/resolvers/QueryResolverTests.test.ts +++ b/test/resolvers/QueryResolverTests.test.ts @@ -2,7 +2,7 @@ import { describe, expect, it } from "@jest/globals"; import { generateMockSystems } from "../testHelpers/mockDataGenerators"; import { setupTestServerContext, setupTestServerHolder } from "../testHelpers/apolloTestServerHelpers"; import assert = require("node:assert"); -import { ScheduledNotificationData } from "../../src/services/NotificationService"; +import { ScheduledNotificationData } from "../../src/notifications/schedulers/ETANotificationScheduler"; import { addMockShuttleToRepository, addMockStopToRepository } from "../testHelpers/repositorySetupHelpers"; // See Apollo documentation for integration test guide diff --git a/test/testHelpers/apolloTestServerHelpers.ts b/test/testHelpers/apolloTestServerHelpers.ts index a8af9d4..f9fa2d9 100644 --- a/test/testHelpers/apolloTestServerHelpers.ts +++ b/test/testHelpers/apolloTestServerHelpers.ts @@ -4,7 +4,7 @@ import { MergedResolvers } from "../../src/MergedResolvers"; import { UnoptimizedInMemoryRepository } from "../../src/repositories/UnoptimizedInMemoryRepository"; import { beforeEach } from "@jest/globals"; import { ServerContext } from "../../src/ServerContext"; -import { NotificationService } from "../../src/services/NotificationService"; +import { ETANotificationScheduler } from "../../src/notifications/schedulers/ETANotificationScheduler"; function setUpTestServer() { @@ -26,7 +26,7 @@ export function setupTestServerContext() { beforeEach(() => { context.repository = new UnoptimizedInMemoryRepository(); - context.notificationService = new NotificationService(context.repository); + context.notificationService = new ETANotificationScheduler(context.repository); }); return context as ServerContext;