gtfs 3.1.3 → 3.1.4
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/.prettierrc.js +4 -0
- package/CHANGELOG.md +156 -0
- package/README.md +113 -126
- package/bin/gtfs-export.js +4 -5
- package/bin/gtfs-import.js +6 -7
- package/config-sample-full.json +2 -7
- package/lib/db.js +4 -2
- package/lib/export.js +26 -9
- package/lib/file-utils.js +26 -9
- package/lib/geojson-utils.js +51 -38
- package/lib/gtfs/agencies.js +8 -2
- package/lib/gtfs/attributions.js +8 -2
- package/lib/gtfs/calendar-dates.js +8 -2
- package/lib/gtfs/calendars.js +8 -2
- package/lib/gtfs/fare-attributes.js +8 -2
- package/lib/gtfs/fare-rules.js +8 -2
- package/lib/gtfs/feed-info.js +8 -2
- package/lib/gtfs/frequencies.js +8 -2
- package/lib/gtfs/levels.js +8 -2
- package/lib/gtfs/pathways.js +8 -2
- package/lib/gtfs/routes.js +15 -4
- package/lib/gtfs/shapes.js +49 -18
- package/lib/gtfs/stop-times.js +8 -2
- package/lib/gtfs/stops.js +45 -16
- package/lib/gtfs/transfers.js +8 -2
- package/lib/gtfs/translations.js +8 -2
- package/lib/gtfs/trips.js +8 -2
- package/lib/gtfs-ride/board-alights.js +8 -2
- package/lib/gtfs-ride/ride-feed-infos.js +8 -2
- package/lib/gtfs-ride/rider-trips.js +8 -2
- package/lib/gtfs-ride/riderships.js +8 -2
- package/lib/gtfs-ride/trip-capacities.js +8 -2
- package/lib/import.js +198 -123
- package/lib/log-utils.js +8 -4
- package/lib/non-standard/directions.js +8 -2
- package/lib/non-standard/stop-attributes.js +8 -2
- package/lib/non-standard/timetable-notes-references.js +13 -3
- package/lib/non-standard/timetable-notes.js +8 -2
- package/lib/non-standard/timetable-pages.js +8 -2
- package/lib/non-standard/timetable-stop-order.js +13 -3
- package/lib/non-standard/timetables.js +8 -2
- package/lib/utils.js +22 -11
- 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 +10 -2
- package/test/mocha/export-gtfs.js +63 -40
- package/test/mocha/get-agencies.js +11 -11
- package/test/mocha/get-attributions.js +1 -1
- package/test/mocha/get-board-alights.js +1 -1
- package/test/mocha/get-calendar-dates.js +22 -21
- package/test/mocha/get-calendars.js +8 -8
- package/test/mocha/get-db.js +9 -2
- package/test/mocha/get-directions.js +1 -1
- package/test/mocha/get-fare-attributes.js +3 -3
- package/test/mocha/get-fare-rules.js +8 -10
- package/test/mocha/get-feed-info.js +1 -1
- package/test/mocha/get-frequencies.js +1 -1
- package/test/mocha/get-levels.js +1 -1
- package/test/mocha/get-pathways.js +1 -1
- package/test/mocha/get-rider-trips.js +1 -1
- package/test/mocha/get-riderships.js +1 -1
- package/test/mocha/get-routes.js +9 -13
- package/test/mocha/get-shapes-as-geojson.js +3 -3
- package/test/mocha/get-shapes.js +28 -36
- package/test/mocha/get-stop-attributes.js +1 -1
- package/test/mocha/get-stops-as-geojson.js +2 -2
- package/test/mocha/get-stops.js +59 -48
- package/test/mocha/get-stoptimes.js +9 -7
- package/test/mocha/get-timetable-pages.js +1 -1
- package/test/mocha/get-timetable-stop-orders.js +1 -1
- package/test/mocha/get-timetables.js +1 -1
- package/test/mocha/get-transfers.js +1 -1
- package/test/mocha/get-translations.js +1 -1
- package/test/mocha/get-trip-capacities.js +1 -1
- package/test/mocha/get-trips.js +3 -3
- package/test/mocha/import-gtfs.js +59 -42
- package/test/test-config.js +9 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gtfs",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.4",
|
|
4
4
|
"description": "Import GTFS transit data into SQLite and query routes, stops, times, fares and more",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"transit",
|
|
@@ -62,6 +62,7 @@
|
|
|
62
62
|
},
|
|
63
63
|
"scripts": {
|
|
64
64
|
"lint": "eslint **/*.js",
|
|
65
|
+
"lint-fix": "eslint **/*.js --fix",
|
|
65
66
|
"test": "eslint **/*.js && NODE_ENV=test mocha ./test/mocha/**/*.js --timeout 2000"
|
|
66
67
|
},
|
|
67
68
|
"dependencies": {
|
|
@@ -77,7 +78,7 @@
|
|
|
77
78
|
"recursive-copy": "^2.0.13",
|
|
78
79
|
"sanitize-filename": "^1.6.3",
|
|
79
80
|
"sqlite": "^4.0.23",
|
|
80
|
-
"sqlite3": "
|
|
81
|
+
"sqlite3": "^5.0.2",
|
|
81
82
|
"sqlstring-sqlite": "^0.1.1",
|
|
82
83
|
"strip-bom-stream": "^5.0.0",
|
|
83
84
|
"tmp-promise": "^3.0.2",
|
|
@@ -87,8 +88,12 @@
|
|
|
87
88
|
},
|
|
88
89
|
"devDependencies": {
|
|
89
90
|
"eslint": "^8.0.1",
|
|
91
|
+
"eslint-config-prettier": "^8.3.0",
|
|
90
92
|
"eslint-config-xo": "^0.39.0",
|
|
93
|
+
"husky": "^7.0.2",
|
|
91
94
|
"mocha": "^9.1.3",
|
|
95
|
+
"prettier": "^2.4.1",
|
|
96
|
+
"pretty-quick": "^3.1.1",
|
|
92
97
|
"should": "^13.2.3"
|
|
93
98
|
},
|
|
94
99
|
"engines": {
|
|
@@ -103,5 +108,8 @@
|
|
|
103
108
|
"filename": "CHANGELOG.md"
|
|
104
109
|
}
|
|
105
110
|
}
|
|
111
|
+
},
|
|
112
|
+
"prettier": {
|
|
113
|
+
"singleQuote": true
|
|
106
114
|
}
|
|
107
115
|
}
|
|
@@ -33,52 +33,72 @@ describe('exportGtfs():', function () {
|
|
|
33
33
|
|
|
34
34
|
describe('Verify data exported', () => {
|
|
35
35
|
const countData = {};
|
|
36
|
-
const temporaryDir = path.join(
|
|
36
|
+
const temporaryDir = path.join(
|
|
37
|
+
path.dirname(fileURLToPath(import.meta.url)),
|
|
38
|
+
'../fixture/tmp/'
|
|
39
|
+
);
|
|
37
40
|
|
|
38
41
|
before(async () => {
|
|
39
42
|
await unzip(config.agencies[0].path, temporaryDir);
|
|
40
43
|
|
|
41
|
-
await Promise.all(
|
|
42
|
-
|
|
44
|
+
await Promise.all(
|
|
45
|
+
models.map((model) => {
|
|
46
|
+
const filePath = path.join(temporaryDir, `${model.filenameBase}.txt`);
|
|
43
47
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const parser = parse({
|
|
51
|
-
columns: true,
|
|
52
|
-
relax: true,
|
|
53
|
-
trim: true
|
|
54
|
-
}, (error, data) => {
|
|
55
|
-
if (error) {
|
|
56
|
-
throw new Error(error);
|
|
48
|
+
// GTFS has optional files
|
|
49
|
+
if (!existsSync(filePath)) {
|
|
50
|
+
countData[model.filenameBase] = 0;
|
|
51
|
+
return false;
|
|
57
52
|
}
|
|
58
53
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
54
|
+
const parser = parse(
|
|
55
|
+
{
|
|
56
|
+
columns: true,
|
|
57
|
+
relax: true,
|
|
58
|
+
trim: true,
|
|
59
|
+
},
|
|
60
|
+
(error, data) => {
|
|
61
|
+
if (error) {
|
|
62
|
+
throw new Error(error);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
countData[model.filenameBase] = data.length;
|
|
66
|
+
}
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
return createReadStream(filePath)
|
|
70
|
+
.pipe(parser)
|
|
71
|
+
.on('error', (error) => {
|
|
72
|
+
countData[model.collection] = 0;
|
|
73
|
+
throw new Error(error);
|
|
74
|
+
});
|
|
75
|
+
})
|
|
76
|
+
);
|
|
69
77
|
|
|
70
78
|
await importGtfs(config);
|
|
71
79
|
});
|
|
72
80
|
|
|
73
81
|
after(async () => {
|
|
74
82
|
const agencies = await getAgencies({}, ['agency_name']);
|
|
75
|
-
await rm(
|
|
83
|
+
await rm(
|
|
84
|
+
path.join(
|
|
85
|
+
process.cwd(),
|
|
86
|
+
'gtfs-export',
|
|
87
|
+
generateFolderName(agencies[0].agency_name)
|
|
88
|
+
),
|
|
89
|
+
{ recursive: true, force: true }
|
|
90
|
+
);
|
|
76
91
|
});
|
|
77
92
|
|
|
78
93
|
for (const model of models) {
|
|
79
94
|
it(`should import the same number of ${model.filenameBase}`, async () => {
|
|
80
95
|
const agencies = await getAgencies({}, ['agency_name']);
|
|
81
|
-
const filePath = path.join(
|
|
96
|
+
const filePath = path.join(
|
|
97
|
+
process.cwd(),
|
|
98
|
+
'gtfs-export',
|
|
99
|
+
generateFolderName(agencies[0].agency_name),
|
|
100
|
+
`${model.filenameBase}.txt`
|
|
101
|
+
);
|
|
82
102
|
|
|
83
103
|
// GTFS has optional files
|
|
84
104
|
if (!existsSync(filePath)) {
|
|
@@ -87,23 +107,26 @@ describe('exportGtfs():', function () {
|
|
|
87
107
|
return;
|
|
88
108
|
}
|
|
89
109
|
|
|
90
|
-
const parser = parse(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
110
|
+
const parser = parse(
|
|
111
|
+
{
|
|
112
|
+
columns: true,
|
|
113
|
+
relax: true,
|
|
114
|
+
trim: true,
|
|
115
|
+
},
|
|
116
|
+
(error, data) => {
|
|
117
|
+
if (error) {
|
|
118
|
+
throw new Error(error);
|
|
119
|
+
}
|
|
98
120
|
|
|
99
|
-
|
|
121
|
+
should.not.exist(error);
|
|
100
122
|
|
|
101
|
-
|
|
102
|
-
|
|
123
|
+
data.length.should.equal(countData[model.filenameBase]);
|
|
124
|
+
}
|
|
125
|
+
);
|
|
103
126
|
|
|
104
127
|
return createReadStream(filePath)
|
|
105
128
|
.pipe(parser)
|
|
106
|
-
.on('error', error => {
|
|
129
|
+
.on('error', (error) => {
|
|
107
130
|
should.not.exist(error);
|
|
108
131
|
});
|
|
109
132
|
});
|
|
@@ -18,7 +18,7 @@ describe('getAgencies():', () => {
|
|
|
18
18
|
it('should return empty array if no agencies exist', async () => {
|
|
19
19
|
const agencyId = 'fake-agency-id';
|
|
20
20
|
const results = await getAgencies({
|
|
21
|
-
agency_id: agencyId
|
|
21
|
+
agency_id: agencyId,
|
|
22
22
|
});
|
|
23
23
|
should.exists(results);
|
|
24
24
|
results.should.have.length(0);
|
|
@@ -36,7 +36,7 @@ describe('getAgencies():', () => {
|
|
|
36
36
|
agency_lang: 'en',
|
|
37
37
|
agency_phone: '800-660-4287',
|
|
38
38
|
agency_fare_url: null,
|
|
39
|
-
agency_email: null
|
|
39
|
+
agency_email: null,
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
should.exist(results);
|
|
@@ -50,7 +50,7 @@ describe('getAgencies():', () => {
|
|
|
50
50
|
|
|
51
51
|
const results = await getAgencies({
|
|
52
52
|
agency_id: agencyId,
|
|
53
|
-
agency_lang: agencyLand
|
|
53
|
+
agency_lang: agencyLand,
|
|
54
54
|
});
|
|
55
55
|
|
|
56
56
|
const expectedResult = {
|
|
@@ -62,7 +62,7 @@ describe('getAgencies():', () => {
|
|
|
62
62
|
agency_lang: 'en',
|
|
63
63
|
agency_phone: '800-660-4287',
|
|
64
64
|
agency_fare_url: null,
|
|
65
|
-
agency_email: null
|
|
65
|
+
agency_email: null,
|
|
66
66
|
};
|
|
67
67
|
|
|
68
68
|
should.exist(results);
|
|
@@ -73,16 +73,16 @@ describe('getAgencies():', () => {
|
|
|
73
73
|
it('should return only specific keys for expected agency for agency_id', async () => {
|
|
74
74
|
const agencyId = 'CT';
|
|
75
75
|
|
|
76
|
-
const results = await getAgencies(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
'agency_lang'
|
|
81
|
-
|
|
76
|
+
const results = await getAgencies(
|
|
77
|
+
{
|
|
78
|
+
agency_id: agencyId,
|
|
79
|
+
},
|
|
80
|
+
['agency_url', 'agency_lang']
|
|
81
|
+
);
|
|
82
82
|
|
|
83
83
|
const expectedResult = {
|
|
84
84
|
agency_url: 'http://www.caltrain.com',
|
|
85
|
-
agency_lang: 'en'
|
|
85
|
+
agency_lang: 'en',
|
|
86
86
|
};
|
|
87
87
|
|
|
88
88
|
should.exist(results);
|
|
@@ -19,7 +19,7 @@ describe('getAttributions():', () => {
|
|
|
19
19
|
it('should return empty array if no attributions exist', async () => {
|
|
20
20
|
const attributionId = 'fake-attribution-id';
|
|
21
21
|
const results = await getAttributions({
|
|
22
|
-
attribution_id: attributionId
|
|
22
|
+
attribution_id: attributionId,
|
|
23
23
|
});
|
|
24
24
|
should.exists(results);
|
|
25
25
|
results.should.have.length(0);
|
|
@@ -20,7 +20,7 @@ describe('getCalendarDates():', () => {
|
|
|
20
20
|
const serviceId = 'fake-service-id';
|
|
21
21
|
|
|
22
22
|
const results = await getCalendarDates({
|
|
23
|
-
service_id: serviceId
|
|
23
|
+
service_id: serviceId,
|
|
24
24
|
});
|
|
25
25
|
should.exists(results);
|
|
26
26
|
results.should.have.length(0);
|
|
@@ -30,7 +30,7 @@ describe('getCalendarDates():', () => {
|
|
|
30
30
|
const serviceId = 'CT-16APR-Caltrain-Weekday-01';
|
|
31
31
|
|
|
32
32
|
const results = await getCalendarDates({
|
|
33
|
-
service_id: serviceId
|
|
33
|
+
service_id: serviceId,
|
|
34
34
|
});
|
|
35
35
|
|
|
36
36
|
should.exists(results);
|
|
@@ -42,29 +42,29 @@ describe('getCalendarDates():', () => {
|
|
|
42
42
|
service_id: 'CT-16APR-Caltrain-Weekday-01',
|
|
43
43
|
date: 20161124,
|
|
44
44
|
exception_type: 2,
|
|
45
|
-
holiday_name: null
|
|
45
|
+
holiday_name: null,
|
|
46
46
|
},
|
|
47
47
|
{
|
|
48
48
|
id: 4,
|
|
49
49
|
service_id: 'CT-16APR-Caltrain-Weekday-01',
|
|
50
50
|
date: 20160905,
|
|
51
51
|
exception_type: 2,
|
|
52
|
-
holiday_name: null
|
|
52
|
+
holiday_name: null,
|
|
53
53
|
},
|
|
54
54
|
{
|
|
55
55
|
id: 6,
|
|
56
56
|
service_id: 'CT-16APR-Caltrain-Weekday-01',
|
|
57
57
|
date: 20160704,
|
|
58
58
|
exception_type: 2,
|
|
59
|
-
holiday_name: null
|
|
59
|
+
holiday_name: null,
|
|
60
60
|
},
|
|
61
61
|
{
|
|
62
62
|
id: 8,
|
|
63
63
|
service_id: 'CT-16APR-Caltrain-Weekday-01',
|
|
64
64
|
date: 20160530,
|
|
65
65
|
exception_type: 2,
|
|
66
|
-
holiday_name: null
|
|
67
|
-
}
|
|
66
|
+
holiday_name: null,
|
|
67
|
+
},
|
|
68
68
|
];
|
|
69
69
|
|
|
70
70
|
for (const result of results) {
|
|
@@ -75,33 +75,34 @@ describe('getCalendarDates():', () => {
|
|
|
75
75
|
it('should return only specific keys for expected calendar dates, sorted by date', async () => {
|
|
76
76
|
const serviceId = 'CT-16APR-Caltrain-Weekday-01';
|
|
77
77
|
|
|
78
|
-
const results = await getCalendarDates(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
'date'
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
78
|
+
const results = await getCalendarDates(
|
|
79
|
+
{
|
|
80
|
+
service_id: serviceId,
|
|
81
|
+
},
|
|
82
|
+
['service_id', 'date'],
|
|
83
|
+
[
|
|
84
|
+
['date', 'ASC'],
|
|
85
|
+
['service_id', 'ASC'],
|
|
86
|
+
]
|
|
87
|
+
);
|
|
87
88
|
|
|
88
89
|
const expectedResults = [
|
|
89
90
|
{
|
|
90
91
|
service_id: 'CT-16APR-Caltrain-Weekday-01',
|
|
91
|
-
date: 20160530
|
|
92
|
+
date: 20160530,
|
|
92
93
|
},
|
|
93
94
|
{
|
|
94
95
|
service_id: 'CT-16APR-Caltrain-Weekday-01',
|
|
95
|
-
date: 20160704
|
|
96
|
+
date: 20160704,
|
|
96
97
|
},
|
|
97
98
|
{
|
|
98
99
|
service_id: 'CT-16APR-Caltrain-Weekday-01',
|
|
99
|
-
date: 20160905
|
|
100
|
+
date: 20160905,
|
|
100
101
|
},
|
|
101
102
|
{
|
|
102
103
|
service_id: 'CT-16APR-Caltrain-Weekday-01',
|
|
103
|
-
date: 20161124
|
|
104
|
-
}
|
|
104
|
+
date: 20161124,
|
|
105
|
+
},
|
|
105
106
|
];
|
|
106
107
|
|
|
107
108
|
results.length.should.equal(4);
|
|
@@ -20,7 +20,7 @@ describe('getCalendars():', () => {
|
|
|
20
20
|
const serviceId = 'fake-service-id';
|
|
21
21
|
|
|
22
22
|
const results = await getCalendars({
|
|
23
|
-
service_id: serviceId
|
|
23
|
+
service_id: serviceId,
|
|
24
24
|
});
|
|
25
25
|
should.exists(results);
|
|
26
26
|
results.should.have.length(0);
|
|
@@ -28,7 +28,7 @@ describe('getCalendars():', () => {
|
|
|
28
28
|
|
|
29
29
|
it('should return expected calendars by day', async () => {
|
|
30
30
|
const results = await getCalendars({
|
|
31
|
-
sunday: 1
|
|
31
|
+
sunday: 1,
|
|
32
32
|
});
|
|
33
33
|
|
|
34
34
|
const expectedResult = {
|
|
@@ -41,7 +41,7 @@ describe('getCalendars():', () => {
|
|
|
41
41
|
saturday: 0,
|
|
42
42
|
sunday: 1,
|
|
43
43
|
start_date: 20140323,
|
|
44
|
-
end_date: 20190331
|
|
44
|
+
end_date: 20190331,
|
|
45
45
|
};
|
|
46
46
|
|
|
47
47
|
should.exist(results);
|
|
@@ -53,8 +53,8 @@ describe('getCalendars():', () => {
|
|
|
53
53
|
const results = await getCalendars({
|
|
54
54
|
service_id: [
|
|
55
55
|
'CT-16APR-Caltrain-Saturday-02',
|
|
56
|
-
'CT-16APR-Caltrain-Sunday-02'
|
|
57
|
-
]
|
|
56
|
+
'CT-16APR-Caltrain-Sunday-02',
|
|
57
|
+
],
|
|
58
58
|
});
|
|
59
59
|
|
|
60
60
|
const expectedResults = [
|
|
@@ -68,7 +68,7 @@ describe('getCalendars():', () => {
|
|
|
68
68
|
saturday: 1,
|
|
69
69
|
sunday: 0,
|
|
70
70
|
start_date: 20140329,
|
|
71
|
-
end_date: 20190331
|
|
71
|
+
end_date: 20190331,
|
|
72
72
|
},
|
|
73
73
|
{
|
|
74
74
|
service_id: 'CT-16APR-Caltrain-Sunday-02',
|
|
@@ -80,8 +80,8 @@ describe('getCalendars():', () => {
|
|
|
80
80
|
saturday: 0,
|
|
81
81
|
sunday: 1,
|
|
82
82
|
start_date: 20140323,
|
|
83
|
-
end_date: 20190331
|
|
84
|
-
}
|
|
83
|
+
end_date: 20190331,
|
|
84
|
+
},
|
|
85
85
|
];
|
|
86
86
|
|
|
87
87
|
should.exist(results);
|
package/test/mocha/get-db.js
CHANGED
|
@@ -19,7 +19,11 @@ describe('getDb():', () => {
|
|
|
19
19
|
it('should allow raw db queries: calendar_dates', async () => {
|
|
20
20
|
const serviceIds = ['CT-16APR-Caltrain-Weekday-01'];
|
|
21
21
|
const db = getDb();
|
|
22
|
-
const results = await db.all(
|
|
22
|
+
const results = await db.all(
|
|
23
|
+
`SELECT * FROM calendar_dates WHERE exception_type = 1 AND service_id NOT IN (${serviceIds
|
|
24
|
+
.map((serviceId) => `'${serviceId}'`)
|
|
25
|
+
.join(', ')})`
|
|
26
|
+
);
|
|
23
27
|
|
|
24
28
|
should.exists(results);
|
|
25
29
|
results.should.have.length(4);
|
|
@@ -30,7 +34,10 @@ describe('getDb():', () => {
|
|
|
30
34
|
const startStopId = '70261';
|
|
31
35
|
const endStopId = '70131';
|
|
32
36
|
const db = getDb();
|
|
33
|
-
const results = await db.all(
|
|
37
|
+
const results = await db.all(
|
|
38
|
+
'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 = ? ))',
|
|
39
|
+
[startStopId, endStopId]
|
|
40
|
+
);
|
|
34
41
|
should.exists(results);
|
|
35
42
|
results.should.have.length(62);
|
|
36
43
|
});
|
|
@@ -20,7 +20,7 @@ describe('getFareAttributes():', () => {
|
|
|
20
20
|
const fareId = 'not_real';
|
|
21
21
|
|
|
22
22
|
const results = await getFareAttributes({
|
|
23
|
-
fare_id: fareId
|
|
23
|
+
fare_id: fareId,
|
|
24
24
|
});
|
|
25
25
|
|
|
26
26
|
should.exists(results);
|
|
@@ -31,7 +31,7 @@ describe('getFareAttributes():', () => {
|
|
|
31
31
|
const fareId = 'OW_1_20160228';
|
|
32
32
|
|
|
33
33
|
const results = await getFareAttributes({
|
|
34
|
-
fare_id: fareId
|
|
34
|
+
fare_id: fareId,
|
|
35
35
|
});
|
|
36
36
|
|
|
37
37
|
const expectedResult = {
|
|
@@ -41,7 +41,7 @@ describe('getFareAttributes():', () => {
|
|
|
41
41
|
payment_method: 1,
|
|
42
42
|
transfers: 0,
|
|
43
43
|
agency_id: null,
|
|
44
|
-
transfer_duration: null
|
|
44
|
+
transfer_duration: null,
|
|
45
45
|
};
|
|
46
46
|
|
|
47
47
|
should.exist(results);
|
|
@@ -20,7 +20,7 @@ describe('getFareRules():', () => {
|
|
|
20
20
|
const routeId = 'not_real';
|
|
21
21
|
|
|
22
22
|
const results = await getFareRules({
|
|
23
|
-
route_id: routeId
|
|
23
|
+
route_id: routeId,
|
|
24
24
|
});
|
|
25
25
|
should.exists(results);
|
|
26
26
|
results.should.have.length(0);
|
|
@@ -29,20 +29,18 @@ describe('getFareRules():', () => {
|
|
|
29
29
|
it('should return expected fare_rules', async () => {
|
|
30
30
|
const routeId = 'Bu-16APR';
|
|
31
31
|
|
|
32
|
-
const results = await getFareRules(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
'route_id',
|
|
37
|
-
|
|
38
|
-
'destination_id'
|
|
39
|
-
]);
|
|
32
|
+
const results = await getFareRules(
|
|
33
|
+
{
|
|
34
|
+
route_id: routeId,
|
|
35
|
+
},
|
|
36
|
+
['fare_id', 'route_id', 'origin_id', 'destination_id']
|
|
37
|
+
);
|
|
40
38
|
|
|
41
39
|
const expectedResult = {
|
|
42
40
|
fare_id: 'OW_2_20160228',
|
|
43
41
|
route_id: 'Bu-16APR',
|
|
44
42
|
origin_id: '6',
|
|
45
|
-
destination_id: '5'
|
|
43
|
+
destination_id: '5',
|
|
46
44
|
};
|
|
47
45
|
|
|
48
46
|
should.exist(results);
|
|
@@ -20,7 +20,7 @@ describe('getFeedInfo():', () => {
|
|
|
20
20
|
const feedPublisherName = 'not_real';
|
|
21
21
|
|
|
22
22
|
const results = await getFeedInfo({
|
|
23
|
-
feed_publisher_name: feedPublisherName
|
|
23
|
+
feed_publisher_name: feedPublisherName,
|
|
24
24
|
});
|
|
25
25
|
should.exists(results);
|
|
26
26
|
results.should.have.length(0);
|
package/test/mocha/get-levels.js
CHANGED
package/test/mocha/get-routes.js
CHANGED
|
@@ -20,18 +20,14 @@ describe('getRoutes():', () => {
|
|
|
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);
|
|
@@ -19,7 +19,7 @@ describe('getShapesAsGeoJSON():', () => {
|
|
|
19
19
|
it('should return geojson with an empty features array if no shapes exist', async () => {
|
|
20
20
|
const shapeId = 'fake-shape-id';
|
|
21
21
|
const geojson = await getShapesAsGeoJSON({
|
|
22
|
-
shape_id: shapeId
|
|
22
|
+
shape_id: shapeId,
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
should.exist(geojson);
|
|
@@ -42,7 +42,7 @@ describe('getShapesAsGeoJSON():', () => {
|
|
|
42
42
|
const routeId = 'Lo-16APR';
|
|
43
43
|
|
|
44
44
|
const geojson = await getShapesAsGeoJSON({
|
|
45
|
-
route_id: routeId
|
|
45
|
+
route_id: routeId,
|
|
46
46
|
});
|
|
47
47
|
|
|
48
48
|
should.exist(geojson);
|
|
@@ -59,7 +59,7 @@ describe('getShapesAsGeoJSON():', () => {
|
|
|
59
59
|
|
|
60
60
|
const geojson = await getShapesAsGeoJSON({
|
|
61
61
|
route_id: routeId,
|
|
62
|
-
direction_id: directionId
|
|
62
|
+
direction_id: directionId,
|
|
63
63
|
});
|
|
64
64
|
|
|
65
65
|
should.exist(geojson);
|