gtfs 3.1.1 → 3.2.0

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.
Files changed (111) hide show
  1. package/.eslintrc.json +14 -19
  2. package/.husky/pre-commit +4 -0
  3. package/@types/index.d.ts +269 -0
  4. package/@types/tests.ts +26 -0
  5. package/@types/tsconfig.json +17 -0
  6. package/CHANGELOG.md +182 -1
  7. package/README.md +168 -149
  8. package/bin/gtfs-export.js +4 -5
  9. package/bin/gtfs-import.js +6 -7
  10. package/config-sample-full.json +2 -7
  11. package/docs/images/node-gtfs-logo.svg +18 -0
  12. package/lib/db.js +63 -12
  13. package/lib/export.js +27 -13
  14. package/lib/file-utils.js +26 -9
  15. package/lib/geojson-utils.js +51 -38
  16. package/lib/gtfs/agencies.js +15 -4
  17. package/lib/gtfs/attributions.js +15 -4
  18. package/lib/gtfs/calendar-dates.js +15 -4
  19. package/lib/gtfs/calendars.js +15 -4
  20. package/lib/gtfs/fare-attributes.js +15 -4
  21. package/lib/gtfs/fare-rules.js +15 -4
  22. package/lib/gtfs/feed-info.js +15 -4
  23. package/lib/gtfs/frequencies.js +15 -4
  24. package/lib/gtfs/levels.js +15 -4
  25. package/lib/gtfs/pathways.js +15 -4
  26. package/lib/gtfs/routes.js +22 -6
  27. package/lib/gtfs/shapes.js +59 -23
  28. package/lib/gtfs/stop-times.js +15 -4
  29. package/lib/gtfs/stops.js +57 -23
  30. package/lib/gtfs/transfers.js +15 -4
  31. package/lib/gtfs/translations.js +15 -4
  32. package/lib/gtfs/trips.js +15 -4
  33. package/lib/gtfs-ride/board-alights.js +15 -4
  34. package/lib/gtfs-ride/ride-feed-infos.js +15 -4
  35. package/lib/gtfs-ride/rider-trips.js +15 -4
  36. package/lib/gtfs-ride/riderships.js +15 -4
  37. package/lib/gtfs-ride/trip-capacities.js +15 -4
  38. package/lib/import.js +203 -128
  39. package/lib/log-utils.js +8 -4
  40. package/lib/non-standard/directions.js +15 -4
  41. package/lib/non-standard/stop-attributes.js +15 -4
  42. package/lib/non-standard/timetable-notes-references.js +15 -4
  43. package/lib/non-standard/timetable-notes.js +15 -4
  44. package/lib/non-standard/timetable-pages.js +15 -4
  45. package/lib/non-standard/timetable-stop-order.js +15 -4
  46. package/lib/non-standard/timetables.js +15 -4
  47. package/lib/utils.js +26 -12
  48. package/models/gtfs/agency.js +11 -11
  49. package/models/gtfs/attributions.js +14 -14
  50. package/models/gtfs/calendar-dates.js +7 -7
  51. package/models/gtfs/calendar.js +12 -12
  52. package/models/gtfs/fare-attributes.js +9 -9
  53. package/models/gtfs/fare-rules.js +8 -8
  54. package/models/gtfs/feed-info.js +12 -12
  55. package/models/gtfs/frequencies.js +10 -10
  56. package/models/gtfs/levels.js +5 -5
  57. package/models/gtfs/pathways.js +14 -14
  58. package/models/gtfs/routes.js +14 -14
  59. package/models/gtfs/shapes.js +8 -8
  60. package/models/gtfs/stop-times.js +17 -17
  61. package/models/gtfs/stops.js +17 -17
  62. package/models/gtfs/transfers.js +7 -7
  63. package/models/gtfs/translations.js +10 -10
  64. package/models/gtfs/trips.js +12 -12
  65. package/models/gtfs-ride/board-alight.js +24 -24
  66. package/models/gtfs-ride/ride-feed-info.js +8 -8
  67. package/models/gtfs-ride/rider-trip.js +21 -21
  68. package/models/gtfs-ride/ridership.js +23 -23
  69. package/models/gtfs-ride/trip-capacity.js +10 -10
  70. package/models/models.js +1 -1
  71. package/models/non-standard/directions.js +6 -6
  72. package/models/non-standard/stop-attributes.js +5 -5
  73. package/models/non-standard/timetable-notes-references.js +9 -9
  74. package/models/non-standard/timetable-notes.js +5 -5
  75. package/models/non-standard/timetable-pages.js +5 -5
  76. package/models/non-standard/timetable-stop-order.js +6 -6
  77. package/models/non-standard/timetables.js +27 -27
  78. package/package.json +35 -13
  79. package/test/mocha/export-gtfs.js +74 -44
  80. package/test/mocha/get-agencies.js +20 -14
  81. package/test/mocha/get-attributions.js +10 -4
  82. package/test/mocha/get-board-alights.js +10 -4
  83. package/test/mocha/get-calendar-dates.js +31 -24
  84. package/test/mocha/get-calendars.js +17 -11
  85. package/test/mocha/get-db.js +71 -5
  86. package/test/mocha/get-directions.js +10 -4
  87. package/test/mocha/get-fare-attributes.js +12 -6
  88. package/test/mocha/get-fare-rules.js +17 -13
  89. package/test/mocha/get-feed-info.js +10 -4
  90. package/test/mocha/get-frequencies.js +10 -4
  91. package/test/mocha/get-levels.js +4 -4
  92. package/test/mocha/get-pathways.js +10 -4
  93. package/test/mocha/get-ride-feed-infos.js +9 -3
  94. package/test/mocha/get-rider-trips.js +10 -4
  95. package/test/mocha/get-riderships.js +10 -4
  96. package/test/mocha/get-routes.js +12 -16
  97. package/test/mocha/get-shapes-as-geojson.js +12 -6
  98. package/test/mocha/get-shapes.js +31 -39
  99. package/test/mocha/get-stop-attributes.js +10 -4
  100. package/test/mocha/get-stops-as-geojson.js +11 -5
  101. package/test/mocha/get-stops.js +62 -51
  102. package/test/mocha/get-stoptimes.js +18 -10
  103. package/test/mocha/get-timetable-pages.js +10 -4
  104. package/test/mocha/get-timetable-stop-orders.js +10 -4
  105. package/test/mocha/get-timetables.js +10 -4
  106. package/test/mocha/get-transfers.js +10 -4
  107. package/test/mocha/get-translations.js +10 -4
  108. package/test/mocha/get-trip-capacities.js +10 -4
  109. package/test/mocha/get-trips.js +6 -6
  110. package/test/mocha/import-gtfs.js +63 -46
  111. package/test/test-config.js +9 -4
