diff --git a/lib/Gtfsrt2LC.js b/lib/Gtfsrt2LC.js index 30225ed..552af8e 100644 --- a/lib/Gtfsrt2LC.js +++ b/lib/Gtfsrt2LC.js @@ -150,14 +150,14 @@ class Gtfsrt2LC { // Check if this is a new update based on recorded Connections history (if any) // and skip it if is not new. - if (this.historyDB && !(await this.differentiaUpdate({ + if (this.historyDB && !(await this.differentialUpdate({ route: r, trip: t, stopTimes: st, - cu, - ncu: completedUpdates[j + 1], + cu: await this.getStop(cu.stopId), + ncu: await this.getStop(completedUpdates[j + 1].stopId), pdIndex, - startTime: tripUpdate.trip.startTime, + startTime: format(tripStartTime, 'H:mm:ss'), startDate, departureDelay, arrivalDelay, @@ -626,7 +626,7 @@ class Gtfsrt2LC { return update; } - async differentiaUpdate(params) { + async differentialUpdate(params) { const { route, trip, @@ -642,11 +642,16 @@ class Gtfsrt2LC { } = params; // Build Connection's original rule as in gtfs2lc + const depStopId = cu['stop_code'] && cu['stop_code'] !== '' ? + cu['stop_code'] : cu['stop_id']; + const arrStopId = ncu['stop_code'] && ncu['stop_code'] !== '' ? + ncu['stop_code'] : ncu['stop_id']; + const uniqueId = [ route['route_long_name'].replace(/\s/g, ''), trip['trip_short_name'], - cu['stopId'], - ncu['stopId'], + depStopId, + arrStopId, startTime, stopTimes[pdIndex]['departure_time'], stopTimes[pdIndex + 1]['arrival_time'], diff --git a/package-lock.json b/package-lock.json index a58921f..cebcfb9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "gtfsrt2lc", - "version": "2.0.2", + "version": "2.0.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "gtfsrt2lc", - "version": "2.0.2", + "version": "2.0.3", "license": "MIT", "dependencies": { "commander": "^5.0.0", diff --git a/package.json b/package.json index effb649..b5e22d4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gtfsrt2lc", - "version": "2.0.2", + "version": "2.0.3", "description": "Converts the GTFS-RT to Linked Connections", "main": "./Gtfsrt2LC.js", "bin": { diff --git a/test/gtfsrt2lc.test.js b/test/gtfsrt2lc.test.js index 3c13c90..b8d63cc 100644 --- a/test/gtfsrt2lc.test.js +++ b/test/gtfsrt2lc.test.js @@ -582,4 +582,19 @@ test('Cover GtfsIndex functions', async () => { try { await gti.getIndexes(); } catch (err) { } +}); + +test('Cover Gtfsrt2LC functions', async () => { + grt = new Gtfsrt2lc({ path: rt_path, uris: mock_uris, headers: {} }); + // Test for resolveScheduleRelationship + const notAvailable = grt.resolveScheduleRelationship(1, 1); + const mustPhone = grt.resolveScheduleRelationship(0, 2); + const mustCoordinate = grt.resolveScheduleRelationship(0, 3); + // Test for getting headers + const headers = grt.headers; + + expect(notAvailable).toBe('gtfs:NotAvailable'); + expect(mustPhone).toBe('gtfs:MustPhone'); + expect(mustCoordinate).toBe('gtfs:MustCoordinateWithDriver'); + expect(headers).toBeDefined(); }); \ No newline at end of file