Skip to content

Commit

Permalink
TripUpdate sigs: make TripDescriptor.start_date mandatory 💥
Browse files Browse the repository at this point in the history
  • Loading branch information
derhuerst committed Sep 15, 2024
1 parent 532fa33 commit 3e6ae4e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 21 deletions.
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ class UnsupportedKindOfFeedEntityError extends Error {}
class FeedEntitySignatureError extends Error {}

const tripSignature = (u) => {
if (u.trip.trip_id) return u.trip.trip_id
if (u.trip.trip_id && u.trip.start_date) {
return u.trip.trip_id + '-' + u.trip.start_date
}
if (u.trip.route_id && u.vehicle.id) {
return u.trip.route_id + '-' + u.vehicle.id
}
Expand Down
6 changes: 3 additions & 3 deletions test/data.ndjson
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{"header":{"gtfs_realtime_version":"2.0","incrementality":1,"timestamp":1},"entity":[{"id":"1","vehicle":{"trip":{"trip_id":"1|64512|1|86|12032020","route_id":"n18"},"vehicle":{"id":null,"label":"U Mohrenstr."},"position":{"latitude":52.5,"longitude":13.3},"stop_id":"900000005205","current_status":2}},{"id":"2","trip_update":{"trip":{"trip_id":"1|25445|2|86|12032020","route_id":"n3"},"vehicle":{"id":"40813","label":"U Wittenbergplatz"},"stop_time_update":[{"stop_id":"900000050301","arrival":{"time":null,"delay":null},"departure":{"time":1584060600,"delay":0},"schedule_relationship":0},{"stop_id":"900000023354","arrival":{"time":1584062400,"delay":-60},"departure":{"time":1584062400,"delay":-60},"schedule_relationship":0},{"stop_id":"900000023203","arrival":{"time":1584062460,"delay":-60},"departure":{"time":1584062460,"delay":-60},"schedule_relationship":0},{"stop_id":"900000023204","arrival":{"time":1584062580,"delay":-60},"departure":{"time":1584062580,"delay":-60},"schedule_relationship":0},{"stop_id":"900000056101","arrival":{"time":1584062640,"delay":-60},"departure":{"time":null,"delay":null},"schedule_relationship":0}]}}]}
{"header":{"gtfs_realtime_version":"2.0","incrementality":1,"timestamp":2},"entity":[{"id":"3","vehicle":{"trip":{"trip_id":"1|64466|1|86|12032020","route_id":"n6"},"vehicle":{"id":null,"label":"U Alt-Mariendorf"},"position":{"latitude":52.1,"longitude":13.1},"stop_id":"900000012106","current_status":1}}]}
{"header":{"gtfs_realtime_version":"2.0","incrementality":1,"timestamp":3},"entity":[{"id":"4","vehicle":{"trip":{"trip_id":"1|64512|1|86|12032020","route_id":"n18"},"vehicle":{"id":null,"label":"U Mohrenstr."},"position":{"latitude":52.6,"longitude":13.4},"stop_id":"900000005205","current_status":2}}]}
{"header":{"gtfs_realtime_version":"2.0","incrementality":1,"timestamp":1},"entity":[{"id":"1","vehicle":{"trip":{"trip_id":"1|64512|1|86|12032020","route_id":"n18","start_date":"20200312"},"vehicle":{"id":null,"label":"U Mohrenstr."},"position":{"latitude":52.5,"longitude":13.3},"stop_id":"900000005205","current_status":2}},{"id":"2","trip_update":{"trip":{"trip_id":"1|25445|2|86|12032020","route_id":"n3","start_date":"20200312"},"vehicle":{"id":"40813","label":"U Wittenbergplatz"},"stop_time_update":[{"stop_id":"900000050301","arrival":{"time":null,"delay":null},"departure":{"time":1584060600,"delay":0},"schedule_relationship":0},{"stop_id":"900000023354","arrival":{"time":1584062400,"delay":-60},"departure":{"time":1584062400,"delay":-60},"schedule_relationship":0},{"stop_id":"900000023203","arrival":{"time":1584062460,"delay":-60},"departure":{"time":1584062460,"delay":-60},"schedule_relationship":0},{"stop_id":"900000023204","arrival":{"time":1584062580,"delay":-60},"departure":{"time":1584062580,"delay":-60},"schedule_relationship":0},{"stop_id":"900000056101","arrival":{"time":1584062640,"delay":-60},"departure":{"time":null,"delay":null},"schedule_relationship":0}]}}]}
{"header":{"gtfs_realtime_version":"2.0","incrementality":1,"timestamp":2},"entity":[{"id":"3","vehicle":{"trip":{"trip_id":"1|64466|1|86|12032020","route_id":"n6","start_date":"20200312"},"vehicle":{"id":null,"label":"U Alt-Mariendorf"},"position":{"latitude":52.1,"longitude":13.1},"stop_id":"900000012106","current_status":1}}]}
{"header":{"gtfs_realtime_version":"2.0","incrementality":1,"timestamp":3},"entity":[{"id":"4","vehicle":{"trip":{"trip_id":"1|64512|1|86|12032020","route_id":"n18","start_date":"20200312"},"vehicle":{"id":null,"label":"U Mohrenstr."},"position":{"latitude":52.6,"longitude":13.4},"stop_id":"900000005205","current_status":2}}]}
49 changes: 32 additions & 17 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ const timestamp = () => 1
const e1 = {
id: '1',
vehicle: {
trip: {trip_id: '1|30532|17|86|12032020', route_id: 'm10'},
trip: {
trip_id: '1|30532|17|86|12032020',
route_id: 'm10',
start_date: '20200312',
},
vehicle: {id: null, label: 'S+U Warschauer Str.'},
position: {latitude: 52.531513, longitude: 13.38741},
stop_id: '900000007104',
Expand All @@ -40,7 +44,11 @@ const e1 = {
const e2 = {
id: '2',
vehicle: {
trip: {trip_id: '1|22921|5|86|12032020', route_id: 'm41'},
trip: {
trip_id: '1|22921|5|86|12032020',
route_id: 'm41',
start_date: '20200312',
},
vehicle: {id: null, label: 'Sonnenallee/Baumschulenstr.'},
position: {latitude: 52.497561, longitude: 13.394512},
stop_id: '900000012152',
Expand All @@ -51,7 +59,11 @@ const e2 = {
const e3 = {
id: '130',
trip_update: {
trip: {trip_id: '1|33296|7|86|12032020', route_id: 'u3'},
trip: {
trip_id: '1|33296|7|86|12032020',
route_id: 'u3',
start_date: '20200312',
},
vehicle: {id: null, label: 'U Gleisdreieck'},
stop_time_update: [
{stop_id: '900000041101', departure: {delay: 60}},
Expand Down Expand Up @@ -126,20 +138,23 @@ pump(
strictEqual(changeEmitted, true, 'no `change` event emitted')
bufEqual(full.asFeedMessage(), Buffer.from(
`\
0a090a03322e301000180112ac020a01321aa6020a1b0a15317c32353434357c327c3\
8367c31323033323032302a026e33121c12001a08080010b8b1abf305220c39303030\
303030353033303128001236121108c4ffffffffffffffff0110c0bfabf3051a1108c\
4ffffffffffffffff0110c0bfabf305220c3930303030303032333335342800123612\
1108c4ffffffffffffffff0110fcbfabf3051a1108c4ffffffffffffffff0110fcbfa\
bf305220c39303030303030323332303328001236121108c4ffffffffffffffff0110\
f4c0abf3051a1108c4ffffffffffffffff0110f4c0abf305220c39303030303030323\
332303428001225121108c4ffffffffffffffff0110b0c1abf3051a00220c39303030\
303030353631303128001a1a0a0534303831331211552057697474656e62657267706\
c61747a12520a0133224d0a1b0a15317c36343436367c317c38367c31323033323032\
302a026e36120a0d66665042159a99514120013a0c393030303030303132313036421\
212105520416c742d4d617269656e646f7266124f0a0134224a0a1c0a15317c363435\
31327c317c38367c31323033323032302a036e3138120a0d666652421566665641200\
23a0c393030303030303035323035420e120c55204d6f6872656e7374722e`,
0a090a03322e301000180112b6020a01321ab0020a250a15317c32353434\
357c327c38367c31323033323032301a0832303230303331322a026e3312\
1c12001a08080010b8b1abf305220c393030303030303530333031280012\
36121108c4ffffffffffffffff0110c0bfabf3051a1108c4ffffffffffff\
ffff0110c0bfabf305220c39303030303030323333353428001236121108\
c4ffffffffffffffff0110fcbfabf3051a1108c4ffffffffffffffff0110\
fcbfabf305220c39303030303030323332303328001236121108c4ffffff\
ffffffffff0110f4c0abf3051a1108c4ffffffffffffffff0110f4c0abf3\
05220c39303030303030323332303428001225121108c4ffffffffffffff\
ff0110b0c1abf3051a00220c39303030303030353631303128001a1a0a05\
34303831331211552057697474656e62657267706c61747a125c0a013322\
570a250a15317c36343436367c317c38367c31323033323032301a083230\
3230303331322a026e36120a0d66665042159a99514120013a0c39303030\
3030303132313036421212105520416c742d4d617269656e646f72661259\
0a013422540a260a15317c36343531327c317c38367c3132303332303230\
1a0832303230303331322a036e3138120a0d66665242156666564120023a\
0c393030303030303035323035420e120c55204d6f6872656e7374722e`,
'hex'
))
strictEqual(full.timeModified(), timestamp(), 'invalid full.timeModified()')
Expand Down

0 comments on commit 3e6ae4e

Please sign in to comment.