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.
- package/.eslintrc.json +14 -19
- package/.husky/pre-commit +4 -0
- package/@types/index.d.ts +269 -0
- package/@types/tests.ts +26 -0
- package/@types/tsconfig.json +17 -0
- package/CHANGELOG.md +182 -1
- package/README.md +168 -149
- package/bin/gtfs-export.js +4 -5
- package/bin/gtfs-import.js +6 -7
- package/config-sample-full.json +2 -7
- package/docs/images/node-gtfs-logo.svg +18 -0
- package/lib/db.js +63 -12
- package/lib/export.js +27 -13
- package/lib/file-utils.js +26 -9
- package/lib/geojson-utils.js +51 -38
- package/lib/gtfs/agencies.js +15 -4
- package/lib/gtfs/attributions.js +15 -4
- package/lib/gtfs/calendar-dates.js +15 -4
- package/lib/gtfs/calendars.js +15 -4
- package/lib/gtfs/fare-attributes.js +15 -4
- package/lib/gtfs/fare-rules.js +15 -4
- package/lib/gtfs/feed-info.js +15 -4
- package/lib/gtfs/frequencies.js +15 -4
- package/lib/gtfs/levels.js +15 -4
- package/lib/gtfs/pathways.js +15 -4
- package/lib/gtfs/routes.js +22 -6
- package/lib/gtfs/shapes.js +59 -23
- package/lib/gtfs/stop-times.js +15 -4
- package/lib/gtfs/stops.js +57 -23
- package/lib/gtfs/transfers.js +15 -4
- package/lib/gtfs/translations.js +15 -4
- package/lib/gtfs/trips.js +15 -4
- package/lib/gtfs-ride/board-alights.js +15 -4
- package/lib/gtfs-ride/ride-feed-infos.js +15 -4
- package/lib/gtfs-ride/rider-trips.js +15 -4
- package/lib/gtfs-ride/riderships.js +15 -4
- package/lib/gtfs-ride/trip-capacities.js +15 -4
- package/lib/import.js +203 -128
- package/lib/log-utils.js +8 -4
- package/lib/non-standard/directions.js +15 -4
- package/lib/non-standard/stop-attributes.js +15 -4
- package/lib/non-standard/timetable-notes-references.js +15 -4
- package/lib/non-standard/timetable-notes.js +15 -4
- package/lib/non-standard/timetable-pages.js +15 -4
- package/lib/non-standard/timetable-stop-order.js +15 -4
- package/lib/non-standard/timetables.js +15 -4
- package/lib/utils.js +26 -12
- package/models/gtfs/agency.js +11 -11
- package/models/gtfs/attributions.js +14 -14
- package/models/gtfs/calendar-dates.js +7 -7
- package/models/gtfs/calendar.js +12 -12
- package/models/gtfs/fare-attributes.js +9 -9
- package/models/gtfs/fare-rules.js +8 -8
- package/models/gtfs/feed-info.js +12 -12
- package/models/gtfs/frequencies.js +10 -10
- package/models/gtfs/levels.js +5 -5
- package/models/gtfs/pathways.js +14 -14
- package/models/gtfs/routes.js +14 -14
- package/models/gtfs/shapes.js +8 -8
- package/models/gtfs/stop-times.js +17 -17
- package/models/gtfs/stops.js +17 -17
- package/models/gtfs/transfers.js +7 -7
- package/models/gtfs/translations.js +10 -10
- package/models/gtfs/trips.js +12 -12
- package/models/gtfs-ride/board-alight.js +24 -24
- package/models/gtfs-ride/ride-feed-info.js +8 -8
- package/models/gtfs-ride/rider-trip.js +21 -21
- package/models/gtfs-ride/ridership.js +23 -23
- package/models/gtfs-ride/trip-capacity.js +10 -10
- package/models/models.js +1 -1
- package/models/non-standard/directions.js +6 -6
- package/models/non-standard/stop-attributes.js +5 -5
- package/models/non-standard/timetable-notes-references.js +9 -9
- package/models/non-standard/timetable-notes.js +5 -5
- package/models/non-standard/timetable-pages.js +5 -5
- package/models/non-standard/timetable-stop-order.js +6 -6
- package/models/non-standard/timetables.js +27 -27
- package/package.json +35 -13
- package/test/mocha/export-gtfs.js +74 -44
- package/test/mocha/get-agencies.js +20 -14
- package/test/mocha/get-attributions.js +10 -4
- package/test/mocha/get-board-alights.js +10 -4
- package/test/mocha/get-calendar-dates.js +31 -24
- package/test/mocha/get-calendars.js +17 -11
- package/test/mocha/get-db.js +71 -5
- package/test/mocha/get-directions.js +10 -4
- package/test/mocha/get-fare-attributes.js +12 -6
- package/test/mocha/get-fare-rules.js +17 -13
- package/test/mocha/get-feed-info.js +10 -4
- package/test/mocha/get-frequencies.js +10 -4
- package/test/mocha/get-levels.js +4 -4
- package/test/mocha/get-pathways.js +10 -4
- package/test/mocha/get-ride-feed-infos.js +9 -3
- package/test/mocha/get-rider-trips.js +10 -4
- package/test/mocha/get-riderships.js +10 -4
- package/test/mocha/get-routes.js +12 -16
- package/test/mocha/get-shapes-as-geojson.js +12 -6
- package/test/mocha/get-shapes.js +31 -39
- package/test/mocha/get-stop-attributes.js +10 -4
- package/test/mocha/get-stops-as-geojson.js +11 -5
- package/test/mocha/get-stops.js +62 -51
- package/test/mocha/get-stoptimes.js +18 -10
- package/test/mocha/get-timetable-pages.js +10 -4
- package/test/mocha/get-timetable-stop-orders.js +10 -4
- package/test/mocha/get-timetables.js +10 -4
- package/test/mocha/get-transfers.js +10 -4
- package/test/mocha/get-translations.js +10 -4
- package/test/mocha/get-trip-capacities.js +10 -4
- package/test/mocha/get-trips.js +6 -6
- package/test/mocha/import-gtfs.js +63 -46
- 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 {
|
|
6
|
+
import {
|
|
7
|
+
openDb,
|
|
8
|
+
getDb,
|
|
9
|
+
closeDb,
|
|
10
|
+
importGtfs,
|
|
11
|
+
getRiderships,
|
|
12
|
+
} from '../../index.js';
|
|
8
13
|
|
|
9
14
|
describe('getRiderships():', () => {
|
|
10
15
|
before(async () => {
|
|
@@ -13,14 +18,15 @@ describe('getRiderships():', () => {
|
|
|
13
18
|
});
|
|
14
19
|
|
|
15
20
|
after(async () => {
|
|
16
|
-
|
|
21
|
+
const db = getDb(config);
|
|
22
|
+
await closeDb(db);
|
|
17
23
|
});
|
|
18
24
|
|
|
19
25
|
it('should return empty array if no riderships (GTFS-ride)', async () => {
|
|
20
26
|
const routeId = 'fake-route-id';
|
|
21
27
|
|
|
22
28
|
const results = await getRiderships({
|
|
23
|
-
route_id: routeId
|
|
29
|
+
route_id: routeId,
|
|
24
30
|
});
|
|
25
31
|
should.exists(results);
|
|
26
32
|
results.should.have.length(0);
|
package/test/mocha/get-routes.js
CHANGED
|
@@ -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, getRoutes } from '../../index.js';
|
|
6
|
+
import { openDb, getDb, closeDb, importGtfs, getRoutes } from '../../index.js';
|
|
8
7
|
|
|
9
8
|
describe('getRoutes():', () => {
|
|
10
9
|
before(async () => {
|
|
@@ -13,25 +12,22 @@ describe('getRoutes():', () => {
|
|
|
13
12
|
});
|
|
14
13
|
|
|
15
14
|
after(async () => {
|
|
16
|
-
|
|
15
|
+
const db = getDb(config);
|
|
16
|
+
await closeDb(db);
|
|
17
17
|
});
|
|
18
18
|
|
|
19
19
|
it('should return empty array if no routes for given agency exist', async () => {
|
|
20
20
|
const routeId = 'fake-route-id';
|
|
21
21
|
|
|
22
22
|
const results = await getRoutes({
|
|
23
|
-
route_id: routeId
|
|
23
|
+
route_id: routeId,
|
|
24
24
|
});
|
|
25
25
|
should.exists(results);
|
|
26
26
|
results.should.have.length(0);
|
|
27
27
|
});
|
|
28
28
|
|
|
29
29
|
it('should return expected routes', async () => {
|
|
30
|
-
const results = await getRoutes(
|
|
31
|
-
{},
|
|
32
|
-
[],
|
|
33
|
-
[['route_long_name', 'ASC']]
|
|
34
|
-
);
|
|
30
|
+
const results = await getRoutes({}, [], [['route_long_name', 'ASC']]);
|
|
35
31
|
|
|
36
32
|
const expectedResults = [
|
|
37
33
|
{
|
|
@@ -46,7 +42,7 @@ describe('getRoutes():', () => {
|
|
|
46
42
|
route_text_color: null,
|
|
47
43
|
route_sort_order: null,
|
|
48
44
|
continuous_pickup: null,
|
|
49
|
-
continuous_drop_off: null
|
|
45
|
+
continuous_drop_off: null,
|
|
50
46
|
},
|
|
51
47
|
{
|
|
52
48
|
route_id: 'Li-16APR',
|
|
@@ -60,7 +56,7 @@ describe('getRoutes():', () => {
|
|
|
60
56
|
route_text_color: null,
|
|
61
57
|
route_sort_order: null,
|
|
62
58
|
continuous_pickup: null,
|
|
63
|
-
continuous_drop_off: null
|
|
59
|
+
continuous_drop_off: null,
|
|
64
60
|
},
|
|
65
61
|
{
|
|
66
62
|
route_id: 'Lo-16APR',
|
|
@@ -74,7 +70,7 @@ describe('getRoutes():', () => {
|
|
|
74
70
|
route_text_color: null,
|
|
75
71
|
route_sort_order: null,
|
|
76
72
|
continuous_pickup: null,
|
|
77
|
-
continuous_drop_off: null
|
|
73
|
+
continuous_drop_off: null,
|
|
78
74
|
},
|
|
79
75
|
{
|
|
80
76
|
route_id: 'TaSj-16APR',
|
|
@@ -88,8 +84,8 @@ describe('getRoutes():', () => {
|
|
|
88
84
|
route_text_color: null,
|
|
89
85
|
route_sort_order: null,
|
|
90
86
|
continuous_pickup: null,
|
|
91
|
-
continuous_drop_off: null
|
|
92
|
-
}
|
|
87
|
+
continuous_drop_off: null,
|
|
88
|
+
},
|
|
93
89
|
];
|
|
94
90
|
|
|
95
91
|
should.exist(results);
|
|
@@ -117,8 +113,8 @@ describe('getRoutes():', () => {
|
|
|
117
113
|
route_text_color: null,
|
|
118
114
|
route_sort_order: null,
|
|
119
115
|
continuous_pickup: null,
|
|
120
|
-
continuous_drop_off: null
|
|
121
|
-
}
|
|
116
|
+
continuous_drop_off: null,
|
|
117
|
+
},
|
|
122
118
|
];
|
|
123
119
|
|
|
124
120
|
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 {
|
|
6
|
+
import {
|
|
7
|
+
openDb,
|
|
8
|
+
getDb,
|
|
9
|
+
closeDb,
|
|
10
|
+
importGtfs,
|
|
11
|
+
getShapesAsGeoJSON,
|
|
12
|
+
} from '../../index.js';
|
|
8
13
|
|
|
9
14
|
describe('getShapesAsGeoJSON():', () => {
|
|
10
15
|
before(async () => {
|
|
@@ -13,13 +18,14 @@ describe('getShapesAsGeoJSON():', () => {
|
|
|
13
18
|
});
|
|
14
19
|
|
|
15
20
|
after(async () => {
|
|
16
|
-
|
|
21
|
+
const db = getDb(config);
|
|
22
|
+
await closeDb(db);
|
|
17
23
|
});
|
|
18
24
|
|
|
19
25
|
it('should return geojson with an empty features array if no shapes exist', async () => {
|
|
20
26
|
const shapeId = 'fake-shape-id';
|
|
21
27
|
const geojson = await getShapesAsGeoJSON({
|
|
22
|
-
shape_id: shapeId
|
|
28
|
+
shape_id: shapeId,
|
|
23
29
|
});
|
|
24
30
|
|
|
25
31
|
should.exist(geojson);
|
|
@@ -42,7 +48,7 @@ describe('getShapesAsGeoJSON():', () => {
|
|
|
42
48
|
const routeId = 'Lo-16APR';
|
|
43
49
|
|
|
44
50
|
const geojson = await getShapesAsGeoJSON({
|
|
45
|
-
route_id: routeId
|
|
51
|
+
route_id: routeId,
|
|
46
52
|
});
|
|
47
53
|
|
|
48
54
|
should.exist(geojson);
|
|
@@ -59,7 +65,7 @@ describe('getShapesAsGeoJSON():', () => {
|
|
|
59
65
|
|
|
60
66
|
const geojson = await getShapesAsGeoJSON({
|
|
61
67
|
route_id: routeId,
|
|
62
|
-
direction_id: directionId
|
|
68
|
+
direction_id: directionId,
|
|
63
69
|
});
|
|
64
70
|
|
|
65
71
|
should.exist(geojson);
|
package/test/mocha/get-shapes.js
CHANGED
|
@@ -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, getShapes } from '../../index.js';
|
|
6
|
+
import { openDb, getDb, closeDb, importGtfs, getShapes } from '../../index.js';
|
|
8
7
|
|
|
9
8
|
describe('getShapes():', () => {
|
|
10
9
|
before(async () => {
|
|
@@ -13,14 +12,15 @@ describe('getShapes():', () => {
|
|
|
13
12
|
});
|
|
14
13
|
|
|
15
14
|
after(async () => {
|
|
16
|
-
|
|
15
|
+
const db = getDb(config);
|
|
16
|
+
await closeDb(db);
|
|
17
17
|
});
|
|
18
18
|
|
|
19
19
|
it('should return an empty array if no shapes exist', async () => {
|
|
20
20
|
const shapeId = 'fake-shape-id';
|
|
21
21
|
|
|
22
22
|
const results = await getShapes({
|
|
23
|
-
shape_id: shapeId
|
|
23
|
+
shape_id: shapeId,
|
|
24
24
|
});
|
|
25
25
|
should.exists(results);
|
|
26
26
|
results.should.have.length(0);
|
|
@@ -32,30 +32,27 @@ describe('getShapes():', () => {
|
|
|
32
32
|
|
|
33
33
|
const results = await getShapes({
|
|
34
34
|
route_id: routeId,
|
|
35
|
-
service_id: serviceId
|
|
35
|
+
service_id: serviceId,
|
|
36
36
|
});
|
|
37
37
|
should.exists(results);
|
|
38
38
|
results.should.have.length(0);
|
|
39
39
|
});
|
|
40
40
|
|
|
41
41
|
it('should return array of shapes', async () => {
|
|
42
|
-
const results = await getShapes(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
'shape_dist_traveled'
|
|
50
|
-
]
|
|
51
|
-
);
|
|
42
|
+
const results = await getShapes({}, [
|
|
43
|
+
'shape_id',
|
|
44
|
+
'shape_pt_lat',
|
|
45
|
+
'shape_pt_lon',
|
|
46
|
+
'shape_pt_sequence',
|
|
47
|
+
'shape_dist_traveled',
|
|
48
|
+
]);
|
|
52
49
|
|
|
53
50
|
const expectedResult = {
|
|
54
51
|
shape_id: 'cal_tam_sf',
|
|
55
52
|
shape_pt_lat: 37.607_687_113_495_64,
|
|
56
53
|
shape_pt_lon: -122.394_679_784_774_78,
|
|
57
54
|
shape_pt_sequence: 244,
|
|
58
|
-
shape_dist_traveled: null
|
|
55
|
+
shape_dist_traveled: null,
|
|
59
56
|
};
|
|
60
57
|
|
|
61
58
|
should.exist(results);
|
|
@@ -67,14 +64,14 @@ describe('getShapes():', () => {
|
|
|
67
64
|
const routeId = 'TaSj-16APR';
|
|
68
65
|
const results = await getShapes(
|
|
69
66
|
{
|
|
70
|
-
route_id: routeId
|
|
67
|
+
route_id: routeId,
|
|
71
68
|
},
|
|
72
69
|
[
|
|
73
70
|
'shape_id',
|
|
74
71
|
'shape_pt_lat',
|
|
75
72
|
'shape_pt_lon',
|
|
76
73
|
'shape_pt_sequence',
|
|
77
|
-
'shape_dist_traveled'
|
|
74
|
+
'shape_dist_traveled',
|
|
78
75
|
]
|
|
79
76
|
);
|
|
80
77
|
|
|
@@ -83,7 +80,7 @@ describe('getShapes():', () => {
|
|
|
83
80
|
shape_pt_lat: 37.323558,
|
|
84
81
|
shape_pt_lon: -121.8919,
|
|
85
82
|
shape_pt_sequence: 10051,
|
|
86
|
-
shape_dist_traveled: null
|
|
83
|
+
shape_dist_traveled: null,
|
|
87
84
|
};
|
|
88
85
|
|
|
89
86
|
should.exist(results);
|
|
@@ -94,17 +91,14 @@ describe('getShapes():', () => {
|
|
|
94
91
|
it('should return array of shapes for multiple routes', async () => {
|
|
95
92
|
const results = await getShapes(
|
|
96
93
|
{
|
|
97
|
-
route_id: [
|
|
98
|
-
'Lo-16APR',
|
|
99
|
-
'Li-16APR'
|
|
100
|
-
]
|
|
94
|
+
route_id: ['Lo-16APR', 'Li-16APR'],
|
|
101
95
|
},
|
|
102
96
|
[
|
|
103
97
|
'shape_id',
|
|
104
98
|
'shape_pt_lat',
|
|
105
99
|
'shape_pt_lon',
|
|
106
100
|
'shape_pt_sequence',
|
|
107
|
-
'shape_dist_traveled'
|
|
101
|
+
'shape_dist_traveled',
|
|
108
102
|
]
|
|
109
103
|
);
|
|
110
104
|
|
|
@@ -113,7 +107,7 @@ describe('getShapes():', () => {
|
|
|
113
107
|
shape_pt_lat: 37.694_407_548_683_614,
|
|
114
108
|
shape_pt_lon: -122.401_739_358_901_98,
|
|
115
109
|
shape_pt_sequence: 306,
|
|
116
|
-
shape_dist_traveled: null
|
|
110
|
+
shape_dist_traveled: null,
|
|
117
111
|
};
|
|
118
112
|
|
|
119
113
|
should.exist(results);
|
|
@@ -122,11 +116,9 @@ describe('getShapes():', () => {
|
|
|
122
116
|
});
|
|
123
117
|
|
|
124
118
|
it('should return empty array of for invalid route', async () => {
|
|
125
|
-
const results = await getShapes(
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
);
|
|
119
|
+
const results = await getShapes({
|
|
120
|
+
route_id: 'not-valid',
|
|
121
|
+
});
|
|
130
122
|
|
|
131
123
|
should.exist(results);
|
|
132
124
|
results.length.should.equal(0);
|
|
@@ -138,14 +130,14 @@ describe('getShapes():', () => {
|
|
|
138
130
|
const results = await getShapes(
|
|
139
131
|
{
|
|
140
132
|
route_id: routeId,
|
|
141
|
-
direction_id: directionId
|
|
133
|
+
direction_id: directionId,
|
|
142
134
|
},
|
|
143
135
|
[
|
|
144
136
|
'shape_id',
|
|
145
137
|
'shape_pt_lat',
|
|
146
138
|
'shape_pt_lon',
|
|
147
139
|
'shape_pt_sequence',
|
|
148
|
-
'shape_dist_traveled'
|
|
140
|
+
'shape_dist_traveled',
|
|
149
141
|
]
|
|
150
142
|
);
|
|
151
143
|
|
|
@@ -154,7 +146,7 @@ describe('getShapes():', () => {
|
|
|
154
146
|
shape_pt_lat: 37.323558,
|
|
155
147
|
shape_pt_lon: -121.8919,
|
|
156
148
|
shape_pt_sequence: 10051,
|
|
157
|
-
shape_dist_traveled: null
|
|
149
|
+
shape_dist_traveled: null,
|
|
158
150
|
};
|
|
159
151
|
|
|
160
152
|
should.exist(results);
|
|
@@ -166,14 +158,14 @@ describe('getShapes():', () => {
|
|
|
166
158
|
const tripId = '329';
|
|
167
159
|
const results = await getShapes(
|
|
168
160
|
{
|
|
169
|
-
trip_id: tripId
|
|
161
|
+
trip_id: tripId,
|
|
170
162
|
},
|
|
171
163
|
[
|
|
172
164
|
'shape_id',
|
|
173
165
|
'shape_pt_lat',
|
|
174
166
|
'shape_pt_lon',
|
|
175
167
|
'shape_pt_sequence',
|
|
176
|
-
'shape_dist_traveled'
|
|
168
|
+
'shape_dist_traveled',
|
|
177
169
|
]
|
|
178
170
|
);
|
|
179
171
|
|
|
@@ -182,7 +174,7 @@ describe('getShapes():', () => {
|
|
|
182
174
|
shape_pt_lat: 37.337_664_044_379_544,
|
|
183
175
|
shape_pt_lon: -121.908_105_611_801_15,
|
|
184
176
|
shape_pt_sequence: 25,
|
|
185
|
-
shape_dist_traveled: null
|
|
177
|
+
shape_dist_traveled: null,
|
|
186
178
|
};
|
|
187
179
|
|
|
188
180
|
should.exist(results);
|
|
@@ -194,14 +186,14 @@ describe('getShapes():', () => {
|
|
|
194
186
|
const serviceId = 'CT-16APR-Caltrain-Sunday-02';
|
|
195
187
|
const results = await getShapes(
|
|
196
188
|
{
|
|
197
|
-
service_id: serviceId
|
|
189
|
+
service_id: serviceId,
|
|
198
190
|
},
|
|
199
191
|
[
|
|
200
192
|
'shape_id',
|
|
201
193
|
'shape_pt_lat',
|
|
202
194
|
'shape_pt_lon',
|
|
203
195
|
'shape_pt_sequence',
|
|
204
|
-
'shape_dist_traveled'
|
|
196
|
+
'shape_dist_traveled',
|
|
205
197
|
]
|
|
206
198
|
);
|
|
207
199
|
|
|
@@ -210,7 +202,7 @@ describe('getShapes():', () => {
|
|
|
210
202
|
shape_pt_lat: 37.294079,
|
|
211
203
|
shape_pt_lon: -121.874108,
|
|
212
204
|
shape_pt_sequence: 10154,
|
|
213
|
-
shape_dist_traveled: null
|
|
205
|
+
shape_dist_traveled: null,
|
|
214
206
|
};
|
|
215
207
|
|
|
216
208
|
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 {
|
|
6
|
+
import {
|
|
7
|
+
openDb,
|
|
8
|
+
getDb,
|
|
9
|
+
closeDb,
|
|
10
|
+
importGtfs,
|
|
11
|
+
getStopAttributes,
|
|
12
|
+
} from '../../index.js';
|
|
8
13
|
|
|
9
14
|
describe('getStopAttributes():', () => {
|
|
10
15
|
before(async () => {
|
|
@@ -13,14 +18,15 @@ describe('getStopAttributes():', () => {
|
|
|
13
18
|
});
|
|
14
19
|
|
|
15
20
|
after(async () => {
|
|
16
|
-
|
|
21
|
+
const db = getDb(config);
|
|
22
|
+
await closeDb(db);
|
|
17
23
|
});
|
|
18
24
|
|
|
19
25
|
it('should return empty array if no stop attributes', async () => {
|
|
20
26
|
const stopId = 'fake-stop-id';
|
|
21
27
|
|
|
22
28
|
const results = await getStopAttributes({
|
|
23
|
-
stop_id: stopId
|
|
29
|
+
stop_id: stopId,
|
|
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 {
|
|
6
|
+
import {
|
|
7
|
+
openDb,
|
|
8
|
+
getDb,
|
|
9
|
+
closeDb,
|
|
10
|
+
importGtfs,
|
|
11
|
+
getStopsAsGeoJSON,
|
|
12
|
+
} from '../../index.js';
|
|
8
13
|
|
|
9
14
|
describe('getStopsAsGeoJSON(): ', () => {
|
|
10
15
|
before(async () => {
|
|
@@ -13,13 +18,14 @@ describe('getStopsAsGeoJSON(): ', () => {
|
|
|
13
18
|
});
|
|
14
19
|
|
|
15
20
|
after(async () => {
|
|
16
|
-
|
|
21
|
+
const db = getDb(config);
|
|
22
|
+
await closeDb(db);
|
|
17
23
|
});
|
|
18
24
|
|
|
19
25
|
it('should return geojson with an empty features array if no stops exist', async () => {
|
|
20
26
|
const stopId = 'fake-stop-id';
|
|
21
27
|
const geojson = await getStopsAsGeoJSON({
|
|
22
|
-
stop_id: stopId
|
|
28
|
+
stop_id: stopId,
|
|
23
29
|
});
|
|
24
30
|
|
|
25
31
|
should.exist(geojson);
|
|
@@ -41,7 +47,7 @@ describe('getStopsAsGeoJSON(): ', () => {
|
|
|
41
47
|
const stopId = '70031';
|
|
42
48
|
|
|
43
49
|
const geojson = await getStopsAsGeoJSON({
|
|
44
|
-
stop_id: stopId
|
|
50
|
+
stop_id: stopId,
|
|
45
51
|
});
|
|
46
52
|
|
|
47
53
|
should.exist(geojson);
|
package/test/mocha/get-stops.js
CHANGED
|
@@ -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, getStops } from '../../index.js';
|
|
6
|
+
import { openDb, getDb, closeDb, importGtfs, getStops } from '../../index.js';
|
|
8
7
|
|
|
9
8
|
describe('getStops():', () => {
|
|
10
9
|
before(async () => {
|
|
@@ -13,14 +12,15 @@ describe('getStops():', () => {
|
|
|
13
12
|
});
|
|
14
13
|
|
|
15
14
|
after(async () => {
|
|
16
|
-
|
|
15
|
+
const db = getDb(config);
|
|
16
|
+
await closeDb(db);
|
|
17
17
|
});
|
|
18
18
|
|
|
19
19
|
it('should return an empty array if no stops exist', async () => {
|
|
20
20
|
const stopId = 'fake-stop-id';
|
|
21
21
|
|
|
22
22
|
const results = await getStops({
|
|
23
|
-
stop_id: stopId
|
|
23
|
+
stop_id: stopId,
|
|
24
24
|
});
|
|
25
25
|
should.exists(results);
|
|
26
26
|
results.should.have.length(0);
|
|
@@ -44,7 +44,7 @@ describe('getStops():', () => {
|
|
|
44
44
|
stop_timezone: null,
|
|
45
45
|
wheelchair_boarding: 1,
|
|
46
46
|
level_id: null,
|
|
47
|
-
platform_code: null
|
|
47
|
+
platform_code: null,
|
|
48
48
|
};
|
|
49
49
|
|
|
50
50
|
should.exist(results);
|
|
@@ -56,26 +56,28 @@ describe('getStops():', () => {
|
|
|
56
56
|
const stopId = '70031';
|
|
57
57
|
|
|
58
58
|
const results = await getStops({
|
|
59
|
-
stop_id: stopId
|
|
59
|
+
stop_id: stopId,
|
|
60
60
|
});
|
|
61
61
|
|
|
62
|
-
const expectedResult = [
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
62
|
+
const expectedResult = [
|
|
63
|
+
{
|
|
64
|
+
stop_id: '70031',
|
|
65
|
+
stop_code: '70031',
|
|
66
|
+
stop_name: 'Bayshore Caltrain',
|
|
67
|
+
tts_stop_name: null,
|
|
68
|
+
stop_desc: null,
|
|
69
|
+
stop_lat: 37.709537,
|
|
70
|
+
stop_lon: -122.401586,
|
|
71
|
+
zone_id: '1',
|
|
72
|
+
stop_url: 'http://www.caltrain.com/stations/bayshorestation.html',
|
|
73
|
+
location_type: 0,
|
|
74
|
+
parent_station: 'ctba',
|
|
75
|
+
stop_timezone: null,
|
|
76
|
+
wheelchair_boarding: 1,
|
|
77
|
+
level_id: null,
|
|
78
|
+
platform_code: 'NB',
|
|
79
|
+
},
|
|
80
|
+
];
|
|
79
81
|
|
|
80
82
|
should.exist(results);
|
|
81
83
|
results.length.should.equal(1);
|
|
@@ -85,13 +87,13 @@ describe('getStops():', () => {
|
|
|
85
87
|
it('should return array of stops if it exists for a specific route_id', async () => {
|
|
86
88
|
const routeId = 'Bu-16APR';
|
|
87
89
|
|
|
88
|
-
const results = await getStops(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
['stop_id', 'ASC']
|
|
94
|
-
|
|
90
|
+
const results = await getStops(
|
|
91
|
+
{
|
|
92
|
+
route_id: routeId,
|
|
93
|
+
},
|
|
94
|
+
[],
|
|
95
|
+
[['stop_id', 'ASC']]
|
|
96
|
+
);
|
|
95
97
|
|
|
96
98
|
const expectedStopIds = [
|
|
97
99
|
'70011',
|
|
@@ -117,13 +119,16 @@ describe('getStops():', () => {
|
|
|
117
119
|
'70261',
|
|
118
120
|
'70262',
|
|
119
121
|
'70271',
|
|
120
|
-
'70272'
|
|
122
|
+
'70272',
|
|
121
123
|
];
|
|
122
124
|
|
|
123
125
|
should.exist(results);
|
|
124
126
|
results.length.should.equal(24);
|
|
125
127
|
for (const [idx, stop] of results.entries()) {
|
|
126
|
-
expectedStopIds[idx].should.equal(
|
|
128
|
+
expectedStopIds[idx].should.equal(
|
|
129
|
+
stop.stop_id,
|
|
130
|
+
'The order of stops are expected to be the same'
|
|
131
|
+
);
|
|
127
132
|
}
|
|
128
133
|
});
|
|
129
134
|
|
|
@@ -131,14 +136,14 @@ describe('getStops():', () => {
|
|
|
131
136
|
const routeId = 'Bu-16APR';
|
|
132
137
|
const directionId = 1;
|
|
133
138
|
|
|
134
|
-
const results = await getStops(
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
['stop_id', 'ASC']
|
|
141
|
-
|
|
139
|
+
const results = await getStops(
|
|
140
|
+
{
|
|
141
|
+
route_id: routeId,
|
|
142
|
+
direction_id: directionId,
|
|
143
|
+
},
|
|
144
|
+
[],
|
|
145
|
+
[['stop_id', 'ASC']]
|
|
146
|
+
);
|
|
142
147
|
|
|
143
148
|
const expectedStopIds = [
|
|
144
149
|
'70012',
|
|
@@ -152,26 +157,29 @@ describe('getStops():', () => {
|
|
|
152
157
|
'70212',
|
|
153
158
|
'70222',
|
|
154
159
|
'70262',
|
|
155
|
-
'70272'
|
|
160
|
+
'70272',
|
|
156
161
|
];
|
|
157
162
|
|
|
158
163
|
should.exist(results);
|
|
159
164
|
results.length.should.equal(12);
|
|
160
165
|
for (const [idx, stop] of results.entries()) {
|
|
161
|
-
expectedStopIds[idx].should.equal(
|
|
166
|
+
expectedStopIds[idx].should.equal(
|
|
167
|
+
stop.stop_id,
|
|
168
|
+
'The order of stops are expected to be the same'
|
|
169
|
+
);
|
|
162
170
|
}
|
|
163
171
|
});
|
|
164
172
|
|
|
165
173
|
it('should return array of stops for a specific trip_id', async () => {
|
|
166
174
|
const tripId = '427a';
|
|
167
175
|
|
|
168
|
-
const results = await getStops(
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
['stop_id', 'ASC']
|
|
174
|
-
|
|
176
|
+
const results = await getStops(
|
|
177
|
+
{
|
|
178
|
+
trip_id: tripId,
|
|
179
|
+
},
|
|
180
|
+
[],
|
|
181
|
+
[['stop_id', 'ASC']]
|
|
182
|
+
);
|
|
175
183
|
|
|
176
184
|
const expectedStopIds = [
|
|
177
185
|
'70011',
|
|
@@ -197,13 +205,16 @@ describe('getStops():', () => {
|
|
|
197
205
|
'70221',
|
|
198
206
|
'70231',
|
|
199
207
|
'70241',
|
|
200
|
-
'70261'
|
|
208
|
+
'70261',
|
|
201
209
|
];
|
|
202
210
|
|
|
203
211
|
should.exist(results);
|
|
204
212
|
results.length.should.equal(24);
|
|
205
213
|
for (const [idx, stop] of results.entries()) {
|
|
206
|
-
expectedStopIds[idx].should.equal(
|
|
214
|
+
expectedStopIds[idx].should.equal(
|
|
215
|
+
stop.stop_id,
|
|
216
|
+
'The order of stops are expected to be the same'
|
|
217
|
+
);
|
|
207
218
|
}
|
|
208
219
|
});
|
|
209
220
|
});
|