beforeJourneys/afterJourneys: more tests

This commit is contained in:
Jannis R 2018-03-04 20:12:38 +01:00 committed by Jannis Redmann
parent 56e660d08e
commit fe7822883e
2 changed files with 96 additions and 22 deletions

View file

@ -53,7 +53,7 @@ const findStation = (id) => new Promise((yay, nay) => {
const isJungfernheide = (s) => { const isJungfernheide = (s) => {
return s.type === 'station' && return s.type === 'station' &&
(s.id === '008011167' || s.id === '8011167') && (s.id === '008011167' || s.id === jungfernh) &&
s.name === 'Berlin Jungfernheide' && s.name === 'Berlin Jungfernheide' &&
s.location && s.location &&
isRoughlyEqual(s.location.latitude, 52.530408, .0005) && isRoughlyEqual(s.location.latitude, 52.530408, .0005) &&
@ -62,7 +62,7 @@ const isJungfernheide = (s) => {
const assertIsJungfernheide = (t, s) => { const assertIsJungfernheide = (t, s) => {
t.equal(s.type, 'station') t.equal(s.type, 'station')
t.ok(s.id === '008011167' || s.id === '8011167', 'id should be 8011167') t.ok(s.id === '008011167' || s.id === jungfernh, 'id should be 8011167')
t.equal(s.name, 'Berlin Jungfernheide') t.equal(s.name, 'Berlin Jungfernheide')
t.ok(s.location) t.ok(s.location)
t.ok(isRoughlyEqual(s.location.latitude, 52.530408, .0005)) t.ok(isRoughlyEqual(s.location.latitude, 52.530408, .0005))
@ -92,8 +92,14 @@ const assertValidPrice = (t, p) => {
const test = tapePromise(tape) const test = tapePromise(tape)
const client = createClient(dbProfile) const client = createClient(dbProfile)
const jungfernh = '8011167'
const berlinHbf = '8011160'
const münchenHbf = '8000261'
const hannoverHbf = '8000152'
const regensburgHbf = '8000309'
test('Berlin Jungfernheide to München Hbf', co(function* (t) { test('Berlin Jungfernheide to München Hbf', co(function* (t) {
const journeys = yield client.journeys('8011167', '8000261', { const journeys = yield client.journeys(jungfernh, münchenHbf, {
when, passedStations: true when, passedStations: true
}) })
@ -154,7 +160,7 @@ test('Berlin Jungfernheide to München Hbf', co(function* (t) {
})) }))
test('Berlin Jungfernheide to Torfstraße 17', co(function* (t) { test('Berlin Jungfernheide to Torfstraße 17', co(function* (t) {
const journeys = yield client.journeys('8011167', { const journeys = yield client.journeys(jungfernh, {
type: 'location', address: 'Torfstraße 17', type: 'location', address: 'Torfstraße 17',
latitude: 52.5416823, longitude: 13.3491223 latitude: 52.5416823, longitude: 13.3491223
}, {when}) }, {when})
@ -183,7 +189,7 @@ test('Berlin Jungfernheide to Torfstraße 17', co(function* (t) {
})) }))
test('Berlin Jungfernheide to ATZE Musiktheater', co(function* (t) { test('Berlin Jungfernheide to ATZE Musiktheater', co(function* (t) {
const journeys = yield client.journeys('8011167', { const journeys = yield client.journeys(jungfernh, {
type: 'location', id: '991598902', name: 'ATZE Musiktheater', type: 'location', id: '991598902', name: 'ATZE Musiktheater',
latitude: 52.542417, longitude: 13.350437 latitude: 52.542417, longitude: 13.350437
}, {when}) }, {when})
@ -212,9 +218,6 @@ test('Berlin Jungfernheide to ATZE Musiktheater', co(function* (t) {
})) }))
test('Berlin Hbf to München Hbf with stopover at Hannover Hbf', co(function* (t) { test('Berlin Hbf to München Hbf with stopover at Hannover Hbf', co(function* (t) {
const berlinHbf = '8011160'
const münchenHbf = '8000261'
const hannoverHbf = '8000152'
const [journey] = yield client.journeys(berlinHbf, münchenHbf, { const [journey] = yield client.journeys(berlinHbf, münchenHbf, {
via: hannoverHbf, via: hannoverHbf,
results: 1 results: 1
@ -230,8 +233,46 @@ test('Berlin Hbf to München Hbf with stopover at Hannover Hbf', co(function* (t
t.end() t.end()
})) }))
test('earlier/later journeys, Jungfernheide -> München Hbf', co(function* (t) {
const model = yield client.journeys(jungfernh, münchenHbf, {
results: 3, when
})
t.equal(typeof model.earlierJourneysRef, 'string')
t.ok(model.earlierJourneysRef)
t.equal(typeof model.laterJourneysRef, 'string')
t.ok(model.laterJourneysRef)
let earliestDep = Infinity, latestDep = -Infinity
for (let j of model) {
const dep = +new Date(j.departure)
if (dep < earliestDep) earliestDep = dep
else if (dep > latestDep) latestDep = dep
}
const earlier = yield client.journeys(jungfernh, münchenHbf, {
results: 3,
// todo: single journey ref?
beforeJourneys: model.earlierJourneysRef
})
for (let j of earlier) {
t.ok(new Date(j.departure) < earliestDep)
}
const later = yield client.journeys(jungfernh, münchenHbf, {
results: 3,
// todo: single journey ref?
afterJourneys: model.laterJourneysRef
})
for (let j of later) {
t.ok(new Date(j.departure) > latestDep)
}
t.end()
}))
test('departures at Berlin Jungfernheide', co(function* (t) { test('departures at Berlin Jungfernheide', co(function* (t) {
const deps = yield client.departures('8011167', { const deps = yield client.departures(jungfernh, {
duration: 5, when duration: 5, when
}) })
@ -252,7 +293,7 @@ test('departures at Berlin Jungfernheide', co(function* (t) {
test('departures with station object', co(function* (t) { test('departures with station object', co(function* (t) {
yield client.departures({ yield client.departures({
type: 'station', type: 'station',
id: '8011167', id: jungfernh,
name: 'Berlin Jungfernheide', name: 'Berlin Jungfernheide',
location: { location: {
type: 'location', type: 'location',
@ -308,7 +349,6 @@ test('locations named Jungfernheide', co(function* (t) {
})) }))
test('location', co(function* (t) { test('location', co(function* (t) {
const regensburgHbf = '8000309'
const loc = yield client.location(regensburgHbf) const loc = yield client.location(regensburgHbf)
assertValidStation(t, loc) assertValidStation(t, loc)

View file

@ -110,9 +110,14 @@ const assertValidLine = (t, l) => { // with optional mode
const test = tapePromise(tape) const test = tapePromise(tape)
const client = createClient(oebbProfile) const client = createClient(oebbProfile)
const salzburgHbf = '8100002'
const wienWestbahnhof = '1291501'
const wien = '1190100'
const klagenfurtHbf = '8100085'
const muenchenHbf = '8000261'
const grazHbf = '8100173'
test('Salzburg Hbf to Wien Westbahnhof', co(function* (t) { test('Salzburg Hbf to Wien Westbahnhof', co(function* (t) {
const salzburgHbf = '8100002'
const wienWestbahnhof = '1291501'
const journeys = yield client.journeys(salzburgHbf, wienWestbahnhof, { const journeys = yield client.journeys(salzburgHbf, wienWestbahnhof, {
when, passedStations: true when, passedStations: true
}) })
@ -178,7 +183,6 @@ test('Salzburg Hbf to Wien Westbahnhof', co(function* (t) {
})) }))
test('Salzburg Hbf to 1220 Wien, Wagramer Straße 5', co(function* (t) { test('Salzburg Hbf to 1220 Wien, Wagramer Straße 5', co(function* (t) {
const salzburgHbf = '8100002'
const wagramerStr = { const wagramerStr = {
type: 'location', type: 'location',
latitude: 48.236216, latitude: 48.236216,
@ -223,7 +227,6 @@ test('Albertina to Salzburg Hbf', co(function* (t) {
name: 'Albertina', name: 'Albertina',
id: '975900003' id: '975900003'
} }
const salzburgHbf = '8100002'
const journeys = yield client.journeys(albertina, salzburgHbf, {when}) const journeys = yield client.journeys(albertina, salzburgHbf, {when})
t.ok(Array.isArray(journeys)) t.ok(Array.isArray(journeys))
@ -255,9 +258,6 @@ test('Albertina to Salzburg Hbf', co(function* (t) {
})) }))
test('Wien to Klagenfurt Hbf with stopover at Salzburg Hbf', co(function* (t) { test('Wien to Klagenfurt Hbf with stopover at Salzburg Hbf', co(function* (t) {
const wien = '1190100'
const klagenfurtHbf = '8100085'
const salzburgHbf = '8100002'
const [journey] = yield client.journeys(wien, klagenfurtHbf, { const [journey] = yield client.journeys(wien, klagenfurtHbf, {
via: salzburgHbf, via: salzburgHbf,
results: 1, results: 1,
@ -274,9 +274,45 @@ test('Wien to Klagenfurt Hbf with stopover at Salzburg Hbf', co(function* (t) {
t.end() t.end()
})) }))
test('earlier/later journeys, Salzburg Hbf -> Wien Westbahnhof', co(function* (t) {
const model = yield client.journeys(salzburgHbf, wienWestbahnhof, {
results: 3, when
})
t.equal(typeof model.earlierJourneysRef, 'string')
t.ok(model.earlierJourneysRef)
t.equal(typeof model.laterJourneysRef, 'string')
t.ok(model.laterJourneysRef)
let earliestDep = Infinity, latestDep = -Infinity
for (let j of model) {
const dep = +new Date(j.departure)
if (dep < earliestDep) earliestDep = dep
else if (dep > latestDep) latestDep = dep
}
const earlier = yield client.journeys(salzburgHbf, wienWestbahnhof, {
results: 3,
// todo: single journey ref?
beforeJourneys: model.earlierJourneysRef
})
for (let j of earlier) {
t.ok(new Date(j.departure) < earliestDep)
}
const later = yield client.journeys(salzburgHbf, wienWestbahnhof, {
results: 3,
// todo: single journey ref?
afterJourneys: model.laterJourneysRef
})
for (let j of later) {
t.ok(new Date(j.departure) > latestDep)
}
t.end()
}))
test('leg details for Wien Westbahnhof to München Hbf', co(function* (t) { test('leg details for Wien Westbahnhof to München Hbf', co(function* (t) {
const wienWestbahnhof = '1291501'
const muenchenHbf = '8000261'
const journeys = yield client.journeys(wienWestbahnhof, muenchenHbf, { const journeys = yield client.journeys(wienWestbahnhof, muenchenHbf, {
results: 1, when results: 1, when
}) })
@ -301,7 +337,6 @@ test('leg details for Wien Westbahnhof to München Hbf', co(function* (t) {
})) }))
test('departures at Salzburg Hbf', co(function* (t) { test('departures at Salzburg Hbf', co(function* (t) {
const salzburgHbf = '8100002'
const deps = yield client.departures(salzburgHbf, { const deps = yield client.departures(salzburgHbf, {
duration: 5, when duration: 5, when
}) })
@ -365,7 +400,6 @@ test('locations named Salzburg', co(function* (t) {
})) }))
test('location', co(function* (t) { test('location', co(function* (t) {
const grazHbf = '8100173'
const loc = yield client.location(grazHbf) const loc = yield client.location(grazHbf)
assertValidStation(t, loc) assertValidStation(t, loc)