From f1dd8650b6454d28afcb0f2cfa3b8fe92a116041 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Tue, 29 Apr 2025 16:06:15 -0700 Subject: [PATCH 01/17] update the time of the data update --- src/entities/SharedEntities.ts | 2 +- src/loaders/shuttle/ApiBasedShuttleRepositoryLoader.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/entities/SharedEntities.ts b/src/entities/SharedEntities.ts index ad723c5..7e334f1 100644 --- a/src/entities/SharedEntities.ts +++ b/src/entities/SharedEntities.ts @@ -1,5 +1,5 @@ export interface IEntityWithOptionalTimestamp { - millisecondsSinceEpoch?: number; + updateTimeMs?: number; } export interface IEntityWithId { diff --git a/src/loaders/shuttle/ApiBasedShuttleRepositoryLoader.ts b/src/loaders/shuttle/ApiBasedShuttleRepositoryLoader.ts index 062ff43..6b73887 100644 --- a/src/loaders/shuttle/ApiBasedShuttleRepositoryLoader.ts +++ b/src/loaders/shuttle/ApiBasedShuttleRepositoryLoader.ts @@ -221,7 +221,7 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader secondsRemaining: jsonEta.secondsSpent, shuttleId: `${shuttleId}`, stopId: stopId, - millisecondsSinceEpoch: Date.now(), + updateTimeMs: Date.now(), systemId: this.systemIdForConstructedData, }; From fe90ffe91181e397bf9883109b939fea18416588 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Tue, 29 Apr 2025 16:07:30 -0700 Subject: [PATCH 02/17] update property name again and make it required --- src/entities/SharedEntities.ts | 2 +- src/loaders/shuttle/ApiBasedShuttleRepositoryLoader.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/entities/SharedEntities.ts b/src/entities/SharedEntities.ts index 7e334f1..9b92713 100644 --- a/src/entities/SharedEntities.ts +++ b/src/entities/SharedEntities.ts @@ -1,5 +1,5 @@ export interface IEntityWithOptionalTimestamp { - updateTimeMs?: number; + updatedTimeMs: number; } export interface IEntityWithId { diff --git a/src/loaders/shuttle/ApiBasedShuttleRepositoryLoader.ts b/src/loaders/shuttle/ApiBasedShuttleRepositoryLoader.ts index 6b73887..70b93a7 100644 --- a/src/loaders/shuttle/ApiBasedShuttleRepositoryLoader.ts +++ b/src/loaders/shuttle/ApiBasedShuttleRepositoryLoader.ts @@ -221,7 +221,7 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader secondsRemaining: jsonEta.secondsSpent, shuttleId: `${shuttleId}`, stopId: stopId, - updateTimeMs: Date.now(), + updatedTimeMs: Date.now(), systemId: this.systemIdForConstructedData, }; From d529554d84a99911499e4d0a91e9cc62d60abf15 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Tue, 29 Apr 2025 16:09:23 -0700 Subject: [PATCH 03/17] update loadShuttleTestData for integration tests --- src/loaders/shuttle/loadShuttleTestData.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/loaders/shuttle/loadShuttleTestData.ts b/src/loaders/shuttle/loadShuttleTestData.ts index c0c4e63..c4770f1 100644 --- a/src/loaders/shuttle/loadShuttleTestData.ts +++ b/src/loaders/shuttle/loadShuttleTestData.ts @@ -4324,6 +4324,7 @@ const routes: IRoute[] = [ systemId: supportedIntegrationTestSystems[0].id, polylineCoordinates: redRoutePolylineCoordinates, color: "#db2316", + updatedTimeMs: Date.now(), }, { name: "Teal Route", @@ -4331,6 +4332,7 @@ const routes: IRoute[] = [ systemId: supportedIntegrationTestSystems[0].id, polylineCoordinates: tealRoutePolylineCoordinates, color: "#21bdd1", + updatedTimeMs: Date.now(), }, ]; @@ -4343,6 +4345,7 @@ const stops: IStop[] = [ longitude: -117.8892805, }, systemId: supportedIntegrationTestSystems[0].id, + updatedTimeMs: Date.now(), }, { id: "2", @@ -4352,6 +4355,7 @@ const stops: IStop[] = [ longitude: -117.895966, }, systemId: supportedIntegrationTestSystems[0].id, + updatedTimeMs: Date.now(), }, { id: "3", @@ -4361,6 +4365,7 @@ const stops: IStop[] = [ "longitude": -117.85281 }, systemId: supportedIntegrationTestSystems[0].id, + updatedTimeMs: Date.now(), } ]; @@ -4370,12 +4375,14 @@ const orderedStopsForRedRoute: IOrderedStop[] = [ stopId: stops[0].id, position: 1, systemId: "1", + updatedTimeMs: Date.now(), }, { routeId: routes[0].id, stopId: stops[2].id, position: 2, systemId: "1", + updatedTimeMs: Date.now(), }, ]; @@ -4385,18 +4392,21 @@ const orderedStopsForTealRoute: IOrderedStop[] = [ stopId: stops[0].id, position: 1, systemId: supportedIntegrationTestSystems[0].id, + updatedTimeMs: Date.now(), }, { routeId: routes[1].id, stopId: stops[1].id, position: 2, systemId: supportedIntegrationTestSystems[0].id, + updatedTimeMs: Date.now(), }, { routeId: routes[1].id, stopId: stops[2].id, position: 2, systemId: supportedIntegrationTestSystems[0].id, + updatedTimeMs: Date.now(), }, ] @@ -4416,6 +4426,7 @@ const shuttles: IShuttle[] = [ routeId: routes[0].id, systemId: supportedIntegrationTestSystems[0].id, orientationInDegrees: 45.91, + updatedTimeMs: Date.now(), }, { name: "24", @@ -4427,6 +4438,7 @@ const shuttles: IShuttle[] = [ routeId: routes[0].id, systemId: supportedIntegrationTestSystems[0].id, orientationInDegrees: 90.24, + updatedTimeMs: Date.now(), } ]; @@ -4436,24 +4448,28 @@ const etas: IEta[] = [ shuttleId: shuttles[0].id, secondsRemaining: 12.023, systemId: supportedIntegrationTestSystems[0].id, + updatedTimeMs: Date.now(), }, { stopId: stops[2].id, shuttleId: shuttles[0].id, secondsRemaining: 600.123, systemId: supportedIntegrationTestSystems[0].id, + updatedTimeMs: Date.now(), }, { stopId: stops[2].id, shuttleId: shuttles[1].id, secondsRemaining: 172.015, systemId: supportedIntegrationTestSystems[0].id, + updatedTimeMs: Date.now(), }, { stopId: stops[0].id, shuttleId: shuttles[1].id, secondsRemaining: 710.152, systemId: supportedIntegrationTestSystems[0].id, + updatedTimeMs: Date.now(), } ]; From 563362b0b5d72a3884b859c0dc00c653e7bbb3c3 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Tue, 29 Apr 2025 16:11:41 -0700 Subject: [PATCH 04/17] update ApiBasedShuttleRepositoryLoader with timestamps --- src/loaders/shuttle/ApiBasedShuttleRepositoryLoader.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/loaders/shuttle/ApiBasedShuttleRepositoryLoader.ts b/src/loaders/shuttle/ApiBasedShuttleRepositoryLoader.ts index 70b93a7..dcc19cf 100644 --- a/src/loaders/shuttle/ApiBasedShuttleRepositoryLoader.ts +++ b/src/loaders/shuttle/ApiBasedShuttleRepositoryLoader.ts @@ -73,6 +73,7 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader id: jsonRoute.myid, polylineCoordinates: [], systemId: this.systemIdForConstructedData, + updatedTimeMs: Date.now(), }; await this.repository.addOrUpdateRoute(constructedRoute); @@ -172,7 +173,8 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader routeId: jsonBus.routeId, systemId: this.systemIdForConstructedData, id: `${jsonBus.busId}`, - orientationInDegrees: parseFloat(jsonBus.calculatedCourse) + orientationInDegrees: parseFloat(jsonBus.calculatedCourse), + updatedTimeMs: Date.now(), } await this.repository.addOrUpdateShuttle(constructedShuttle); @@ -249,6 +251,7 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader latitude: parseFloat(stop.latitude), longitude: parseFloat(stop.longitude), }, + updatedTimeMs: Date.now(), }; await this.repository.addOrUpdateStop(constructedStop); @@ -280,6 +283,7 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader stopId, position: index + 1, systemId: this.systemIdForConstructedData, + updatedTimeMs: Date.now(), }; } @@ -289,6 +293,7 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader stopId: jsonOrderedStopData[index - 1][1], position: index, systemId: this.systemIdForConstructedData, + updatedTimeMs: Date.now(), }; } if (index < jsonOrderedStopData.length - 1) { @@ -297,6 +302,7 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader stopId: jsonOrderedStopData[index + 1][1], position: index + 2, systemId: this.systemIdForConstructedData, + updatedTimeMs: Date.now(), }; } From 518044d8608c951bf428fa7c701c56040553c04a Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Tue, 29 Apr 2025 16:12:31 -0700 Subject: [PATCH 05/17] update parking code --- src/loaders/parking/ChapmanApiBasedParkingRepositoryLoader.ts | 3 ++- src/loaders/parking/loadParkingTestData.ts | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/loaders/parking/ChapmanApiBasedParkingRepositoryLoader.ts b/src/loaders/parking/ChapmanApiBasedParkingRepositoryLoader.ts index 9730df8..707d3c5 100644 --- a/src/loaders/parking/ChapmanApiBasedParkingRepositoryLoader.ts +++ b/src/loaders/parking/ChapmanApiBasedParkingRepositoryLoader.ts @@ -58,7 +58,8 @@ export class ChapmanApiBasedParkingRepositoryLoader implements ParkingRepository id: ChapmanApiBasedParkingRepositoryLoader.generateId(jsonStructure.Address), name: jsonStructure.Name, spotsAvailable: jsonStructure.CurrentCount > jsonStructure.Capacity ? jsonStructure.Capacity : jsonStructure.CurrentCount, - address: jsonStructure.Address + address: jsonStructure.Address, + updatedTimeMs: Date.now(), } return structureToReturn; diff --git a/src/loaders/parking/loadParkingTestData.ts b/src/loaders/parking/loadParkingTestData.ts index f73d15a..c790782 100644 --- a/src/loaders/parking/loadParkingTestData.ts +++ b/src/loaders/parking/loadParkingTestData.ts @@ -12,6 +12,7 @@ const parkingStructures: IParkingStructure[] = [ }, name: "Anderson Structure", id: "1", + updatedTimeMs: Date.now(), }, { address: "200 W Sycamore Ave, Orange, CA 92866-1053", @@ -23,6 +24,7 @@ const parkingStructures: IParkingStructure[] = [ }, name: "Barrera", id: "2", + updatedTimeMs: Date.now(), } ]; From 570ab8a17826938e21076311408f0075633600b4 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Tue, 29 Apr 2025 16:18:46 -0700 Subject: [PATCH 06/17] update tests and mock data generators --- ...iBasedParkingRepositoryLoaderTests.test.ts | 2 + .../ETANotificationSchedulerTests.test.ts | 1 + .../InMemoryParkingRepositoryTests.test.ts | 3 +- test/testHelpers/mockDataGenerators.ts | 41 +++++++++++-------- 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/test/loaders/parking/ChapmanApiBasedParkingRepositoryLoaderTests.test.ts b/test/loaders/parking/ChapmanApiBasedParkingRepositoryLoaderTests.test.ts index 9d9ebfc..b92026e 100644 --- a/test/loaders/parking/ChapmanApiBasedParkingRepositoryLoaderTests.test.ts +++ b/test/loaders/parking/ChapmanApiBasedParkingRepositoryLoaderTests.test.ts @@ -59,6 +59,7 @@ describe("ChapmanApiBasedParkingRepositoryLoader", () => { }, name: "Anderson Structure", id: "", + updatedTimeMs: Date.now(), }, { address: "200 W Sycamore Ave, Orange, CA 92866-1053", @@ -70,6 +71,7 @@ describe("ChapmanApiBasedParkingRepositoryLoader", () => { }, name: "Barrera", id: "", + updatedTimeMs: Date.now(), } ]; expectedStructures[0].id = ChapmanApiBasedParkingRepositoryLoader.generateId(expectedStructures[0].address); diff --git a/test/notifications/schedulers/ETANotificationSchedulerTests.test.ts b/test/notifications/schedulers/ETANotificationSchedulerTests.test.ts index db6a94b..136dd16 100644 --- a/test/notifications/schedulers/ETANotificationSchedulerTests.test.ts +++ b/test/notifications/schedulers/ETANotificationSchedulerTests.test.ts @@ -52,6 +52,7 @@ describe("ETANotificationScheduler", () => { stopId: stop.id, secondsRemaining: 120, systemId: "1", + updatedTimeMs: Date.now(), }; const notificationData1 = { diff --git a/test/repositories/InMemoryParkingRepositoryTests.test.ts b/test/repositories/InMemoryParkingRepositoryTests.test.ts index b656c81..2e541bf 100644 --- a/test/repositories/InMemoryParkingRepositoryTests.test.ts +++ b/test/repositories/InMemoryParkingRepositoryTests.test.ts @@ -13,7 +13,8 @@ describe("InMemoryParkingRepository", () => { id: "1", name: "Anderson Parking Structure", capacity: 100, - address: "300 E Walnut Ave, Orange, CA 92867" + address: "300 E Walnut Ave, Orange, CA 92867", + updatedTimeMs: Date.now(), }; beforeEach(() => { diff --git a/test/testHelpers/mockDataGenerators.ts b/test/testHelpers/mockDataGenerators.ts index b28cff7..64f2cbc 100644 --- a/test/testHelpers/mockDataGenerators.ts +++ b/test/testHelpers/mockDataGenerators.ts @@ -16,7 +16,8 @@ export function generateParkingStructures(): IParkingStructure[] { "id": "b0723baf8a6b8bcc37c821473373049e", "name": "Anderson Structure", "spotsAvailable": 163, - "address": "300 E Walnut, Orange, CA 92867" + "address": "300 E Walnut, Orange, CA 92867", + updatedTimeMs: Date.now(), }, { "capacity": 692, @@ -27,7 +28,8 @@ export function generateParkingStructures(): IParkingStructure[] { "id": "81b9e1ed004cf6def2e6c568aaf79ece", "name": "Barrera", "spotsAvailable": 179, - "address": "200 W Sycamore Ave, Orange, CA 92866-1053" + "address": "200 W Sycamore Ave, Orange, CA 92866-1053", + updatedTimeMs: Date.now(), } ]; } @@ -43,7 +45,8 @@ export function generateMockShuttles(): IShuttle[] { latitude: 10, longitude: 20 }, - orientationInDegrees: 25.163 + orientationInDegrees: 25.163, + updatedTimeMs: Date.now(), }, { id: "sh2", @@ -54,7 +57,8 @@ export function generateMockShuttles(): IShuttle[] { latitude: 15, longitude: 25 }, - orientationInDegrees: 50.912 + orientationInDegrees: 50.912, + updatedTimeMs: Date.now(), }, { id: "sh3", @@ -65,40 +69,41 @@ export function generateMockShuttles(): IShuttle[] { latitude: 30, longitude: 40 }, - orientationInDegrees: 321.019 + orientationInDegrees: 321.019, + updatedTimeMs: Date.now(), }, ]; } export function generateMockRoutes(): IRoute[] { return [ - { id: "r1", name: "Route 1", color: "red", systemId: "sys1", polylineCoordinates: [] }, - { id: "r2", name: "Route 2", color: "blue", systemId: "sys2", polylineCoordinates: [] }, - { id: "r3", name: "Route 3", color: "green", systemId: "sys3", polylineCoordinates: [] }, + { id: "r1", name: "Route 1", color: "red", systemId: "sys1", polylineCoordinates: [], updatedTimeMs: Date.now() }, + { id: "r2", name: "Route 2", color: "blue", systemId: "sys2", polylineCoordinates: [], updatedTimeMs: Date.now() }, + { id: "r3", name: "Route 3", color: "green", systemId: "sys3", polylineCoordinates: [], updatedTimeMs: Date.now() }, ]; } export function generateMockStops(): IStop[] { return [ - { id: "st1", name: "Stop A", systemId: "sys1", coordinates: { latitude: 10, longitude: 20 } }, - { id: "st2", name: "Stop B", systemId: "sys2", coordinates: { latitude: 15, longitude: 25 } }, - { id: "st3", name: "Stop C", systemId: "sys3", coordinates: { latitude: 30, longitude: 40 } }, + { id: "st1", name: "Stop A", systemId: "sys1", coordinates: { latitude: 10, longitude: 20 }, updatedTimeMs: Date.now() }, + { id: "st2", name: "Stop B", systemId: "sys2", coordinates: { latitude: 15, longitude: 25 }, updatedTimeMs: Date.now() }, + { id: "st3", name: "Stop C", systemId: "sys3", coordinates: { latitude: 30, longitude: 40 }, updatedTimeMs: Date.now() }, ]; } export function generateMockOrderedStops(): IOrderedStop[] { return [ - { stopId: "st1", routeId: "r1", position: 1, systemId: "sys1" }, - { stopId: "st1", routeId: "r2", position: 2, systemId: "sys1" }, - { stopId: "st2", routeId: "r1", position: 3, systemId: "sys1" }, - { stopId: "st2", routeId: "r2", position: 4, systemId: "sys1" }, + { stopId: "st1", routeId: "r1", position: 1, systemId: "sys1", updatedTimeMs: Date.now(), }, + { stopId: "st1", routeId: "r2", position: 2, systemId: "sys1", updatedTimeMs: Date.now(), }, + { stopId: "st2", routeId: "r1", position: 3, systemId: "sys1", updatedTimeMs: Date.now(), }, + { stopId: "st2", routeId: "r2", position: 4, systemId: "sys1", updatedTimeMs: Date.now(), }, ]; } export function generateMockEtas(): IEta[] { return [ - { shuttleId: "sh1", stopId: "st1", secondsRemaining: 120, systemId: "sys1" }, - { shuttleId: "sh1", stopId: "st2", secondsRemaining: 180, systemId: "sys1" }, - { shuttleId: "sh2", stopId: "st3", secondsRemaining: 240, systemId: "sys1" }, + { shuttleId: "sh1", stopId: "st1", secondsRemaining: 120, systemId: "sys1", updatedTimeMs: Date.now() }, + { shuttleId: "sh1", stopId: "st2", secondsRemaining: 180, systemId: "sys1", updatedTimeMs: Date.now() }, + { shuttleId: "sh2", stopId: "st3", secondsRemaining: 240, systemId: "sys1", updatedTimeMs: Date.now() }, ]; } From ee4b11a3081e01c86284c3cf5fb5632dc94e8297 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Tue, 29 Apr 2025 16:19:41 -0700 Subject: [PATCH 07/17] remove "optional" from entity type --- src/entities/ParkingRepositoryEntities.ts | 4 ++-- src/entities/SharedEntities.ts | 2 +- src/entities/ShuttleRepositoryEntities.ts | 12 ++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/entities/ParkingRepositoryEntities.ts b/src/entities/ParkingRepositoryEntities.ts index f0dadea..b78a754 100644 --- a/src/entities/ParkingRepositoryEntities.ts +++ b/src/entities/ParkingRepositoryEntities.ts @@ -1,6 +1,6 @@ -import { ICoordinates, IEntityWithId, IEntityWithOptionalTimestamp } from "./SharedEntities"; +import { ICoordinates, IEntityWithId, IEntityWithTimestamp } from "./SharedEntities"; -export interface IParkingStructure extends IEntityWithOptionalTimestamp, IEntityWithId { +export interface IParkingStructure extends IEntityWithTimestamp, IEntityWithId { address: string; capacity: number; spotsAvailable: number; diff --git a/src/entities/SharedEntities.ts b/src/entities/SharedEntities.ts index 9b92713..d23915a 100644 --- a/src/entities/SharedEntities.ts +++ b/src/entities/SharedEntities.ts @@ -1,4 +1,4 @@ -export interface IEntityWithOptionalTimestamp { +export interface IEntityWithTimestamp { updatedTimeMs: number; } diff --git a/src/entities/ShuttleRepositoryEntities.ts b/src/entities/ShuttleRepositoryEntities.ts index 3ab9a29..608bda6 100644 --- a/src/entities/ShuttleRepositoryEntities.ts +++ b/src/entities/ShuttleRepositoryEntities.ts @@ -1,19 +1,19 @@ -import { ICoordinates, IEntityWithId, IEntityWithOptionalTimestamp } from "./SharedEntities"; +import { ICoordinates, IEntityWithId, IEntityWithTimestamp } from "./SharedEntities"; -export interface IRoute extends IEntityWithId, IEntityWithOptionalTimestamp { +export interface IRoute extends IEntityWithId, IEntityWithTimestamp { name: string; color: string; polylineCoordinates: ICoordinates[]; systemId: string; } -export interface IStop extends IEntityWithId, IEntityWithOptionalTimestamp { +export interface IStop extends IEntityWithId, IEntityWithTimestamp { name: string; systemId: string; coordinates: ICoordinates; } -export interface IShuttle extends IEntityWithId, IEntityWithOptionalTimestamp { +export interface IShuttle extends IEntityWithId, IEntityWithTimestamp { coordinates: ICoordinates; name: string; routeId: string; @@ -21,14 +21,14 @@ export interface IShuttle extends IEntityWithId, IEntityWithOptionalTimestamp { orientationInDegrees: number; } -export interface IEta extends IEntityWithOptionalTimestamp { +export interface IEta extends IEntityWithTimestamp { secondsRemaining: number; shuttleId: string; stopId: string; systemId: string; } -export interface IOrderedStop extends IEntityWithOptionalTimestamp { +export interface IOrderedStop extends IEntityWithTimestamp { nextStop?: IOrderedStop; previousStop?: IOrderedStop; routeId: string; From 6dae7959bfdc7617469566339cdd6008c60c487e Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Tue, 29 Apr 2025 16:23:30 -0700 Subject: [PATCH 08/17] update schema to include timestamp --- schema.graphqls | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/schema.graphqls b/schema.graphqls index 614bfa0..a1587b2 100644 --- a/schema.graphqls +++ b/schema.graphqls @@ -27,6 +27,7 @@ type ParkingStructure { spotsAvailable: Int! coordinates: Coordinates! address: String! + updatedTimeMs: Int! } type Route { @@ -37,6 +38,7 @@ type Route { shuttles: [Shuttle!] polylineCoordinates: [Coordinates!]! color: String! + updatedTimeMs: Int! } type OrderedStop { @@ -47,6 +49,7 @@ type OrderedStop { stop: Stop stopId: ID! systemId: ID! + updatedTimeMs: Int! } type Stop { @@ -56,6 +59,7 @@ type Stop { coordinates: Coordinates! etas: [ETA!] orderedStops: [OrderedStop!] + updatedTimeMs: Int! } type Coordinates { @@ -70,6 +74,7 @@ type ETA { shuttleId: ID! secondsRemaining: Float! systemId: ID! + updatedTimeMs: Int! } type Shuttle { @@ -82,6 +87,7 @@ type Shuttle { etas: [ETA!] eta(forStopId: ID): ETA orientationInDegrees: Float! + updatedTimeMs: Int! } # Queries From b02e2f721deb661808ffa97dab69320f7bd03cb0 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Tue, 29 Apr 2025 16:26:47 -0700 Subject: [PATCH 09/17] update resolvers to include timestamps --- src/resolvers/OrderedStopResolvers.ts | 2 ++ src/resolvers/RouteResolvers.ts | 5 ++++- src/resolvers/ShuttleResolvers.ts | 23 ++++++++++++++--------- src/resolvers/SystemResolvers.ts | 2 ++ 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/resolvers/OrderedStopResolvers.ts b/src/resolvers/OrderedStopResolvers.ts index 0410e46..c29de5f 100644 --- a/src/resolvers/OrderedStopResolvers.ts +++ b/src/resolvers/OrderedStopResolvers.ts @@ -24,6 +24,7 @@ export const OrderedStopResolvers: Resolvers = { routeId: parent.routeId, stopId: nextOrderedStopObject.id, systemId: system.id, + updatedTimeMs: nextOrderedStopObject.updatedTimeMs } }, previousStop: async (parent, args, contextValue, _info): Promise => { @@ -47,6 +48,7 @@ export const OrderedStopResolvers: Resolvers = { routeId: parent.routeId, stopId: previousOrderedStopObject.id, systemId: system.id, + updatedTimeMs: previousOrderedStopObject.updatedTimeMs, } }, stop: async (parent, args, contextValue, _info) => { diff --git a/src/resolvers/RouteResolvers.ts b/src/resolvers/RouteResolvers.ts index aa29fdc..732c70e 100644 --- a/src/resolvers/RouteResolvers.ts +++ b/src/resolvers/RouteResolvers.ts @@ -13,7 +13,8 @@ export const RouteResolvers: Resolvers = { coordinates, name, id, - orientationInDegrees + orientationInDegrees, + updatedTimeMs }) => ({ coordinates: coordinates as Coordinates, name, @@ -22,6 +23,7 @@ export const RouteResolvers: Resolvers = { id, orientationInDegrees, systemId: parent.systemId, + updatedTimeMs, })); }, orderedStop: async (parent, args, contextValue, info) => { @@ -41,6 +43,7 @@ export const RouteResolvers: Resolvers = { routeId: parent.id, route: parent, systemId: system.id, + updatedTimeMs: orderedStop.updatedTimeMs, } }, }, diff --git a/src/resolvers/ShuttleResolvers.ts b/src/resolvers/ShuttleResolvers.ts index 103e40f..92cb62c 100644 --- a/src/resolvers/ShuttleResolvers.ts +++ b/src/resolvers/ShuttleResolvers.ts @@ -18,6 +18,7 @@ export const ShuttleResolvers: Resolvers = { shuttleId: parent.id, shuttle: parent, systemId: system.id, + updatedTimeMs: etaForStopId.updatedTimeMs, }; }, etas: async (parent, args, contextValue, info) => { @@ -27,17 +28,20 @@ export const ShuttleResolvers: Resolvers = { const etasForShuttle = await system.shuttleRepository.getEtasForShuttleId(parent.id); if (!etasForShuttle) return null; - const computedEtas = await Promise.all(etasForShuttle.map(async ({ - secondsRemaining, - stopId, - }): Promise => { - return { + const computedEtas = await Promise.all( + etasForShuttle.map(async ({ secondsRemaining, stopId, - shuttle: parent, - shuttleId: parent.id, - systemId: system.id, - } + updatedTimeMs + }): Promise => { + return { + secondsRemaining, + stopId, + shuttle: parent, + shuttleId: parent.id, + systemId: system.id, + updatedTimeMs, + } })); if (computedEtas.every((eta) => eta !== null)) { @@ -59,6 +63,7 @@ export const ShuttleResolvers: Resolvers = { name: route.name, polylineCoordinates: route.polylineCoordinates, systemId: system.id, + updatedTimeMs: route.updatedTimeMs } } }, diff --git a/src/resolvers/SystemResolvers.ts b/src/resolvers/SystemResolvers.ts index dc10fe9..e48e45f 100644 --- a/src/resolvers/SystemResolvers.ts +++ b/src/resolvers/SystemResolvers.ts @@ -36,6 +36,7 @@ export const SystemResolvers: Resolvers = { name: stop.name, coordinates: stop.coordinates as Coordinates, systemId: parent.id, + updatedTimeMs: stop.updatedTimeMs, }; }, route: async (parent, args, contextValue, _info) => { @@ -55,6 +56,7 @@ export const SystemResolvers: Resolvers = { name: route.name, polylineCoordinates: route.polylineCoordinates as Coordinates[], systemId: parent.id, + updatedTimeMs: route.updatedTimeMs, }; }, shuttle: async (parent, args, contextValue, _info) => { From bdb1da0bc45390bcf8d1cc131be6f74dcc2e719e Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Tue, 29 Apr 2025 16:30:45 -0700 Subject: [PATCH 10/17] fix test due to mismatched timestamps on parking repo loader --- .../ChapmanApiBasedParkingRepositoryLoaderTests.test.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/loaders/parking/ChapmanApiBasedParkingRepositoryLoaderTests.test.ts b/test/loaders/parking/ChapmanApiBasedParkingRepositoryLoaderTests.test.ts index b92026e..2abd5d7 100644 --- a/test/loaders/parking/ChapmanApiBasedParkingRepositoryLoaderTests.test.ts +++ b/test/loaders/parking/ChapmanApiBasedParkingRepositoryLoaderTests.test.ts @@ -78,6 +78,11 @@ describe("ChapmanApiBasedParkingRepositoryLoader", () => { expectedStructures[1].id = ChapmanApiBasedParkingRepositoryLoader.generateId(expectedStructures[1].address); const structuresFromLoader = await loader.repository.getParkingStructures(); + + // Set updatedTimeMs on expected data to avoid comparison + expectedStructures[0].updatedTimeMs = structuresFromLoader[0].updatedTimeMs; + expectedStructures[1].updatedTimeMs = structuresFromLoader[1].updatedTimeMs; + expect(structuresFromLoader).toEqual(expectedStructures); }); From ba82ce9f98506fd2c553bada14441852fd1adc79 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Tue, 29 Apr 2025 16:46:55 -0700 Subject: [PATCH 11/17] add custom DateTime scalar type --- schema.graphqls | 2 ++ src/MergedResolvers.ts | 4 +++- src/scalars/DateTime.ts | 28 ++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/scalars/DateTime.ts diff --git a/schema.graphqls b/schema.graphqls index a1587b2..ff2f1a9 100644 --- a/schema.graphqls +++ b/schema.graphqls @@ -1,3 +1,5 @@ +scalar DateTime + # The Interchange system schema. # Note how Passio ID and parking ID are abstracted away # from the endpoints. diff --git a/src/MergedResolvers.ts b/src/MergedResolvers.ts index 795ec38..c1925ff 100644 --- a/src/MergedResolvers.ts +++ b/src/MergedResolvers.ts @@ -1,4 +1,4 @@ -import { Coordinates, Eta, OrderedStop, Resolvers } from "./generated/graphql"; +import { Resolvers } from "./generated/graphql"; import { ServerContext } from "./ServerContext"; import { QueryResolvers } from "./resolvers/QueryResolvers"; import { SystemResolvers } from "./resolvers/SystemResolvers"; @@ -9,6 +9,7 @@ import { ShuttleResolvers } from "./resolvers/ShuttleResolvers"; import { RouteResolvers } from "./resolvers/RouteResolvers"; import { MutationResolvers } from "./resolvers/MutationResolvers"; import { ParkingSystemResolvers } from "./resolvers/ParkingSystemResolvers"; +import { DateTime } from "./scalars/DateTime"; export const MergedResolvers: Resolvers = { ...QueryResolvers, @@ -20,4 +21,5 @@ export const MergedResolvers: Resolvers = { ...OrderedStopResolvers, ...EtaResolvers, ...MutationResolvers, + DateTime: DateTime, }; diff --git a/src/scalars/DateTime.ts b/src/scalars/DateTime.ts new file mode 100644 index 0000000..45a5ac6 --- /dev/null +++ b/src/scalars/DateTime.ts @@ -0,0 +1,28 @@ +import { GraphQLScalarType } from "graphql/type"; +import { Kind } from "graphql/language"; + +// See Apollo documentation: https://www.apollographql.com/docs/apollo-server/schema/custom-scalars#providing-custom-scalars-to-apollo-server +export const DateTime = new GraphQLScalarType({ + name: 'DateTime', + description: 'DateTime custom scalar type', + serialize(value) { + if (value instanceof Date) { + return value.getTime(); + } else if (value instanceof Number) { + return value; + } + throw Error('GraphQL Date Scalar serializer expected a `Date` object or number'); + }, + parseValue(value) { + if (typeof value === 'number') { + return new Date(value); + } + throw new Error('GraphQL Date Scalar parser expected a `number`'); + }, + parseLiteral(ast) { + if (ast.kind === Kind.INT) { + return new Date(parseInt(ast.value, 10)); + } + return null; + }, +}) From c21446b80a0ac91166acc38a0990c20ffa908c26 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Tue, 29 Apr 2025 16:48:14 -0700 Subject: [PATCH 12/17] update schema to use new DateTime scalar --- schema.graphqls | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/schema.graphqls b/schema.graphqls index ff2f1a9..b37b8d4 100644 --- a/schema.graphqls +++ b/schema.graphqls @@ -29,7 +29,7 @@ type ParkingStructure { spotsAvailable: Int! coordinates: Coordinates! address: String! - updatedTimeMs: Int! + updatedTime: DateTime } type Route { @@ -40,7 +40,7 @@ type Route { shuttles: [Shuttle!] polylineCoordinates: [Coordinates!]! color: String! - updatedTimeMs: Int! + updatedTime: DateTime } type OrderedStop { @@ -51,7 +51,7 @@ type OrderedStop { stop: Stop stopId: ID! systemId: ID! - updatedTimeMs: Int! + updatedTime: DateTime } type Stop { @@ -61,7 +61,7 @@ type Stop { coordinates: Coordinates! etas: [ETA!] orderedStops: [OrderedStop!] - updatedTimeMs: Int! + updatedTime: DateTime } type Coordinates { @@ -76,7 +76,7 @@ type ETA { shuttleId: ID! secondsRemaining: Float! systemId: ID! - updatedTimeMs: Int! + updatedTime: DateTime } type Shuttle { @@ -89,7 +89,7 @@ type Shuttle { etas: [ETA!] eta(forStopId: ID): ETA orientationInDegrees: Float! - updatedTimeMs: Int! + updatedTime: DateTime } # Queries From b91f8ce1513253c17ef988d34261bc5bf58c0551 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Tue, 29 Apr 2025 16:49:55 -0700 Subject: [PATCH 13/17] update resolvers with updated argument name --- src/resolvers/OrderedStopResolvers.ts | 4 ++-- src/resolvers/ShuttleResolvers.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/resolvers/OrderedStopResolvers.ts b/src/resolvers/OrderedStopResolvers.ts index c29de5f..869fd34 100644 --- a/src/resolvers/OrderedStopResolvers.ts +++ b/src/resolvers/OrderedStopResolvers.ts @@ -24,7 +24,7 @@ export const OrderedStopResolvers: Resolvers = { routeId: parent.routeId, stopId: nextOrderedStopObject.id, systemId: system.id, - updatedTimeMs: nextOrderedStopObject.updatedTimeMs + updatedTime: nextOrderedStopObject.updatedTimeMs } }, previousStop: async (parent, args, contextValue, _info): Promise => { @@ -48,7 +48,7 @@ export const OrderedStopResolvers: Resolvers = { routeId: parent.routeId, stopId: previousOrderedStopObject.id, systemId: system.id, - updatedTimeMs: previousOrderedStopObject.updatedTimeMs, + updatedTime: previousOrderedStopObject.updatedTimeMs, } }, stop: async (parent, args, contextValue, _info) => { diff --git a/src/resolvers/ShuttleResolvers.ts b/src/resolvers/ShuttleResolvers.ts index 92cb62c..ca3ec88 100644 --- a/src/resolvers/ShuttleResolvers.ts +++ b/src/resolvers/ShuttleResolvers.ts @@ -40,7 +40,7 @@ export const ShuttleResolvers: Resolvers = { shuttle: parent, shuttleId: parent.id, systemId: system.id, - updatedTimeMs, + updatedTime: updatedTimeMs, } })); From f68dad0ca2183ee21cc00fecfd4851cae6f907fa Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Tue, 29 Apr 2025 16:54:22 -0700 Subject: [PATCH 14/17] update parking system tests to use updatedTime parameter --- .../ParkingSystemResolverTests.test.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/test/resolvers/ParkingSystemResolverTests.test.ts b/test/resolvers/ParkingSystemResolverTests.test.ts index 9515c18..c207536 100644 --- a/test/resolvers/ParkingSystemResolverTests.test.ts +++ b/test/resolvers/ParkingSystemResolverTests.test.ts @@ -40,6 +40,7 @@ describe("ParkingSystemResolver", () => { longitude } address + updatedTime } } } @@ -56,8 +57,15 @@ describe("ParkingSystemResolver", () => { assert(response.body.kind === "single"); expect(response.body.singleResult.errors).toBeUndefined(); + const parkingStructures = (response.body.singleResult.data as any).system.parkingSystem.parkingStructures; - expect(parkingStructures).toEqual(expectedParkingStructures); + const transformedParkingStructures = parkingStructures.map((structure: any) => { + const newStructure = { ...structure, updatedTimeMs: structure.updatedTime }; + delete newStructure.updatedTime; + return newStructure; + }); + + expect(transformedParkingStructures).toEqual(expectedParkingStructures); }); it("returns a blank array if there are no parking structures", async () => { @@ -65,7 +73,9 @@ describe("ParkingSystemResolver", () => { assert(response.body.kind === "single"); expect(response.body.singleResult.errors).toBeUndefined(); + const parkingStructures = (response.body.singleResult.data as any).system.parkingSystem.parkingStructures; + expect(parkingStructures).toHaveLength(0); }); }); @@ -87,6 +97,7 @@ describe("ParkingSystemResolver", () => { longitude } address + updatedTime } } } @@ -116,7 +127,10 @@ describe("ParkingSystemResolver", () => { assert(response.body.kind === "single"); expect(response.body.singleResult.errors).toBeUndefined(); + const parkingStructure = (response.body.singleResult.data as any).system.parkingSystem.parkingStructure; + parkingStructure.updatedTimeMs = parkingStructure.updatedTime; + delete parkingStructure.updatedTime; expect(parkingStructure).toEqual(expectedParkingStructure); }); @@ -132,6 +146,7 @@ describe("ParkingSystemResolver", () => { assert(response.body.kind === "single"); expect(response.body.singleResult.errors).toBeUndefined(); + const parkingStructure = (response.body.singleResult.data as any).system.parkingSystem.parkingStructure; expect(parkingStructure).toBeNull(); }); From b58babc7eae34216093bf31db5f62208611111b7 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Tue, 29 Apr 2025 17:01:51 -0700 Subject: [PATCH 15/17] change updatedTime into a Date --- src/entities/SharedEntities.ts | 2 +- .../ChapmanApiBasedParkingRepositoryLoader.ts | 2 +- src/loaders/parking/loadParkingTestData.ts | 4 +-- .../ApiBasedShuttleRepositoryLoader.ts | 14 ++++---- src/loaders/shuttle/loadShuttleTestData.ts | 32 ++++++++--------- src/resolvers/OrderedStopResolvers.ts | 4 +-- src/resolvers/RouteResolvers.ts | 6 ++-- src/resolvers/ShuttleResolvers.ts | 8 ++--- src/resolvers/SystemResolvers.ts | 4 +-- ...iBasedParkingRepositoryLoaderTests.test.ts | 8 ++--- .../ETANotificationSchedulerTests.test.ts | 2 +- .../InMemoryParkingRepositoryTests.test.ts | 2 +- test/testHelpers/mockDataGenerators.ts | 36 +++++++++---------- 13 files changed, 62 insertions(+), 62 deletions(-) diff --git a/src/entities/SharedEntities.ts b/src/entities/SharedEntities.ts index d23915a..67aa03e 100644 --- a/src/entities/SharedEntities.ts +++ b/src/entities/SharedEntities.ts @@ -1,5 +1,5 @@ export interface IEntityWithTimestamp { - updatedTimeMs: number; + updatedTime: Date; } export interface IEntityWithId { diff --git a/src/loaders/parking/ChapmanApiBasedParkingRepositoryLoader.ts b/src/loaders/parking/ChapmanApiBasedParkingRepositoryLoader.ts index 707d3c5..1c08a06 100644 --- a/src/loaders/parking/ChapmanApiBasedParkingRepositoryLoader.ts +++ b/src/loaders/parking/ChapmanApiBasedParkingRepositoryLoader.ts @@ -59,7 +59,7 @@ export class ChapmanApiBasedParkingRepositoryLoader implements ParkingRepository name: jsonStructure.Name, spotsAvailable: jsonStructure.CurrentCount > jsonStructure.Capacity ? jsonStructure.Capacity : jsonStructure.CurrentCount, address: jsonStructure.Address, - updatedTimeMs: Date.now(), + updatedTime: Date.now(), } return structureToReturn; diff --git a/src/loaders/parking/loadParkingTestData.ts b/src/loaders/parking/loadParkingTestData.ts index c790782..d117ab8 100644 --- a/src/loaders/parking/loadParkingTestData.ts +++ b/src/loaders/parking/loadParkingTestData.ts @@ -12,7 +12,7 @@ const parkingStructures: IParkingStructure[] = [ }, name: "Anderson Structure", id: "1", - updatedTimeMs: Date.now(), + updatedTime: Date.now(), }, { address: "200 W Sycamore Ave, Orange, CA 92866-1053", @@ -24,7 +24,7 @@ const parkingStructures: IParkingStructure[] = [ }, name: "Barrera", id: "2", - updatedTimeMs: Date.now(), + updatedTime: Date.now(), } ]; diff --git a/src/loaders/shuttle/ApiBasedShuttleRepositoryLoader.ts b/src/loaders/shuttle/ApiBasedShuttleRepositoryLoader.ts index dcc19cf..95cbdc2 100644 --- a/src/loaders/shuttle/ApiBasedShuttleRepositoryLoader.ts +++ b/src/loaders/shuttle/ApiBasedShuttleRepositoryLoader.ts @@ -73,7 +73,7 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader id: jsonRoute.myid, polylineCoordinates: [], systemId: this.systemIdForConstructedData, - updatedTimeMs: Date.now(), + updatedTime: Date.now(), }; await this.repository.addOrUpdateRoute(constructedRoute); @@ -174,7 +174,7 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader systemId: this.systemIdForConstructedData, id: `${jsonBus.busId}`, orientationInDegrees: parseFloat(jsonBus.calculatedCourse), - updatedTimeMs: Date.now(), + updatedTime: Date.now(), } await this.repository.addOrUpdateShuttle(constructedShuttle); @@ -223,7 +223,7 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader secondsRemaining: jsonEta.secondsSpent, shuttleId: `${shuttleId}`, stopId: stopId, - updatedTimeMs: Date.now(), + updatedTime: Date.now(), systemId: this.systemIdForConstructedData, }; @@ -251,7 +251,7 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader latitude: parseFloat(stop.latitude), longitude: parseFloat(stop.longitude), }, - updatedTimeMs: Date.now(), + updatedTime: Date.now(), }; await this.repository.addOrUpdateStop(constructedStop); @@ -283,7 +283,7 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader stopId, position: index + 1, systemId: this.systemIdForConstructedData, - updatedTimeMs: Date.now(), + updatedTime: Date.now(), }; } @@ -293,7 +293,7 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader stopId: jsonOrderedStopData[index - 1][1], position: index, systemId: this.systemIdForConstructedData, - updatedTimeMs: Date.now(), + updatedTime: Date.now(), }; } if (index < jsonOrderedStopData.length - 1) { @@ -302,7 +302,7 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader stopId: jsonOrderedStopData[index + 1][1], position: index + 2, systemId: this.systemIdForConstructedData, - updatedTimeMs: Date.now(), + updatedTime: Date.now(), }; } diff --git a/src/loaders/shuttle/loadShuttleTestData.ts b/src/loaders/shuttle/loadShuttleTestData.ts index c4770f1..5b52402 100644 --- a/src/loaders/shuttle/loadShuttleTestData.ts +++ b/src/loaders/shuttle/loadShuttleTestData.ts @@ -4324,7 +4324,7 @@ const routes: IRoute[] = [ systemId: supportedIntegrationTestSystems[0].id, polylineCoordinates: redRoutePolylineCoordinates, color: "#db2316", - updatedTimeMs: Date.now(), + updatedTime: Date.now(), }, { name: "Teal Route", @@ -4332,7 +4332,7 @@ const routes: IRoute[] = [ systemId: supportedIntegrationTestSystems[0].id, polylineCoordinates: tealRoutePolylineCoordinates, color: "#21bdd1", - updatedTimeMs: Date.now(), + updatedTime: Date.now(), }, ]; @@ -4345,7 +4345,7 @@ const stops: IStop[] = [ longitude: -117.8892805, }, systemId: supportedIntegrationTestSystems[0].id, - updatedTimeMs: Date.now(), + updatedTime: Date.now(), }, { id: "2", @@ -4355,7 +4355,7 @@ const stops: IStop[] = [ longitude: -117.895966, }, systemId: supportedIntegrationTestSystems[0].id, - updatedTimeMs: Date.now(), + updatedTime: Date.now(), }, { id: "3", @@ -4365,7 +4365,7 @@ const stops: IStop[] = [ "longitude": -117.85281 }, systemId: supportedIntegrationTestSystems[0].id, - updatedTimeMs: Date.now(), + updatedTime: Date.now(), } ]; @@ -4375,14 +4375,14 @@ const orderedStopsForRedRoute: IOrderedStop[] = [ stopId: stops[0].id, position: 1, systemId: "1", - updatedTimeMs: Date.now(), + updatedTime: Date.now(), }, { routeId: routes[0].id, stopId: stops[2].id, position: 2, systemId: "1", - updatedTimeMs: Date.now(), + updatedTime: Date.now(), }, ]; @@ -4392,21 +4392,21 @@ const orderedStopsForTealRoute: IOrderedStop[] = [ stopId: stops[0].id, position: 1, systemId: supportedIntegrationTestSystems[0].id, - updatedTimeMs: Date.now(), + updatedTime: Date.now(), }, { routeId: routes[1].id, stopId: stops[1].id, position: 2, systemId: supportedIntegrationTestSystems[0].id, - updatedTimeMs: Date.now(), + updatedTime: Date.now(), }, { routeId: routes[1].id, stopId: stops[2].id, position: 2, systemId: supportedIntegrationTestSystems[0].id, - updatedTimeMs: Date.now(), + updatedTime: Date.now(), }, ] @@ -4426,7 +4426,7 @@ const shuttles: IShuttle[] = [ routeId: routes[0].id, systemId: supportedIntegrationTestSystems[0].id, orientationInDegrees: 45.91, - updatedTimeMs: Date.now(), + updatedTime: Date.now(), }, { name: "24", @@ -4438,7 +4438,7 @@ const shuttles: IShuttle[] = [ routeId: routes[0].id, systemId: supportedIntegrationTestSystems[0].id, orientationInDegrees: 90.24, - updatedTimeMs: Date.now(), + updatedTime: Date.now(), } ]; @@ -4448,28 +4448,28 @@ const etas: IEta[] = [ shuttleId: shuttles[0].id, secondsRemaining: 12.023, systemId: supportedIntegrationTestSystems[0].id, - updatedTimeMs: Date.now(), + updatedTime: Date.now(), }, { stopId: stops[2].id, shuttleId: shuttles[0].id, secondsRemaining: 600.123, systemId: supportedIntegrationTestSystems[0].id, - updatedTimeMs: Date.now(), + updatedTime: Date.now(), }, { stopId: stops[2].id, shuttleId: shuttles[1].id, secondsRemaining: 172.015, systemId: supportedIntegrationTestSystems[0].id, - updatedTimeMs: Date.now(), + updatedTime: Date.now(), }, { stopId: stops[0].id, shuttleId: shuttles[1].id, secondsRemaining: 710.152, systemId: supportedIntegrationTestSystems[0].id, - updatedTimeMs: Date.now(), + updatedTime: Date.now(), } ]; diff --git a/src/resolvers/OrderedStopResolvers.ts b/src/resolvers/OrderedStopResolvers.ts index 869fd34..54ae00a 100644 --- a/src/resolvers/OrderedStopResolvers.ts +++ b/src/resolvers/OrderedStopResolvers.ts @@ -24,7 +24,7 @@ export const OrderedStopResolvers: Resolvers = { routeId: parent.routeId, stopId: nextOrderedStopObject.id, systemId: system.id, - updatedTime: nextOrderedStopObject.updatedTimeMs + updatedTime: nextOrderedStopObject.updatedTime } }, previousStop: async (parent, args, contextValue, _info): Promise => { @@ -48,7 +48,7 @@ export const OrderedStopResolvers: Resolvers = { routeId: parent.routeId, stopId: previousOrderedStopObject.id, systemId: system.id, - updatedTime: previousOrderedStopObject.updatedTimeMs, + updatedTime: previousOrderedStopObject.updatedTime, } }, stop: async (parent, args, contextValue, _info) => { diff --git a/src/resolvers/RouteResolvers.ts b/src/resolvers/RouteResolvers.ts index 732c70e..d24e992 100644 --- a/src/resolvers/RouteResolvers.ts +++ b/src/resolvers/RouteResolvers.ts @@ -14,7 +14,7 @@ export const RouteResolvers: Resolvers = { name, id, orientationInDegrees, - updatedTimeMs + updatedTime }) => ({ coordinates: coordinates as Coordinates, name, @@ -23,7 +23,7 @@ export const RouteResolvers: Resolvers = { id, orientationInDegrees, systemId: parent.systemId, - updatedTimeMs, + updatedTime: updatedTimeMs, })); }, orderedStop: async (parent, args, contextValue, info) => { @@ -43,7 +43,7 @@ export const RouteResolvers: Resolvers = { routeId: parent.id, route: parent, systemId: system.id, - updatedTimeMs: orderedStop.updatedTimeMs, + updatedTimeMs: orderedStop.updatedTime, } }, }, diff --git a/src/resolvers/ShuttleResolvers.ts b/src/resolvers/ShuttleResolvers.ts index ca3ec88..2eb9478 100644 --- a/src/resolvers/ShuttleResolvers.ts +++ b/src/resolvers/ShuttleResolvers.ts @@ -18,7 +18,7 @@ export const ShuttleResolvers: Resolvers = { shuttleId: parent.id, shuttle: parent, systemId: system.id, - updatedTimeMs: etaForStopId.updatedTimeMs, + updatedTimeMs: etaForStopId.updatedTime, }; }, etas: async (parent, args, contextValue, info) => { @@ -32,7 +32,7 @@ export const ShuttleResolvers: Resolvers = { etasForShuttle.map(async ({ secondsRemaining, stopId, - updatedTimeMs + updatedTime }): Promise => { return { secondsRemaining, @@ -40,7 +40,7 @@ export const ShuttleResolvers: Resolvers = { shuttle: parent, shuttleId: parent.id, systemId: system.id, - updatedTime: updatedTimeMs, + updatedTime: updatedTime, } })); @@ -63,7 +63,7 @@ export const ShuttleResolvers: Resolvers = { name: route.name, polylineCoordinates: route.polylineCoordinates, systemId: system.id, - updatedTimeMs: route.updatedTimeMs + updatedTimeMs: route.updatedTime } } }, diff --git a/src/resolvers/SystemResolvers.ts b/src/resolvers/SystemResolvers.ts index e48e45f..a955fc2 100644 --- a/src/resolvers/SystemResolvers.ts +++ b/src/resolvers/SystemResolvers.ts @@ -36,7 +36,7 @@ export const SystemResolvers: Resolvers = { name: stop.name, coordinates: stop.coordinates as Coordinates, systemId: parent.id, - updatedTimeMs: stop.updatedTimeMs, + updatedTimeMs: stop.updatedTime, }; }, route: async (parent, args, contextValue, _info) => { @@ -56,7 +56,7 @@ export const SystemResolvers: Resolvers = { name: route.name, polylineCoordinates: route.polylineCoordinates as Coordinates[], systemId: parent.id, - updatedTimeMs: route.updatedTimeMs, + updatedTimeMs: route.updatedTime, }; }, shuttle: async (parent, args, contextValue, _info) => { diff --git a/test/loaders/parking/ChapmanApiBasedParkingRepositoryLoaderTests.test.ts b/test/loaders/parking/ChapmanApiBasedParkingRepositoryLoaderTests.test.ts index 2abd5d7..02012bb 100644 --- a/test/loaders/parking/ChapmanApiBasedParkingRepositoryLoaderTests.test.ts +++ b/test/loaders/parking/ChapmanApiBasedParkingRepositoryLoaderTests.test.ts @@ -59,7 +59,7 @@ describe("ChapmanApiBasedParkingRepositoryLoader", () => { }, name: "Anderson Structure", id: "", - updatedTimeMs: Date.now(), + updatedTime: Date.now(), }, { address: "200 W Sycamore Ave, Orange, CA 92866-1053", @@ -71,7 +71,7 @@ describe("ChapmanApiBasedParkingRepositoryLoader", () => { }, name: "Barrera", id: "", - updatedTimeMs: Date.now(), + updatedTime: Date.now(), } ]; expectedStructures[0].id = ChapmanApiBasedParkingRepositoryLoader.generateId(expectedStructures[0].address); @@ -80,8 +80,8 @@ describe("ChapmanApiBasedParkingRepositoryLoader", () => { const structuresFromLoader = await loader.repository.getParkingStructures(); // Set updatedTimeMs on expected data to avoid comparison - expectedStructures[0].updatedTimeMs = structuresFromLoader[0].updatedTimeMs; - expectedStructures[1].updatedTimeMs = structuresFromLoader[1].updatedTimeMs; + expectedStructures[0].updatedTime = structuresFromLoader[0].updatedTime; + expectedStructures[1].updatedTime = structuresFromLoader[1].updatedTime; expect(structuresFromLoader).toEqual(expectedStructures); }); diff --git a/test/notifications/schedulers/ETANotificationSchedulerTests.test.ts b/test/notifications/schedulers/ETANotificationSchedulerTests.test.ts index 136dd16..229dc22 100644 --- a/test/notifications/schedulers/ETANotificationSchedulerTests.test.ts +++ b/test/notifications/schedulers/ETANotificationSchedulerTests.test.ts @@ -52,7 +52,7 @@ describe("ETANotificationScheduler", () => { stopId: stop.id, secondsRemaining: 120, systemId: "1", - updatedTimeMs: Date.now(), + updatedTime: Date.now(), }; const notificationData1 = { diff --git a/test/repositories/InMemoryParkingRepositoryTests.test.ts b/test/repositories/InMemoryParkingRepositoryTests.test.ts index 2e541bf..ece527b 100644 --- a/test/repositories/InMemoryParkingRepositoryTests.test.ts +++ b/test/repositories/InMemoryParkingRepositoryTests.test.ts @@ -14,7 +14,7 @@ describe("InMemoryParkingRepository", () => { name: "Anderson Parking Structure", capacity: 100, address: "300 E Walnut Ave, Orange, CA 92867", - updatedTimeMs: Date.now(), + updatedTime: Date.now(), }; beforeEach(() => { diff --git a/test/testHelpers/mockDataGenerators.ts b/test/testHelpers/mockDataGenerators.ts index 64f2cbc..7e237e8 100644 --- a/test/testHelpers/mockDataGenerators.ts +++ b/test/testHelpers/mockDataGenerators.ts @@ -17,7 +17,7 @@ export function generateParkingStructures(): IParkingStructure[] { "name": "Anderson Structure", "spotsAvailable": 163, "address": "300 E Walnut, Orange, CA 92867", - updatedTimeMs: Date.now(), + updatedTime: Date.now(), }, { "capacity": 692, @@ -29,7 +29,7 @@ export function generateParkingStructures(): IParkingStructure[] { "name": "Barrera", "spotsAvailable": 179, "address": "200 W Sycamore Ave, Orange, CA 92866-1053", - updatedTimeMs: Date.now(), + updatedTime: Date.now(), } ]; } @@ -46,7 +46,7 @@ export function generateMockShuttles(): IShuttle[] { longitude: 20 }, orientationInDegrees: 25.163, - updatedTimeMs: Date.now(), + updatedTime: Date.now(), }, { id: "sh2", @@ -58,7 +58,7 @@ export function generateMockShuttles(): IShuttle[] { longitude: 25 }, orientationInDegrees: 50.912, - updatedTimeMs: Date.now(), + updatedTime: Date.now(), }, { id: "sh3", @@ -70,40 +70,40 @@ export function generateMockShuttles(): IShuttle[] { longitude: 40 }, orientationInDegrees: 321.019, - updatedTimeMs: Date.now(), + updatedTime: Date.now(), }, ]; } export function generateMockRoutes(): IRoute[] { return [ - { id: "r1", name: "Route 1", color: "red", systemId: "sys1", polylineCoordinates: [], updatedTimeMs: Date.now() }, - { id: "r2", name: "Route 2", color: "blue", systemId: "sys2", polylineCoordinates: [], updatedTimeMs: Date.now() }, - { id: "r3", name: "Route 3", color: "green", systemId: "sys3", polylineCoordinates: [], updatedTimeMs: Date.now() }, + { id: "r1", name: "Route 1", color: "red", systemId: "sys1", polylineCoordinates: [], updatedTime: Date.now() }, + { id: "r2", name: "Route 2", color: "blue", systemId: "sys2", polylineCoordinates: [], updatedTime: Date.now() }, + { id: "r3", name: "Route 3", color: "green", systemId: "sys3", polylineCoordinates: [], updatedTime: Date.now() }, ]; } export function generateMockStops(): IStop[] { return [ - { id: "st1", name: "Stop A", systemId: "sys1", coordinates: { latitude: 10, longitude: 20 }, updatedTimeMs: Date.now() }, - { id: "st2", name: "Stop B", systemId: "sys2", coordinates: { latitude: 15, longitude: 25 }, updatedTimeMs: Date.now() }, - { id: "st3", name: "Stop C", systemId: "sys3", coordinates: { latitude: 30, longitude: 40 }, updatedTimeMs: Date.now() }, + { id: "st1", name: "Stop A", systemId: "sys1", coordinates: { latitude: 10, longitude: 20 }, updatedTime: Date.now() }, + { id: "st2", name: "Stop B", systemId: "sys2", coordinates: { latitude: 15, longitude: 25 }, updatedTime: Date.now() }, + { id: "st3", name: "Stop C", systemId: "sys3", coordinates: { latitude: 30, longitude: 40 }, updatedTime: Date.now() }, ]; } export function generateMockOrderedStops(): IOrderedStop[] { return [ - { stopId: "st1", routeId: "r1", position: 1, systemId: "sys1", updatedTimeMs: Date.now(), }, - { stopId: "st1", routeId: "r2", position: 2, systemId: "sys1", updatedTimeMs: Date.now(), }, - { stopId: "st2", routeId: "r1", position: 3, systemId: "sys1", updatedTimeMs: Date.now(), }, - { stopId: "st2", routeId: "r2", position: 4, systemId: "sys1", updatedTimeMs: Date.now(), }, + { stopId: "st1", routeId: "r1", position: 1, systemId: "sys1", updatedTime: Date.now(), }, + { stopId: "st1", routeId: "r2", position: 2, systemId: "sys1", updatedTime: Date.now(), }, + { stopId: "st2", routeId: "r1", position: 3, systemId: "sys1", updatedTime: Date.now(), }, + { stopId: "st2", routeId: "r2", position: 4, systemId: "sys1", updatedTime: Date.now(), }, ]; } export function generateMockEtas(): IEta[] { return [ - { shuttleId: "sh1", stopId: "st1", secondsRemaining: 120, systemId: "sys1", updatedTimeMs: Date.now() }, - { shuttleId: "sh1", stopId: "st2", secondsRemaining: 180, systemId: "sys1", updatedTimeMs: Date.now() }, - { shuttleId: "sh2", stopId: "st3", secondsRemaining: 240, systemId: "sys1", updatedTimeMs: Date.now() }, + { shuttleId: "sh1", stopId: "st1", secondsRemaining: 120, systemId: "sys1", updatedTime: Date.now() }, + { shuttleId: "sh1", stopId: "st2", secondsRemaining: 180, systemId: "sys1", updatedTime: Date.now() }, + { shuttleId: "sh2", stopId: "st3", secondsRemaining: 240, systemId: "sys1", updatedTime: Date.now() }, ]; } From 1c7ee9fbc369576c093f2c2b8f23fe5cc776c653 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Tue, 29 Apr 2025 17:05:23 -0700 Subject: [PATCH 16/17] change all millisecond references into Dates --- .../ChapmanApiBasedParkingRepositoryLoader.ts | 2 +- src/loaders/parking/loadParkingTestData.ts | 4 +-- .../ApiBasedShuttleRepositoryLoader.ts | 14 ++++---- src/loaders/shuttle/loadShuttleTestData.ts | 32 ++++++++--------- src/resolvers/RouteResolvers.ts | 6 ++-- ...iBasedParkingRepositoryLoaderTests.test.ts | 4 +-- .../ETANotificationSchedulerTests.test.ts | 2 +- .../InMemoryParkingRepositoryTests.test.ts | 2 +- test/testHelpers/mockDataGenerators.ts | 36 +++++++++---------- 9 files changed, 51 insertions(+), 51 deletions(-) diff --git a/src/loaders/parking/ChapmanApiBasedParkingRepositoryLoader.ts b/src/loaders/parking/ChapmanApiBasedParkingRepositoryLoader.ts index 1c08a06..5cfafea 100644 --- a/src/loaders/parking/ChapmanApiBasedParkingRepositoryLoader.ts +++ b/src/loaders/parking/ChapmanApiBasedParkingRepositoryLoader.ts @@ -59,7 +59,7 @@ export class ChapmanApiBasedParkingRepositoryLoader implements ParkingRepository name: jsonStructure.Name, spotsAvailable: jsonStructure.CurrentCount > jsonStructure.Capacity ? jsonStructure.Capacity : jsonStructure.CurrentCount, address: jsonStructure.Address, - updatedTime: Date.now(), + updatedTime: new Date(), } return structureToReturn; diff --git a/src/loaders/parking/loadParkingTestData.ts b/src/loaders/parking/loadParkingTestData.ts index d117ab8..be7663d 100644 --- a/src/loaders/parking/loadParkingTestData.ts +++ b/src/loaders/parking/loadParkingTestData.ts @@ -12,7 +12,7 @@ const parkingStructures: IParkingStructure[] = [ }, name: "Anderson Structure", id: "1", - updatedTime: Date.now(), + updatedTime: new Date(), }, { address: "200 W Sycamore Ave, Orange, CA 92866-1053", @@ -24,7 +24,7 @@ const parkingStructures: IParkingStructure[] = [ }, name: "Barrera", id: "2", - updatedTime: Date.now(), + updatedTime: new Date(), } ]; diff --git a/src/loaders/shuttle/ApiBasedShuttleRepositoryLoader.ts b/src/loaders/shuttle/ApiBasedShuttleRepositoryLoader.ts index 95cbdc2..c7735aa 100644 --- a/src/loaders/shuttle/ApiBasedShuttleRepositoryLoader.ts +++ b/src/loaders/shuttle/ApiBasedShuttleRepositoryLoader.ts @@ -73,7 +73,7 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader id: jsonRoute.myid, polylineCoordinates: [], systemId: this.systemIdForConstructedData, - updatedTime: Date.now(), + updatedTime: new Date(), }; await this.repository.addOrUpdateRoute(constructedRoute); @@ -174,7 +174,7 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader systemId: this.systemIdForConstructedData, id: `${jsonBus.busId}`, orientationInDegrees: parseFloat(jsonBus.calculatedCourse), - updatedTime: Date.now(), + updatedTime: new Date(), } await this.repository.addOrUpdateShuttle(constructedShuttle); @@ -223,7 +223,7 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader secondsRemaining: jsonEta.secondsSpent, shuttleId: `${shuttleId}`, stopId: stopId, - updatedTime: Date.now(), + updatedTime: new Date(), systemId: this.systemIdForConstructedData, }; @@ -251,7 +251,7 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader latitude: parseFloat(stop.latitude), longitude: parseFloat(stop.longitude), }, - updatedTime: Date.now(), + updatedTime: new Date(), }; await this.repository.addOrUpdateStop(constructedStop); @@ -283,7 +283,7 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader stopId, position: index + 1, systemId: this.systemIdForConstructedData, - updatedTime: Date.now(), + updatedTime: new Date(), }; } @@ -293,7 +293,7 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader stopId: jsonOrderedStopData[index - 1][1], position: index, systemId: this.systemIdForConstructedData, - updatedTime: Date.now(), + updatedTime: new Date(), }; } if (index < jsonOrderedStopData.length - 1) { @@ -302,7 +302,7 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader stopId: jsonOrderedStopData[index + 1][1], position: index + 2, systemId: this.systemIdForConstructedData, - updatedTime: Date.now(), + updatedTime: new Date(), }; } diff --git a/src/loaders/shuttle/loadShuttleTestData.ts b/src/loaders/shuttle/loadShuttleTestData.ts index 5b52402..782962d 100644 --- a/src/loaders/shuttle/loadShuttleTestData.ts +++ b/src/loaders/shuttle/loadShuttleTestData.ts @@ -4324,7 +4324,7 @@ const routes: IRoute[] = [ systemId: supportedIntegrationTestSystems[0].id, polylineCoordinates: redRoutePolylineCoordinates, color: "#db2316", - updatedTime: Date.now(), + updatedTime: new Date(), }, { name: "Teal Route", @@ -4332,7 +4332,7 @@ const routes: IRoute[] = [ systemId: supportedIntegrationTestSystems[0].id, polylineCoordinates: tealRoutePolylineCoordinates, color: "#21bdd1", - updatedTime: Date.now(), + updatedTime: new Date(), }, ]; @@ -4345,7 +4345,7 @@ const stops: IStop[] = [ longitude: -117.8892805, }, systemId: supportedIntegrationTestSystems[0].id, - updatedTime: Date.now(), + updatedTime: new Date(), }, { id: "2", @@ -4355,7 +4355,7 @@ const stops: IStop[] = [ longitude: -117.895966, }, systemId: supportedIntegrationTestSystems[0].id, - updatedTime: Date.now(), + updatedTime: new Date(), }, { id: "3", @@ -4365,7 +4365,7 @@ const stops: IStop[] = [ "longitude": -117.85281 }, systemId: supportedIntegrationTestSystems[0].id, - updatedTime: Date.now(), + updatedTime: new Date(), } ]; @@ -4375,14 +4375,14 @@ const orderedStopsForRedRoute: IOrderedStop[] = [ stopId: stops[0].id, position: 1, systemId: "1", - updatedTime: Date.now(), + updatedTime: new Date(), }, { routeId: routes[0].id, stopId: stops[2].id, position: 2, systemId: "1", - updatedTime: Date.now(), + updatedTime: new Date(), }, ]; @@ -4392,21 +4392,21 @@ const orderedStopsForTealRoute: IOrderedStop[] = [ stopId: stops[0].id, position: 1, systemId: supportedIntegrationTestSystems[0].id, - updatedTime: Date.now(), + updatedTime: new Date(), }, { routeId: routes[1].id, stopId: stops[1].id, position: 2, systemId: supportedIntegrationTestSystems[0].id, - updatedTime: Date.now(), + updatedTime: new Date(), }, { routeId: routes[1].id, stopId: stops[2].id, position: 2, systemId: supportedIntegrationTestSystems[0].id, - updatedTime: Date.now(), + updatedTime: new Date(), }, ] @@ -4426,7 +4426,7 @@ const shuttles: IShuttle[] = [ routeId: routes[0].id, systemId: supportedIntegrationTestSystems[0].id, orientationInDegrees: 45.91, - updatedTime: Date.now(), + updatedTime: new Date(), }, { name: "24", @@ -4438,7 +4438,7 @@ const shuttles: IShuttle[] = [ routeId: routes[0].id, systemId: supportedIntegrationTestSystems[0].id, orientationInDegrees: 90.24, - updatedTime: Date.now(), + updatedTime: new Date(), } ]; @@ -4448,28 +4448,28 @@ const etas: IEta[] = [ shuttleId: shuttles[0].id, secondsRemaining: 12.023, systemId: supportedIntegrationTestSystems[0].id, - updatedTime: Date.now(), + updatedTime: new Date(), }, { stopId: stops[2].id, shuttleId: shuttles[0].id, secondsRemaining: 600.123, systemId: supportedIntegrationTestSystems[0].id, - updatedTime: Date.now(), + updatedTime: new Date(), }, { stopId: stops[2].id, shuttleId: shuttles[1].id, secondsRemaining: 172.015, systemId: supportedIntegrationTestSystems[0].id, - updatedTime: Date.now(), + updatedTime: new Date(), }, { stopId: stops[0].id, shuttleId: shuttles[1].id, secondsRemaining: 710.152, systemId: supportedIntegrationTestSystems[0].id, - updatedTime: Date.now(), + updatedTime: new Date(), } ]; diff --git a/src/resolvers/RouteResolvers.ts b/src/resolvers/RouteResolvers.ts index d24e992..43f6c53 100644 --- a/src/resolvers/RouteResolvers.ts +++ b/src/resolvers/RouteResolvers.ts @@ -3,7 +3,7 @@ import { ServerContext } from "../ServerContext"; export const RouteResolvers: Resolvers = { Route: { - shuttles: async (parent, args, contextValue, info) => { + shuttles: async (parent, args, contextValue, _info) => { const system = contextValue.findSystemById(parent.systemId); if (!system) return null; @@ -23,10 +23,10 @@ export const RouteResolvers: Resolvers = { id, orientationInDegrees, systemId: parent.systemId, - updatedTime: updatedTimeMs, + updatedTime, })); }, - orderedStop: async (parent, args, contextValue, info) => { + orderedStop: async (parent, args, contextValue, _info) => { if (!args.forStopId) return null; const system = contextValue.findSystemById(parent.systemId); diff --git a/test/loaders/parking/ChapmanApiBasedParkingRepositoryLoaderTests.test.ts b/test/loaders/parking/ChapmanApiBasedParkingRepositoryLoaderTests.test.ts index 02012bb..ecd6a12 100644 --- a/test/loaders/parking/ChapmanApiBasedParkingRepositoryLoaderTests.test.ts +++ b/test/loaders/parking/ChapmanApiBasedParkingRepositoryLoaderTests.test.ts @@ -59,7 +59,7 @@ describe("ChapmanApiBasedParkingRepositoryLoader", () => { }, name: "Anderson Structure", id: "", - updatedTime: Date.now(), + updatedTime: new Date(), }, { address: "200 W Sycamore Ave, Orange, CA 92866-1053", @@ -71,7 +71,7 @@ describe("ChapmanApiBasedParkingRepositoryLoader", () => { }, name: "Barrera", id: "", - updatedTime: Date.now(), + updatedTime: new Date(), } ]; expectedStructures[0].id = ChapmanApiBasedParkingRepositoryLoader.generateId(expectedStructures[0].address); diff --git a/test/notifications/schedulers/ETANotificationSchedulerTests.test.ts b/test/notifications/schedulers/ETANotificationSchedulerTests.test.ts index 229dc22..1c5b819 100644 --- a/test/notifications/schedulers/ETANotificationSchedulerTests.test.ts +++ b/test/notifications/schedulers/ETANotificationSchedulerTests.test.ts @@ -52,7 +52,7 @@ describe("ETANotificationScheduler", () => { stopId: stop.id, secondsRemaining: 120, systemId: "1", - updatedTime: Date.now(), + updatedTime: new Date(), }; const notificationData1 = { diff --git a/test/repositories/InMemoryParkingRepositoryTests.test.ts b/test/repositories/InMemoryParkingRepositoryTests.test.ts index ece527b..d358d14 100644 --- a/test/repositories/InMemoryParkingRepositoryTests.test.ts +++ b/test/repositories/InMemoryParkingRepositoryTests.test.ts @@ -14,7 +14,7 @@ describe("InMemoryParkingRepository", () => { name: "Anderson Parking Structure", capacity: 100, address: "300 E Walnut Ave, Orange, CA 92867", - updatedTime: Date.now(), + updatedTime: new Date(), }; beforeEach(() => { diff --git a/test/testHelpers/mockDataGenerators.ts b/test/testHelpers/mockDataGenerators.ts index 7e237e8..dea9037 100644 --- a/test/testHelpers/mockDataGenerators.ts +++ b/test/testHelpers/mockDataGenerators.ts @@ -17,7 +17,7 @@ export function generateParkingStructures(): IParkingStructure[] { "name": "Anderson Structure", "spotsAvailable": 163, "address": "300 E Walnut, Orange, CA 92867", - updatedTime: Date.now(), + updatedTime: new Date(), }, { "capacity": 692, @@ -29,7 +29,7 @@ export function generateParkingStructures(): IParkingStructure[] { "name": "Barrera", "spotsAvailable": 179, "address": "200 W Sycamore Ave, Orange, CA 92866-1053", - updatedTime: Date.now(), + updatedTime: new Date(), } ]; } @@ -46,7 +46,7 @@ export function generateMockShuttles(): IShuttle[] { longitude: 20 }, orientationInDegrees: 25.163, - updatedTime: Date.now(), + updatedTime: new Date(), }, { id: "sh2", @@ -58,7 +58,7 @@ export function generateMockShuttles(): IShuttle[] { longitude: 25 }, orientationInDegrees: 50.912, - updatedTime: Date.now(), + updatedTime: new Date(), }, { id: "sh3", @@ -70,40 +70,40 @@ export function generateMockShuttles(): IShuttle[] { longitude: 40 }, orientationInDegrees: 321.019, - updatedTime: Date.now(), + updatedTime: new Date(), }, ]; } export function generateMockRoutes(): IRoute[] { return [ - { id: "r1", name: "Route 1", color: "red", systemId: "sys1", polylineCoordinates: [], updatedTime: Date.now() }, - { id: "r2", name: "Route 2", color: "blue", systemId: "sys2", polylineCoordinates: [], updatedTime: Date.now() }, - { id: "r3", name: "Route 3", color: "green", systemId: "sys3", polylineCoordinates: [], updatedTime: Date.now() }, + { id: "r1", name: "Route 1", color: "red", systemId: "sys1", polylineCoordinates: [], updatedTime: new Date() }, + { id: "r2", name: "Route 2", color: "blue", systemId: "sys2", polylineCoordinates: [], updatedTime: new Date() }, + { id: "r3", name: "Route 3", color: "green", systemId: "sys3", polylineCoordinates: [], updatedTime: new Date() }, ]; } export function generateMockStops(): IStop[] { return [ - { id: "st1", name: "Stop A", systemId: "sys1", coordinates: { latitude: 10, longitude: 20 }, updatedTime: Date.now() }, - { id: "st2", name: "Stop B", systemId: "sys2", coordinates: { latitude: 15, longitude: 25 }, updatedTime: Date.now() }, - { id: "st3", name: "Stop C", systemId: "sys3", coordinates: { latitude: 30, longitude: 40 }, updatedTime: Date.now() }, + { id: "st1", name: "Stop A", systemId: "sys1", coordinates: { latitude: 10, longitude: 20 }, updatedTime: new Date() }, + { id: "st2", name: "Stop B", systemId: "sys2", coordinates: { latitude: 15, longitude: 25 }, updatedTime: new Date() }, + { id: "st3", name: "Stop C", systemId: "sys3", coordinates: { latitude: 30, longitude: 40 }, updatedTime: new Date() }, ]; } export function generateMockOrderedStops(): IOrderedStop[] { return [ - { stopId: "st1", routeId: "r1", position: 1, systemId: "sys1", updatedTime: Date.now(), }, - { stopId: "st1", routeId: "r2", position: 2, systemId: "sys1", updatedTime: Date.now(), }, - { stopId: "st2", routeId: "r1", position: 3, systemId: "sys1", updatedTime: Date.now(), }, - { stopId: "st2", routeId: "r2", position: 4, systemId: "sys1", updatedTime: Date.now(), }, + { stopId: "st1", routeId: "r1", position: 1, systemId: "sys1", updatedTime: new Date(), }, + { stopId: "st1", routeId: "r2", position: 2, systemId: "sys1", updatedTime: new Date(), }, + { stopId: "st2", routeId: "r1", position: 3, systemId: "sys1", updatedTime: new Date(), }, + { stopId: "st2", routeId: "r2", position: 4, systemId: "sys1", updatedTime: new Date(), }, ]; } export function generateMockEtas(): IEta[] { return [ - { shuttleId: "sh1", stopId: "st1", secondsRemaining: 120, systemId: "sys1", updatedTime: Date.now() }, - { shuttleId: "sh1", stopId: "st2", secondsRemaining: 180, systemId: "sys1", updatedTime: Date.now() }, - { shuttleId: "sh2", stopId: "st3", secondsRemaining: 240, systemId: "sys1", updatedTime: Date.now() }, + { shuttleId: "sh1", stopId: "st1", secondsRemaining: 120, systemId: "sys1", updatedTime: new Date() }, + { shuttleId: "sh1", stopId: "st2", secondsRemaining: 180, systemId: "sys1", updatedTime: new Date() }, + { shuttleId: "sh2", stopId: "st3", secondsRemaining: 240, systemId: "sys1", updatedTime: new Date() }, ]; } From a7c33c9479e210f49382849660ec935e73b6e4cf Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Tue, 29 Apr 2025 17:21:17 -0700 Subject: [PATCH 17/17] empty commit to fix actions? --- .../ParkingSystemResolverTests.test.ts | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/test/resolvers/ParkingSystemResolverTests.test.ts b/test/resolvers/ParkingSystemResolverTests.test.ts index c207536..951e2c2 100644 --- a/test/resolvers/ParkingSystemResolverTests.test.ts +++ b/test/resolvers/ParkingSystemResolverTests.test.ts @@ -4,6 +4,7 @@ import { setupTestServerContext, setupTestServerHolder } from "../testHelpers/ap import { InterchangeSystem } from "../../src/entities/InterchangeSystem"; import assert = require("node:assert"); + describe("ParkingSystemResolver", () => { const holder = setupTestServerHolder(); const context = setupTestServerContext(); @@ -48,24 +49,26 @@ describe("ParkingSystemResolver", () => { ` it("gets parking structures associated with the system id", async () => { - const expectedParkingStructures = generateParkingStructures(); + let expectedParkingStructures = generateParkingStructures(); await Promise.all(expectedParkingStructures.map(async (structure) => { await context.systems[0].parkingRepository?.addOrUpdateParkingStructure(structure); })); + // Dates are transformed into epoch timestamps when serialized + expectedParkingStructures = expectedParkingStructures.map((structure) => { + const newStructure = { ...structure }; + // @ts-ignore + newStructure.updatedTime = newStructure.updatedTime.getTime(); + return newStructure; + }); + const response = await getResponseFromQueryNeedingSystemId(query); assert(response.body.kind === "single"); expect(response.body.singleResult.errors).toBeUndefined(); const parkingStructures = (response.body.singleResult.data as any).system.parkingSystem.parkingStructures; - const transformedParkingStructures = parkingStructures.map((structure: any) => { - const newStructure = { ...structure, updatedTimeMs: structure.updatedTime }; - delete newStructure.updatedTime; - return newStructure; - }); - - expect(transformedParkingStructures).toEqual(expectedParkingStructures); + expect(parkingStructures).toEqual(expectedParkingStructures); }); it("returns a blank array if there are no parking structures", async () => { @@ -122,6 +125,8 @@ describe("ParkingSystemResolver", () => { await context.systems[0].parkingRepository?.addOrUpdateParkingStructure(structure); })); const expectedParkingStructure = generatedParkingStructures[1]; + // @ts-ignore + expectedParkingStructure.updatedTime = expectedParkingStructure.updatedTime.getTime(); const response = await getResponseForParkingStructureQuery(expectedParkingStructure.id); @@ -129,8 +134,6 @@ describe("ParkingSystemResolver", () => { expect(response.body.singleResult.errors).toBeUndefined(); const parkingStructure = (response.body.singleResult.data as any).system.parkingSystem.parkingStructure; - parkingStructure.updatedTimeMs = parkingStructure.updatedTime; - delete parkingStructure.updatedTime; expect(parkingStructure).toEqual(expectedParkingStructure); });