@@ -2,9 +2,14 @@
2
2
 
3
3
  import should from 'should';
4
4
 
5
- import { openDb, closeDb } from '../../lib/db.js';
6
5
  import config from '../test-config.js';
7
- import { importGtfs, getCalendarDates } from '../../index.js';
6
+ import {
7
+ openDb,
8
+ getDb,
9
+ closeDb,
10
+ importGtfs,
11
+ getCalendarDates,
12
+ } from '../../index.js';
8
13
 
9
14
  describe('getCalendarDates():', () => {
10
15
  before(async () => {
@@ -13,14 +18,15 @@ describe('getCalendarDates():', () => {
13
18
  });
14
19
 
15
20
  after(async () => {
16
- await closeDb();
21
+ const db = getDb(config);
22
+ await closeDb(db);
17
23
  });
18
24
 
19
25
  it('should return empty array if no calendar dates exist', async () => {
20
26
  const serviceId = 'fake-service-id';
21
27
 
22
28
  const results = await getCalendarDates({
23
- service_id: serviceId
29
+ service_id: serviceId,
24
30
  });
25
31
  should.exists(results);
26
32
  results.should.have.length(0);
@@ -30,7 +36,7 @@ describe('getCalendarDates():', () => {
30
36
  const serviceId = 'CT-16APR-Caltrain-Weekday-01';
31
37
 
32
38
  const results = await getCalendarDates({
33
- service_id: serviceId
39
+ service_id: serviceId,
34
40
  });
35
41
 
36
42
  should.exists(results);
@@ -42,29 +48,29 @@ describe('getCalendarDates():', () => {
42
48
  service_id: 'CT-16APR-Caltrain-Weekday-01',
43
49
  date: 20161124,
44
50
  exception_type: 2,
45
- holiday_name: null
51
+ holiday_name: null,
46
52
  },
47
53
  {
48
54
  id: 4,
49
55
  service_id: 'CT-16APR-Caltrain-Weekday-01',
50
56
  date: 20160905,
51
57
  exception_type: 2,
52
- holiday_name: null
58
+ holiday_name: null,
53
59
  },
54
60
  {
55
61
  id: 6,
56
62
  service_id: 'CT-16APR-Caltrain-Weekday-01',
57
63
  date: 20160704,
58
64
  exception_type: 2,
59
- holiday_name: null
65
+ holiday_name: null,
60
66
  },
61
67
  {
62
68
  id: 8,
63
69
  service_id: 'CT-16APR-Caltrain-Weekday-01',
64
70
  date: 20160530,
65
71
  exception_type: 2,
66
- holiday_name: null
67
- }
72
+ holiday_name: null,
73
+ },
68
74
  ];
69
75
 
70
76
  for (const result of results) {
@@ -75,33 +81,34 @@ describe('getCalendarDates():', () => {
75
81
  it('should return only specific keys for expected calendar dates, sorted by date', async () => {
76
82
  const serviceId = 'CT-16APR-Caltrain-Weekday-01';
77
83
 
78
- const results = await getCalendarDates({
79
- service_id: serviceId
80
- }, [
81
- 'service_id',
82
- 'date'
83
- ], [
84
- ['date', 'ASC'],
85
- ['service_id', 'ASC']
86
- ]);
84
+ const results = await getCalendarDates(
85
+ {
86
+ service_id: serviceId,
87
+ },
88
+ ['service_id', 'date'],
89
+ [
90
+ ['date', 'ASC'],
91
+ ['service_id', 'ASC'],
92
+ ]
93
+ );
87
94
 
88
95
  const expectedResults = [
89
96
  {
90
97
  service_id: 'CT-16APR-Caltrain-Weekday-01',
91
- date: 20160530
98
+ date: 20160530,
92
99
  },
93
100
  {
94
101
  service_id: 'CT-16APR-Caltrain-Weekday-01',
95
- date: 20160704
102
+ date: 20160704,
96
103
  },
97
104
  {
98
105
  service_id: 'CT-16APR-Caltrain-Weekday-01',
99
- date: 20160905
106
+ date: 20160905,
100
107
  },
101
108
  {
102
109
  service_id: 'CT-16APR-Caltrain-Weekday-01',
103
- date: 20161124
104
- }
110
+ date: 20161124,
111
+ },
105
112
  ];
106
113
 
107
114
  results.length.should.equal(4);
@@ -2,9 +2,14 @@
2
2
 
3
3
  import should from 'should';
4
4
 
5
- import { openDb, closeDb } from '../../lib/db.js';
6
5
  import config from '../test-config.js';
7
- import { importGtfs, getCalendars } from '../../index.js';
6
+ import {
7
+ openDb,
8
+ getDb,
9
+ closeDb,
10
+ importGtfs,
11
+ getCalendars,
12
+ } from '../../index.js';
8
13
 
9
14
  describe('getCalendars():', () => {
10
15
  before(async () => {
@@ -13,14 +18,15 @@ describe('getCalendars():', () => {
13
18
  });
14
19
 
15
20
  after(async () => {
16
- await closeDb();
21
+ const db = getDb(config);
22
+ await closeDb(db);
17
23
  });
18
24
 
19
25
  it('should return empty array if no calendars', async () => {
20
26
  const serviceId = 'fake-service-id';
21
27
 
22
28
  const results = await getCalendars({
23
- service_id: serviceId
29
+ service_id: serviceId,
24
30
  });
25
31
  should.exists(results);
26
32
  results.should.have.length(0);
@@ -28,7 +34,7 @@ describe('getCalendars():', () => {
28
34
 
29
35
  it('should return expected calendars by day', async () => {
30
36
  const results = await getCalendars({
31
- sunday: 1
37
+ sunday: 1,
32
38
  });
33
39
 
34
40
  const expectedResult = {
@@ -41,7 +47,7 @@ describe('getCalendars():', () => {
41
47
  saturday: 0,
42
48
  sunday: 1,
43
49
  start_date: 20140323,
44
- end_date: 20190331
50
+ end_date: 20190331,
45
51
  };
46
52
 
47
53
  should.exist(results);
@@ -53,8 +59,8 @@ describe('getCalendars():', () => {
53
59
  const results = await getCalendars({
54
60
  service_id: [
55
61
  'CT-16APR-Caltrain-Saturday-02',
56
- 'CT-16APR-Caltrain-Sunday-02'
57
- ]
62
+ 'CT-16APR-Caltrain-Sunday-02',
63
+ ],
58
64
  });
59
65
 
60
66
  const expectedResults = [
@@ -68,7 +74,7 @@ describe('getCalendars():', () => {
68
74
  saturday: 1,
69
75
  sunday: 0,
70
76
  start_date: 20140329,
71
- end_date: 20190331
77
+ end_date: 20190331,
72
78
  },
73
79
  {
74
80
  service_id: 'CT-16APR-Caltrain-Sunday-02',
@@ -80,8 +86,8 @@ describe('getCalendars():', () => {
80
86
  saturday: 0,
81
87
  sunday: 1,
82
88
  start_date: 20140323,
83
- end_date: 20190331
84
- }
89
+ end_date: 20190331,
90
+ },
85
91
  ];
86
92
 
87
93
  should.exist(results);
@@ -1,10 +1,21 @@
1
1
  /* eslint-env mocha */
2
2
 
3
3
  import should from 'should';
4
+ import fs from 'fs';
4
5
 
5
- import { openDb, closeDb } from '../../lib/db.js';
6
6
  import config from '../test-config.js';
7
- import { importGtfs, getDb } from '../../index.js';
7
+ import { openDb, getDb, closeDb, importGtfs, getShapes } from '../../index.js';
8
+
9
+ const db2Config = {
10
+ ...config,
11
+ agencies: [
12
+ {
13
+ ...config.agencies[0],
14
+ exclude: ['shapes'],
15
+ },
16
+ ],
17
+ sqlitePath: './tmpdb',
18
+ };
8
19
 
9
20
  describe('getDb():', () => {
10
21
  before(async () => {
@@ -13,13 +24,23 @@ describe('getDb():', () => {
13
24
  });
14
25
 
15
26
  after(async () => {
16
- await closeDb();
27
+ const db = getDb(config);
28
+ await closeDb(db);
29
+
30
+ // Close db2 and then delete it
31
+ const db2 = getDb(db2Config);
32
+ await closeDb(db2);
33
+ fs.unlinkSync(db2Config.sqlitePath);
17
34
  });
18
35
 
19
36
  it('should allow raw db queries: calendar_dates', async () => {
20
37
  const serviceIds = ['CT-16APR-Caltrain-Weekday-01'];
21
38
  const db = getDb();
22
- const results = await db.all(`SELECT * FROM calendar_dates WHERE exception_type = 1 AND service_id NOT IN (${serviceIds.map(serviceId => `'${serviceId}'`).join(', ')})`);
39
+ const results = await db.all(
40
+ `SELECT * FROM calendar_dates WHERE exception_type = 1 AND service_id NOT IN (${serviceIds
41
+ .map((serviceId) => `'${serviceId}'`)
42
+ .join(', ')})`
43
+ );
23
44
 
24
45
  should.exists(results);
25
46
  results.should.have.length(4);
@@ -30,8 +51,53 @@ describe('getDb():', () => {
30
51
  const startStopId = '70261';
31
52
  const endStopId = '70131';
32
53
  const db = getDb();
33
- const results = await db.all('SELECT * from trips where trips.trip_id IN (SELECT start_stop_times.trip_id FROM stop_times as start_stop_times WHERE stop_id = ? AND start_stop_times.stop_sequence < (SELECT end_stop_times.stop_sequence FROM stop_times as end_stop_times WHERE end_stop_times.stop_sequence > start_stop_times.stop_sequence AND end_stop_times.trip_id = start_stop_times.trip_id AND end_stop_times.stop_id = ? ))', [startStopId, endStopId]);
54
+ const results = await db.all(
55
+ 'SELECT * from trips where trips.trip_id IN (SELECT start_stop_times.trip_id FROM stop_times as start_stop_times WHERE stop_id = ? AND start_stop_times.stop_sequence < (SELECT end_stop_times.stop_sequence FROM stop_times as end_stop_times WHERE end_stop_times.stop_sequence > start_stop_times.stop_sequence AND end_stop_times.trip_id = start_stop_times.trip_id AND end_stop_times.stop_id = ? ))',
56
+ [startStopId, endStopId]
57
+ );
34
58
  should.exists(results);
35
59
  results.should.have.length(62);
36
60
  });
61
+
62
+ it('should allow multiple db connections', async () => {
63
+ const db2 = await openDb(db2Config);
64
+ await importGtfs(db2Config);
65
+
66
+ const db1 = getDb(config);
67
+
68
+ db1.config.filename.should.equal(':memory:');
69
+ db2.config.filename.should.equal('./tmpdb');
70
+
71
+ // Query db1 for shapes
72
+ const shapeId = 'cal_sf_tam';
73
+ const results1 = await getShapes({
74
+ shape_id: shapeId,
75
+ });
76
+
77
+ const expectedResult = {
78
+ id: 1424,
79
+ shape_id: 'cal_sf_tam',
80
+ shape_pt_lat: 37.45375587083584,
81
+ shape_pt_lon: -122.18063950538635,
82
+ shape_pt_sequence: 279,
83
+ shape_dist_traveled: null,
84
+ };
85
+
86
+ should.exist(results1);
87
+ results1.length.should.equal(401);
88
+ results1.should.containEql(expectedResult);
89
+
90
+ // Query db2 for shapes, none should exist
91
+ const results2 = await getShapes(
92
+ {
93
+ shape_id: shapeId,
94
+ },
95
+ [],
96
+ [],
97
+ { db: db2 }
98
+ );
99
+
100
+ should.exist(results2);
101
+ results2.length.should.equal(0);
102
+ });
37
103
  });
@@ -2,9 +2,14 @@
2
2
 
3
3
  import should from 'should';
4
4
 
5
- import { openDb, closeDb } from '../../lib/db.js';
6
5
  import config from '../test-config.js';
7
- import { importGtfs, getDirections } from '../../index.js';
6
+ import {
7
+ openDb,
8
+ getDb,
9
+ closeDb,
10
+ importGtfs,
11
+ getDirections,
12
+ } from '../../index.js';
8
13
 
9
14
  describe('getDirections():', () => {
10
15
  before(async () => {
@@ -13,14 +18,15 @@ describe('getDirections():', () => {
13
18
  });
14
19
 
15
20
  after(async () => {
16
- await closeDb();
21
+ const db = getDb(config);
22
+ await closeDb(db);
17
23
  });
18
24
 
19
25
  it('should return empty array if no directions', async () => {
20
26
  const fareRouteId = 'not_real';
21
27
 
22
28
  const results = await getDirections({
23
- route_id: fareRouteId
29
+ route_id: fareRouteId,
24
30
  });
25
31
  should.exists(results);
26
32
  results.should.have.length(0);
@@ -2,9 +2,14 @@
2
2
 
3
3
  import should from 'should';
4
4
 
5
- import { openDb, closeDb } from '../../lib/db.js';
6
5
  import config from '../test-config.js';
7
- import { importGtfs, getFareAttributes } from '../../index.js';
6
+ import {
7
+ openDb,
8
+ getDb,
9
+ closeDb,
10
+ importGtfs,
11
+ getFareAttributes,
12
+ } from '../../index.js';
8
13
 
9
14
  describe('getFareAttributes():', () => {
10
15
  before(async () => {
@@ -13,14 +18,15 @@ describe('getFareAttributes():', () => {
13
18
  });
14
19
 
15
20
  after(async () => {
16
- await closeDb();
21
+ const db = getDb(config);
22
+ await closeDb(db);
17
23
  });
18
24
 
19
25
  it('should return empty array if no fare_attributes', async () => {
20
26
  const fareId = 'not_real';
21
27
 
22
28
  const results = await getFareAttributes({
23
- fare_id: fareId
29
+ fare_id: fareId,
24
30
  });
25
31
 
26
32
  should.exists(results);
@@ -31,7 +37,7 @@ describe('getFareAttributes():', () => {
31
37
  const fareId = 'OW_1_20160228';
32
38
 
33
39
  const results = await getFareAttributes({
34
- fare_id: fareId
40
+ fare_id: fareId,
35
41
  });
36
42
 
37
43
  const expectedResult = {
@@ -41,7 +47,7 @@ describe('getFareAttributes():', () => {
41
47
  payment_method: 1,
42
48
  transfers: 0,
43
49
  agency_id: null,
44
- transfer_duration: null
50
+ transfer_duration: null,
45
51
  };
46
52
 
47
53
  should.exist(results);
@@ -2,9 +2,14 @@
2
2
 
3
3
  import should from 'should';
4
4
 
5
- import { openDb, closeDb } from '../../lib/db.js';
6
5
  import config from '../test-config.js';
7
- import { importGtfs, getFareRules } from '../../index.js';
6
+ import {
7
+ openDb,
8
+ getDb,
9
+ closeDb,
10
+ importGtfs,
11
+ getFareRules,
12
+ } from '../../index.js';
8
13
 
9
14
  describe('getFareRules():', () => {
10
15
  before(async () => {
@@ -13,14 +18,15 @@ describe('getFareRules():', () => {
13
18
  });
14
19
 
15
20
  after(async () => {
16
- await closeDb();
21
+ const db = getDb(config);
22
+ await closeDb(db);
17
23
  });
18
24
 
19
25
  it('should return empty array if no fare_rules', async () => {
20
26
  const routeId = 'not_real';
21
27
 
22
28
  const results = await getFareRules({
23
- route_id: routeId
29
+ route_id: routeId,
24
30
  });
25
31
  should.exists(results);
26
32
  results.should.have.length(0);
@@ -29,20 +35,18 @@ describe('getFareRules():', () => {
29
35
  it('should return expected fare_rules', async () => {
30
36
  const routeId = 'Bu-16APR';
31
37
 
32
- const results = await getFareRules({
33
- route_id: routeId
34
- }, [
35
- 'fare_id',
36
- 'route_id',
37
- 'origin_id',
38
- 'destination_id'
39
- ]);
38
+ const results = await getFareRules(
39
+ {
40
+ route_id: routeId,
41
+ },
42
+ ['fare_id', 'route_id', 'origin_id', 'destination_id']
43
+ );
40
44
 
41
45
  const expectedResult = {
42
46
  fare_id: 'OW_2_20160228',
43
47
  route_id: 'Bu-16APR',
44
48
  origin_id: '6',
45
- destination_id: '5'
49
+ destination_id: '5',
46
50
  };
47
51
 
48
52
  should.exist(results);
@@ -2,9 +2,14 @@
2
2
 
3
3
  import should from 'should';
4
4
 
5
- import { openDb, closeDb } from '../../lib/db.js';
6
5
  import config from '../test-config.js';
7
- import { importGtfs, getFeedInfo } from '../../index.js';
6
+ import {
7
+ openDb,
8
+ getDb,
9
+ closeDb,
10
+ importGtfs,
11
+ getFeedInfo,
12
+ } from '../../index.js';
8
13
 
9
14
  describe('getFeedInfo():', () => {
10
15
  before(async () => {
@@ -13,14 +18,15 @@ describe('getFeedInfo():', () => {
13
18
  });
14
19
 
15
20
  after(async () => {
16
- await closeDb();
21
+ const db = getDb(config);
22
+ await closeDb(db);
17
23
  });
18
24
 
19
25
  it('should return empty array if no feed info', async () => {
20
26
  const feedPublisherName = 'not_real';
21
27
 
22
28
  const results = await getFeedInfo({
23
- feed_publisher_name: feedPublisherName
29
+ feed_publisher_name: feedPublisherName,
24
30
  });
25
31
  should.exists(results);
26
32
  results.should.have.length(0);
@@ -2,9 +2,14 @@
2
2
 
3
3
  import should from 'should';
4
4
 
5
- import { openDb, closeDb } from '../../lib/db.js';
6
5
  import config from '../test-config.js';
7
- import { importGtfs, getFrequencies } from '../../index.js';
6
+ import {
7
+ openDb,
8
+ getDb,
9
+ closeDb,
10
+ importGtfs,
11
+ getFrequencies,
12
+ } from '../../index.js';
8
13
 
9
14
  describe('getFrequencies():', () => {
10
15
  before(async () => {
@@ -13,14 +18,15 @@ describe('getFrequencies():', () => {
13
18
  });
14
19
 
15
20
  after(async () => {
16
- await closeDb();
21
+ const db = getDb(config);
22
+ await closeDb(db);
17
23
  });
18
24
 
19
25
  it('should return empty array if no frequencies', async () => {
20
26
  const tripId = 'not_real';
21
27
 
22
28
  const results = await getFrequencies({
23
- trip_id: tripId
29
+ trip_id: tripId,
24
30
  });
25
31
  should.exists(results);
26
32
  results.should.have.length(0);
@@ -2,9 +2,8 @@
2
2
 
3
3
  import should from 'should';
4
4
 
5
- import { openDb, closeDb } from '../../lib/db.js';
6
5
  import config from '../test-config.js';
7
- import { importGtfs, getLevels } from '../../index.js';
6
+ import { openDb, getDb, closeDb, importGtfs, getLevels } from '../../index.js';
8
7
 
9
8
  describe('getLevels():', () => {
10
9
  before(async () => {
@@ -13,14 +12,15 @@ describe('getLevels():', () => {
13
12
  });
14
13
 
15
14
  after(async () => {
16
- await closeDb();
15
+ const db = getDb(config);
16
+ await closeDb(db);
17
17
  });
18
18
 
19
19
  it('should return empty array if no levels', async () => {
20
20
  const levelId = 'not_real';
21
21
 
22
22
  const results = await getLevels({
23
- level_id: levelId
23
+ level_id: levelId,
24
24
  });
25
25
  should.exists(results);
26
26
  results.should.have.length(0);
@@ -2,9 +2,14 @@
2
2
 
3
3
  import should from 'should';
4
4
 
5
- import { openDb, closeDb } from '../../lib/db.js';
6
5
  import config from '../test-config.js';
7
- import { importGtfs, getPathways } from '../../index.js';
6
+ import {
7
+ openDb,
8
+ getDb,
9
+ closeDb,
10
+ importGtfs,
11
+ getPathways,
12
+ } from '../../index.js';
8
13
 
9
14
  describe('getPathways():', () => {
10
15
  before(async () => {
@@ -13,14 +18,15 @@ describe('getPathways():', () => {
13
18
  });
14
19
 
15
20
  after(async () => {
16
- await closeDb();
21
+ const db = getDb(config);
22
+ await closeDb(db);
17
23
  });
18
24
 
19
25
  it('should return empty array if no pathways', async () => {
20
26
  const pathwayId = 'not_real';
21
27
 
22
28
  const results = await getPathways({
23
- pathway_id: pathwayId
29
+ pathway_id: pathwayId,
24
30
  });
25
31
  should.exists(results);
26
32
  results.should.have.length(0);
@@ -2,9 +2,14 @@
2
2
 
3
3
  import should from 'should';
4
4
 
5
- import { openDb, closeDb } from '../../lib/db.js';
6
5
  import config from '../test-config.js';
7
- import { importGtfs, getRideFeedInfos } from '../../index.js';
6
+ import {
7
+ openDb,
8
+ getDb,
9
+ closeDb,
10
+ importGtfs,
11
+ getRideFeedInfos,
12
+ } from '../../index.js';
8
13
 
9
14
  describe('getRideFeedInfos():', () => {
10
15
  before(async () => {
@@ -13,7 +18,8 @@ describe('getRideFeedInfos():', () => {
13
18
  });
14
19
 
15
20
  after(async () => {
16
- await closeDb();
21
+ const db = getDb(config);
22
+ await closeDb(db);
17
23
  });
18
24
 
19
25
  it('should return empty array if no ride-feed-infos (GTFS-ride)', async () => {
@@ -2,9 +2,14 @@
2
2
 
3
3
  import should from 'should';
4
4
 
5
- import { openDb, closeDb } from '../../lib/db.js';
6
5
  import config from '../test-config.js';
7
- import { importGtfs, getRiderTrips } from '../../index.js';
6
+ import {
7
+ openDb,
8
+ getDb,
9
+ closeDb,
10
+ importGtfs,
11
+ getRiderTrips,
12
+ } from '../../index.js';
8
13
 
9
14
  describe('getRiderTrips():', () => {
10
15
  before(async () => {
@@ -13,14 +18,15 @@ describe('getRiderTrips():', () => {
13
18
  });
14
19
 
15
20
  after(async () => {
16
- await closeDb();
21
+ const db = getDb(config);
22
+ await closeDb(db);
17
23
  });
18
24
 
19
25
  it('should return empty array if no rider trips (GTFS-ride)', async () => {
20
26
  const tripId = 'fake-trip-id';
21
27
 
22
28
  const results = await getRiderTrips({
23
- trip_id: tripId
29
+ trip_id: tripId,
24
30
  });
25
31
  should.exists(results);
26
32
  results.should.have.length(0);