-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from linkedconnections/development
v0.8.6
- Loading branch information
Showing
4 changed files
with
134 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
{ | ||
"stop" : "http://data.gtfs.org/example/stops/{stop_id}", | ||
"route" : "http://data.gtfs.org/example/routes/{routes.route_id}", | ||
"trip" : "http://data.gtfs.org/example/trips/{trips.trip_id}/{trips.startTime(YYYYMMDDTHHmm)}", | ||
"connection" : "http://example/linkedconnections.org/connections/{trips.startTime(YYYYMMDDTHHmm)}/{connection.departureStop}/{trips.trip_id}" | ||
"stop": "http://data.gtfs.org/example/stops/{stop_id}", | ||
"route": "http://data.gtfs.org/example/routes/{routes.route_short_name}", | ||
"trip": "http://data.gtfs.org/example/trips/{trip_id}/{routes.route_short_name}{trips.startTime}", | ||
"connection": "http://example/linkedconnections.org/connections/{trips.startTime}/{connection.departureStop}/{trips.trip_id}", | ||
"resolve": { | ||
"route_short_id": "connection.trip.route.route_id.substring(0,5)", | ||
"trip_id": "connection.trip.trip_id", | ||
"trip_startTime": "format(connection.trip.startTime, 'YYYYMMDDTHHmm');", | ||
"departureStop": "connection.departureStop" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
const assert = require('assert'); | ||
const URIStrategy = require('../lib/URIStrategy'); | ||
|
||
describe('URIStrategy', () => { | ||
describe('getRouteId', () => { | ||
it('should replace {routes.route_id} by connection.trip.route.route_id', () => { | ||
const strategy = new URIStrategy({ | ||
route: 'http://example.org/routes/{routes.route_id}', | ||
}); | ||
|
||
const connection = { | ||
trip: { | ||
route: { | ||
route_id: 'B1234-56789', | ||
}, | ||
}, | ||
}; | ||
|
||
assert.equal( | ||
strategy.getRouteId(connection), | ||
'http://example.org/routes/B1234-56789' | ||
); | ||
}); | ||
|
||
it('should replace spaces by %20', () => { | ||
const strategy = new URIStrategy({ | ||
route: 'http://example.org/routes/{routes.route_id}', | ||
}); | ||
|
||
const connection = { | ||
trip: { | ||
route: { | ||
route_id: 'a b c', | ||
}, | ||
}, | ||
}; | ||
|
||
assert.equal( | ||
strategy.getRouteId(connection), | ||
'http://example.org/routes/a%20b%20c' | ||
); | ||
}); | ||
|
||
it('should resolve expression by evaluating matching key in resolve object', () => { | ||
const strategy = new URIStrategy({ | ||
route: 'http://example.org/routes/{route_short_id}', | ||
resolve: { | ||
route_short_id: 'connection.trip.route.route_id.substring(0,5)', | ||
}, | ||
}); | ||
|
||
const connection = { | ||
trip: { | ||
route: { | ||
route_id: 'B1234-56789', | ||
}, | ||
}, | ||
}; | ||
|
||
assert.equal( | ||
strategy.getRouteId(connection), | ||
'http://example.org/routes/B1234' | ||
); | ||
}); | ||
}); | ||
|
||
describe('getId', () => { | ||
it('should resolve expression using date-fns.format function', () => { | ||
const strategy = new URIStrategy({ | ||
connection: | ||
'http://example.org/connections/{trip_startTime}/{departureStop}/{trip_id}', | ||
resolve: { | ||
trip_id: 'connection.trip.trip_id', | ||
trip_startTime: "format(connection.trip.startTime, 'YYYYMMDDTHHmm');", | ||
departureStop: 'connection.departureStop', | ||
}, | ||
}); | ||
|
||
const connection = { | ||
departureStop: '1234', | ||
trip: { | ||
trip_id: '5678', | ||
startTime: new Date('2018-09-21T10:25:12'), | ||
}, | ||
}; | ||
|
||
assert.equal( | ||
strategy.getId(connection), | ||
'http://example.org/connections/20180921T1025/1234/5678' | ||
); | ||
}); | ||
}); | ||
}); |