@transportme/load-ptv-gtfs 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -96,7 +96,14 @@ export default class StopsLoader {
96
96
  }
97
97
 
98
98
  async mergeStops(matchingStop, stopData) {
99
- matchingStop.bays.push(stopData.bays[0])
99
+ let newBay = stopData.bays[0]
100
+ let hasIdenticalBay = matchingStop.bays.some(bay =>
101
+ bay.mode === newBay.mode && bay.stopGTFSID === newBay.stopGTFSID
102
+ )
103
+
104
+ if (hasIdenticalBay) return
105
+
106
+ matchingStop.bays.push(newBay)
100
107
 
101
108
  this.updateStopSuburb(matchingStop)
102
109
  this.updateStopName(matchingStop)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transportme/load-ptv-gtfs",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "",
5
5
  "main": "index.mjs",
6
6
  "scripts": {
@@ -220,4 +220,74 @@ describe('The GTFS Stops Loader', () => {
220
220
  expect(huntingdale).to.not.be.null
221
221
  expect(huntingdale.stopName).to.equal('Huntingdale Railway Station')
222
222
  })
223
+
224
+ it('Should not load duplicate stops with the same mode in', async () => {
225
+ let database = new LokiDatabaseConnection('test-db')
226
+ let stops = await database.createCollection('stops')
227
+
228
+ let loader = new StopsLoader(specialHeader, suburbs, TRANSIT_MODES.bus, database)
229
+ let reader = new GTFSStopsReader('')
230
+
231
+ await loader.loadStop(reader.processEntity({
232
+ stop_id: '51586',
233
+ stop_name: 'Huntingdale Station/Haughton Road (Oakleigh)',
234
+ stop_lat: '-37.9111998619901',
235
+ stop_lon: '145.103064853799'
236
+ }))
237
+
238
+ let huntingdale = await stops.findDocument({
239
+ 'bays.stopGTFSID': '51586'
240
+ })
241
+ expect(huntingdale.bays.length).to.equal(1)
242
+ expect(huntingdale.bays[0].stopGTFSID).to.equal('51586')
243
+
244
+ await loader.loadStop(reader.processEntity({
245
+ stop_id: '51586',
246
+ stop_name: 'Huntingdale Station/Haughton Road (Oakleigh)',
247
+ stop_lat: '-37.9111998619901',
248
+ stop_lon: '145.103064853799'
249
+ }))
250
+
251
+ huntingdale = await stops.findDocument({
252
+ 'bays.stopGTFSID': '51586'
253
+ })
254
+ expect(huntingdale.bays.length).to.equal(1)
255
+ })
256
+
257
+ it('Should load duplicate stops with the different mode in', async () => {
258
+ let database = new LokiDatabaseConnection('test-db')
259
+ let stops = await database.createCollection('stops')
260
+
261
+ let busLoader = new StopsLoader(specialHeader, suburbs, TRANSIT_MODES.bus, database)
262
+ let coachLoader = new StopsLoader(specialHeader, suburbs, TRANSIT_MODES.regionalCoach, database)
263
+ let reader = new GTFSStopsReader('')
264
+
265
+ await busLoader.loadStop(reader.processEntity({
266
+ stop_id: '51586',
267
+ stop_name: 'Huntingdale Station/Haughton Road (Oakleigh)',
268
+ stop_lat: '-37.9111998619901',
269
+ stop_lon: '145.103064853799'
270
+ }))
271
+
272
+ let huntingdale = await stops.findDocument({
273
+ 'bays.stopGTFSID': '51586'
274
+ })
275
+ expect(huntingdale.bays.length).to.equal(1)
276
+ expect(huntingdale.bays[0].stopGTFSID).to.equal('51586')
277
+ expect(huntingdale.bays[0].mode).to.equal(TRANSIT_MODES.bus)
278
+
279
+ await coachLoader.loadStop(reader.processEntity({
280
+ stop_id: '51586',
281
+ stop_name: 'Huntingdale Station/Haughton Road (Oakleigh)',
282
+ stop_lat: '-37.9111998619901',
283
+ stop_lon: '145.103064853799'
284
+ }))
285
+
286
+ huntingdale = await stops.findDocument({
287
+ 'bays.stopGTFSID': '51586'
288
+ })
289
+ expect(huntingdale.bays.length).to.equal(2)
290
+ expect(huntingdale.bays[1].stopGTFSID).to.equal('51586')
291
+ expect(huntingdale.bays[1].mode).to.equal(TRANSIT_MODES.regionalCoach)
292
+ })
223
293
  })