journeys from station to station test: use helper fn

This commit is contained in:
Jannis R 2018-04-23 13:56:00 +02:00
parent 279dfa4f8f
commit 63e303b6f8
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
6 changed files with 84 additions and 48 deletions

View file

@ -15,6 +15,7 @@ const {
station: createValidateStation
} = require('./lib/validators')
const createValidate = require('./lib/validate-fptf-with')
const testJourneysStationToStation = require('./lib/journeys-station-to-station')
const isObj = o => o !== null && 'object' === typeof o && !Array.isArray(o)
@ -60,18 +61,26 @@ const client = createClient(dbProfile)
const berlinHbf = '8011160'
const münchenHbf = '8000261'
const jungfernheide = '8011167'
const blnSchwedterStr = '732652'
const atze = '991598902'
const westhafen = '008089116'
const wedding = '008089131'
const württembergallee = '731084'
const regensburgHbf = '8000309'
test('Berlin Jungfernheide to München Hbf', co(function* (t) {
const journeys = yield client.journeys(jungfernheide, münchenHbf, {
when, passedStations: true
test('journeys  Berlin Schwedter Str. to München Hbf', co(function* (t) {
const journeys = yield client.journeys(blnSchwedterStr, münchenHbf, {
results: 3, when, passedStations: true
})
validate(t, journeys, 'journeys', 'journeys')
yield testJourneysStationToStation({
test: t,
journeys,
validate,
fromId: blnSchwedterStr,
toId: münchenHbf
})
// todo: find a journey where there pricing info is always available
for (let journey of journeys) {
if (journey.price) assertValidPrice(t, journey.price)
}

View file

@ -10,6 +10,7 @@ const createClient = require('..')
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 isObj = o => o !== null && 'object' === typeof o && !Array.isArray(o)
@ -32,20 +33,18 @@ const hasselbachplatzSternstrasse = '000006545'
const stendal = '008010334'
const dessau = '008010077'
test('Magdeburg Hbf to Magdeburg-Buckau', co(function*(t) {
test('journeys  Magdeburg Hbf to Magdeburg-Buckau', co(function* (t) {
const journeys = yield client.journeys(magdeburgHbf, magdeburgBuckau, {
when,
passedStations: true
results: 3, when, passedStations: true
})
validate(t, journeys, 'journeys', 'journeys')
for (let j of journeys) {
const firstLeg = j.legs[0]
const lastLeg = j.legs[j.legs.length - 1]
t.strictEqual(firstLeg.origin.id, magdeburgHbf)
t.strictEqual(lastLeg.destination.id, magdeburgBuckau)
}
yield testJourneysStationToStation({
test: t,
journeys,
validate,
fromId: magdeburgHbf,
toId: magdeburgBuckau
})
t.end()
}))

View file

@ -0,0 +1,20 @@
'use strict'
const co = require('./co')
const testJourneysStationToStation = co(function* (cfg) {
const {test: t, journeys, validate, fromId, toId} = cfg
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]
const lastLeg = j.legs[j.legs.length - 1]
t.strictEqual(firstLeg.origin.id, fromId)
t.strictEqual(lastLeg.destination.id, toId)
}
})
module.exports = testJourneysStationToStation

View file

@ -14,6 +14,7 @@ const {
station: createValidateStation
} = require('./lib/validators')
const createValidate = require('./lib/validate-fptf-with')
const testJourneysStationToStation = require('./lib/journeys-station-to-station')
const when = createWhen('Europe/Berlin', 'de-DE')
@ -60,24 +61,25 @@ const luebeckHbf = '8000237'
const husum = '8000181'
const schleswig = '8005362'
test('Kiel Hbf to Flensburg', co(function* (t) {
test('journeys  Kiel Hbf to Flensburg', co(function* (t) {
const journeys = yield client.journeys(kielHbf, flensburg, {
when, passedStations: true, results: 3
results: 3, when, passedStations: true
})
yield testJourneysStationToStation({
test: t,
journeys,
validate,
fromId: kielHbf,
toId: flensburg
})
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]
const lastLeg = j.legs[j.legs.length - 1]
t.strictEqual(firstLeg.origin.id, kielHbf)
t.strictEqual(lastLeg.destination.id, flensburg)
// todo: find a journey where there pricing info is always available
if (j.price) assertValidPrice(t, j.price)
if (j.price) assertValidPrice(t, j.price, `journeys[${i}].price`)
}
t.end()
}))

View file

@ -14,6 +14,7 @@ const {
station: createValidateStation
} = require('./lib/validators')
const createValidate = require('./lib/validate-fptf-with')
const testJourneysStationToStation = require('./lib/journeys-station-to-station')
const when = createWhen('Europe/Vienna', 'de-AT')
@ -45,20 +46,29 @@ const test = tapePromise(tape)
const client = createClient(oebbProfile)
const salzburgHbf = '8100002'
const wienWestbahnhof = '1291501'
const wienFickeystr = '911014'
const wien = '1190100'
const wienWestbahnhof = '1291501'
const klagenfurtHbf = '8100085'
const muenchenHbf = '8000261'
const wienRenngasse = '1390186'
test('Salzburg Hbf to Wien Westbahnhof', co(function* (t) {
const journeys = yield client.journeys(salzburgHbf, wienWestbahnhof, {
when, passedStations: true
test('journeys  Salzburg Hbf to Wien Westbahnhof', co(function* (t) {
const journeys = yield client.journeys(salzburgHbf, wienFickeystr, {
results: 3, when, passedStations: true
})
validate(t, journeys, 'journeys', 'journeys')
for (let journey of journeys) {
if (journey.price) assertValidPrice(t, journey.price)
yield testJourneysStationToStation({
test: t,
journeys,
validate,
fromId: salzburgHbf,
toId: wienFickeystr
})
for (let i = 0; i < journeys.length; i++) {
const j = journeys[i]
if (j.price) assertValidPrice(t, j.price, `journeys[${i}].price`)
}
t.end()

View file

@ -20,8 +20,7 @@ const {
movement: _validateMovement
} = require('./lib/validators')
const createValidate = require('./lib/validate-fptf-with')
const isObj = o => o !== null && 'object' === typeof o && !Array.isArray(o)
const testJourneysStationToStation = require('./lib/journeys-station-to-station')
const when = createWhen('Europe/Berlin', 'de-DE')
@ -106,23 +105,20 @@ const württembergallee = '900000026153'
const berlinerStr = '900000044201'
const landhausstr = '900000043252'
test('journeys  station to station', co(function* (t) {
const journeys = yield client.journeys(spichernstr, amrumerStr, {
test('journeys  Spichernstr. to Bismarckstr.', co(function* (t) {
const journeys = yield client.journeys(spichernstr, bismarckstr, {
results: 3, when, passedStations: true
})
validate(t, journeys, 'journeys', 'journeys')
t.strictEqual(journeys.length, 3)
for (let i = 0; i < journeys.length; i++) {
const j = journeys[i]
yield testJourneysStationToStation({
test: t,
journeys,
validate,
fromId: spichernstr,
toId: bismarckstr
})
// todo: find a journey where there ticket info is always available
const firstLeg = j.legs[0]
const lastLeg = j.legs[j.legs.length - 1]
t.strictEqual(firstLeg.origin.id, spichernstr)
t.strictEqual(lastLeg.destination.id, amrumerStr)
// todo: find a journey where there ticket info is always available
}
t.end()
}))