mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
journeys from station to address tests: use helper fn
This commit is contained in:
parent
6818635ee4
commit
1018369576
6 changed files with 100 additions and 70 deletions
34
test/db.js
34
test/db.js
|
@ -16,6 +16,7 @@ const {
|
|||
} = require('./lib/validators')
|
||||
const createValidate = require('./lib/validate-fptf-with')
|
||||
const testJourneysStationToStation = require('./lib/journeys-station-to-station')
|
||||
const testJourneysStationToAddress = require('./lib/journeys-station-to-address')
|
||||
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
|
||||
|
||||
const isObj = o => o !== null && 'object' === typeof o && !Array.isArray(o)
|
||||
|
@ -92,23 +93,24 @@ test('journeys – Berlin Schwedter Str. to München Hbf', co(function* (t) {
|
|||
// todo: journeys, only one product
|
||||
// todo: journeys, fails with no product
|
||||
|
||||
test('Berlin Jungfernheide to Torfstraße 17', co(function* (t) {
|
||||
const latitude = 52.5416823
|
||||
const longitude = 13.3491223
|
||||
const journeys = yield client.journeys(jungfernheide, {
|
||||
type: 'location', address: 'Torfstraße 17',
|
||||
latitude, longitude
|
||||
}, {when})
|
||||
|
||||
validate(t, journeys, 'journeys', 'journeys')
|
||||
|
||||
const i = journeys[0].legs.length - 1
|
||||
const d = journeys[0].legs[i].destination
|
||||
const name = `journeys[0].legs[${i}].destination`
|
||||
t.equal(d.address, 'Torfstraße 17', name + '.address is invalid')
|
||||
t.ok(isRoughlyEqual(.0001, d.latitude, latitude), name + '.latitude is invalid')
|
||||
t.ok(isRoughlyEqual(.0001, d.longitude, longitude), name + '.longitude is invalid')
|
||||
test('Berlin Schwedter Str. to Torfstraße 17', co(function* (t) {
|
||||
const torfstr = {
|
||||
type: 'location',
|
||||
address: 'Torfstraße 17',
|
||||
latitude: 52.5416823,
|
||||
longitude: 13.3491223
|
||||
}
|
||||
const journeys = yield client.journeys(blnSchwedterStr, torfstr, {
|
||||
results: 3, when
|
||||
})
|
||||
|
||||
yield testJourneysStationToAddress({
|
||||
test: t,
|
||||
journeys,
|
||||
validate,
|
||||
fromId: blnSchwedterStr,
|
||||
to: torfstr
|
||||
})
|
||||
t.end()
|
||||
}))
|
||||
|
||||
|
|
22
test/insa.js
22
test/insa.js
|
@ -11,6 +11,7 @@ const insaProfile = require('../p/insa')
|
|||
const products = require('../p/insa/products')
|
||||
const createValidate = require('./lib/validate-fptf-with')
|
||||
const testJourneysStationToStation = require('./lib/journeys-station-to-station')
|
||||
const testJourneysStationToAddress = require('./lib/journeys-station-to-address')
|
||||
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
|
||||
|
||||
const isObj = o => o !== null && 'object' === typeof o && !Array.isArray(o)
|
||||
|
@ -55,23 +56,22 @@ test('journeys – Magdeburg Hbf to Magdeburg-Buckau', co(function* (t) {
|
|||
test('Magdeburg Hbf to 39104 Magdeburg, Sternstr. 10', co(function*(t) {
|
||||
const sternStr = {
|
||||
type: 'location',
|
||||
address: 'Magdeburg - Altenstadt, Sternstraße 10',
|
||||
latitude: 52.118414,
|
||||
longitude: 11.422332,
|
||||
address: 'Magdeburg - Altenstadt, Sternstraße 10'
|
||||
longitude: 11.422332
|
||||
}
|
||||
|
||||
const journeys = yield client.journeys(magdeburgHbf, sternStr, {
|
||||
when
|
||||
results: 3, when
|
||||
})
|
||||
validate(t, journeys, 'journeys', 'journeys')
|
||||
|
||||
for (let journey of journeys) {
|
||||
const i = journey.legs.length - 1
|
||||
const d = journey.legs[i].destination
|
||||
t.equal(d.address, sternStr.address)
|
||||
t.ok(isRoughlyEqual(0.0001, d.latitude, sternStr.latitude))
|
||||
t.ok(isRoughlyEqual(0.0001, d.longitude, sternStr.longitude))
|
||||
}
|
||||
yield testJourneysStationToAddress({
|
||||
test: t,
|
||||
journeys,
|
||||
validate,
|
||||
fromId: magdeburgHbf,
|
||||
to: sternStr
|
||||
})
|
||||
t.end()
|
||||
}))
|
||||
|
||||
|
|
29
test/lib/journeys-station-to-address.js
Normal file
29
test/lib/journeys-station-to-address.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
'use strict'
|
||||
|
||||
const isRoughlyEqual = require('is-roughly-equal')
|
||||
|
||||
const co = require('./co')
|
||||
|
||||
const testJourneysStationToAddress = co(function* (cfg) {
|
||||
const {test: t, journeys, validate, fromId} = cfg
|
||||
const {address, latitude, longitude} = cfg.to
|
||||
|
||||
validate(t, journeys, 'journeys', 'journeys')
|
||||
t.strictEqual(journeys.length, 3)
|
||||
for (let i = 0; i < journeys.length; i++) {
|
||||
const j = journeys[i]
|
||||
|
||||
const firstLeg = j.legs[0]
|
||||
t.strictEqual(firstLeg.origin.id, fromId)
|
||||
|
||||
const d = j.legs[j.legs.length - 1].destination
|
||||
const n = `journeys[0].legs[${i}].destination`
|
||||
|
||||
t.strictEqual(d.type, 'location', n + '.type is invalid')
|
||||
t.strictEqual(d.address, address, n + '.address is invalid')
|
||||
t.ok(isRoughlyEqual(.0001, d.latitude, latitude), n + '.latitude is invalid')
|
||||
t.ok(isRoughlyEqual(.0001, d.longitude, longitude), n + '.longitude is invalid')
|
||||
}
|
||||
})
|
||||
|
||||
module.exports = testJourneysStationToAddress
|
|
@ -15,6 +15,7 @@ const {
|
|||
} = require('./lib/validators')
|
||||
const createValidate = require('./lib/validate-fptf-with')
|
||||
const testJourneysStationToStation = require('./lib/journeys-station-to-station')
|
||||
const testJourneysStationToAddress = require('./lib/journeys-station-to-address')
|
||||
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
|
||||
|
||||
const when = createWhen('Europe/Berlin', 'de-DE')
|
||||
|
@ -88,25 +89,23 @@ test('journeys – Kiel Hbf to Flensburg', co(function* (t) {
|
|||
// todo: journeys, fails with no product
|
||||
|
||||
test('Kiel Hbf to Husum, Zingel 10', co(function* (t) {
|
||||
const latitude = 54.475359
|
||||
const longitude = 9.050798
|
||||
const zingel = {
|
||||
type: 'location',
|
||||
address: 'Husum, Zingel 10',
|
||||
latitude, longitude
|
||||
latitude: 54.475359,
|
||||
longitude: 9.050798
|
||||
}
|
||||
const journeys = yield client.journeys(kielHbf, zingel, {when})
|
||||
|
||||
validate(t, journeys, 'journeys', 'journeys')
|
||||
|
||||
const i = journeys[0].legs.length - 1
|
||||
const d = journeys[0].legs[i].destination
|
||||
const name = `journeys[0].legs[${i}].destination`
|
||||
|
||||
t.strictEqual(d.address, 'Husum, Zingel 10', name + '.address is invalid')
|
||||
t.ok(isRoughlyEqual(.0001, d.latitude, latitude), name + '.latitude is invalid')
|
||||
t.ok(isRoughlyEqual(.0001, d.longitude, longitude), name + '.longitude is invalid')
|
||||
const journeys = yield client.journeys(kielHbf, zingel, {
|
||||
results: 3, when
|
||||
})
|
||||
|
||||
yield testJourneysStationToAddress({
|
||||
test: t,
|
||||
journeys,
|
||||
validate,
|
||||
fromId: kielHbf,
|
||||
to: zingel
|
||||
})
|
||||
t.end()
|
||||
}))
|
||||
|
||||
|
|
26
test/oebb.js
26
test/oebb.js
|
@ -15,6 +15,7 @@ const {
|
|||
} = require('./lib/validators')
|
||||
const createValidate = require('./lib/validate-fptf-with')
|
||||
const testJourneysStationToStation = require('./lib/journeys-station-to-station')
|
||||
const testJourneysStationToAddress = require('./lib/journeys-station-to-address')
|
||||
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
|
||||
|
||||
const when = createWhen('Europe/Vienna', 'de-AT')
|
||||
|
@ -79,24 +80,23 @@ test('journeys – Salzburg Hbf to Wien Westbahnhof', co(function* (t) {
|
|||
// todo: journeys, fails with no product
|
||||
|
||||
test('Salzburg Hbf to 1220 Wien, Wagramer Straße 5', co(function* (t) {
|
||||
const latitude = 48.236216
|
||||
const longitude = 16.425863
|
||||
const wagramerStr = {
|
||||
type: 'location',
|
||||
address: '1220 Wien, Wagramer Straße 5',
|
||||
latitude, longitude
|
||||
latitude: 48.236216,
|
||||
longitude: 16.425863
|
||||
}
|
||||
const journeys = yield client.journeys(salzburgHbf, wagramerStr, {when})
|
||||
|
||||
validate(t, journeys, 'journeys', 'journeys')
|
||||
|
||||
const i = journeys[0].legs.length - 1
|
||||
const d = journeys[0].legs[i].destination
|
||||
const k = `journeys[0].legs[${i}].destination`
|
||||
t.equal(d.address, '1220 Wien, Wagramer Straße 5', k + '.address is invalid')
|
||||
t.ok(isRoughlyEqual(.0001, d.latitude, latitude), k + '.latitude is invalid')
|
||||
t.ok(isRoughlyEqual(.0001, d.longitude, longitude), k + '.longitude is invalid')
|
||||
const journeys = yield client.journeys(salzburgHbf, wagramerStr, {
|
||||
results: 3, when
|
||||
})
|
||||
|
||||
yield testJourneysStationToAddress({
|
||||
test: t,
|
||||
journeys,
|
||||
validate,
|
||||
fromId: salzburgHbf,
|
||||
to: wagramerStr
|
||||
})
|
||||
t.end()
|
||||
}))
|
||||
|
||||
|
|
32
test/vbb.js
32
test/vbb.js
|
@ -21,6 +21,7 @@ const {
|
|||
} = require('./lib/validators')
|
||||
const createValidate = require('./lib/validate-fptf-with')
|
||||
const testJourneysStationToStation = require('./lib/journeys-station-to-station')
|
||||
const testJourneysStationToAddress = require('./lib/journeys-station-to-address')
|
||||
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
|
||||
|
||||
const when = createWhen('Europe/Berlin', 'de-DE')
|
||||
|
@ -207,24 +208,23 @@ test('journey leg details', co(function* (t) {
|
|||
}))
|
||||
|
||||
test('journeys – station to address', co(function* (t) {
|
||||
const latitude = 52.541797
|
||||
const longitude = 13.350042
|
||||
const journeys = yield client.journeys(spichernstr, {
|
||||
const torfstr = {
|
||||
type: 'location',
|
||||
address: 'Torfstr. 17, Berlin',
|
||||
latitude, longitude
|
||||
}, {results: 1, when})
|
||||
|
||||
validate(t, journeys, 'journeys', 'journeys')
|
||||
|
||||
const i = journeys[0].legs.length - 1
|
||||
const d = journeys[0].legs[i].destination
|
||||
const name = `journeys[0].legs[${i}].destination`
|
||||
|
||||
t.strictEqual(d.address, '13353 Berlin-Wedding, Torfstr. 17', name + '.address is invalid')
|
||||
t.ok(isRoughlyEqual(.0001, d.latitude, latitude), name + '.latitude is invalid')
|
||||
t.ok(isRoughlyEqual(.0001, d.longitude, longitude), name + '.longitude is invalid')
|
||||
address: '13353 Berlin-Wedding, Torfstr. 17',
|
||||
latitude: 52.541797,
|
||||
longitude: 13.350042
|
||||
}
|
||||
const journeys = yield client.journeys(spichernstr, torfstr, {
|
||||
results: 3, when
|
||||
})
|
||||
|
||||
yield testJourneysStationToAddress({
|
||||
test: t,
|
||||
journeys,
|
||||
validate,
|
||||
fromId: spichernstr,
|
||||
to: torfstr
|
||||
})
|
||||
t.end()
|
||||
}))
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue