tests: move assertValidStationProducts into assertValidStation

This commit is contained in:
Jannis R 2018-04-18 15:53:08 +02:00
parent 3680f1fe94
commit 41b574c468
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
5 changed files with 56 additions and 150 deletions

View file

@ -10,7 +10,7 @@ const createClient = require('..')
const dbProfile = require('../p/db') const dbProfile = require('../p/db')
const allProducts = require('../p/db/products') const allProducts = require('../p/db/products')
const { const {
assertValidStation, assertValidStation: _assertValidStation,
assertValidPoi, assertValidPoi,
assertValidAddress, assertValidAddress,
assertValidLocation, assertValidLocation,
@ -21,18 +21,15 @@ const {
const when = createWhen('Europe/Berlin', 'de-DE') const when = createWhen('Europe/Berlin', 'de-DE')
const assertValidStationProducts = (t, p) => { // todo: DRY with other tests, move into lib
t.ok(p) const assertValidStation = (t, s) => {
t.equal(typeof p.nationalExp, 'boolean') _assertValidStation(t, s)
t.equal(typeof p.national, 'boolean') t.ok(s.products)
t.equal(typeof p.regionalExp, 'boolean') for (let product of allProducts) {
t.equal(typeof p.regional, 'boolean') product = product.id
t.equal(typeof p.suburban, 'boolean') const msg = `station.products[${product}] must be a boolean`
t.equal(typeof p.bus, 'boolean') t.equal(typeof s.products[product], 'boolean', msg)
t.equal(typeof p.ferry, 'boolean') }
t.equal(typeof p.subway, 'boolean')
t.equal(typeof p.tram, 'boolean')
t.equal(typeof p.taxi, 'boolean')
} }
const findStation = (id) => new Promise((yay, nay) => { const findStation = (id) => new Promise((yay, nay) => {
@ -69,15 +66,6 @@ const assertIsJungfernheide = (t, s) => {
t.ok(isRoughlyEqual(s.location.longitude, 13.299424, .0005)) t.ok(isRoughlyEqual(s.location.longitude, 13.299424, .0005))
} }
// todo: DRY with assertValidStationProducts
// todo: DRY with other tests
const assertValidProducts = (t, p) => {
for (let product of allProducts) {
product = product.id
t.equal(typeof p[product], 'boolean', 'product ' + p + ' must be a boolean')
}
}
const assertValidPrice = (t, p) => { const assertValidPrice = (t, p) => {
t.ok(p) t.ok(p)
if (p.amount !== null) { if (p.amount !== null) {
@ -114,7 +102,6 @@ test('Berlin Jungfernheide to München Hbf', co(function* (t) {
const leg = journey.legs[0] // todo: all legs const leg = journey.legs[0] // todo: all legs
assertValidStation(t, leg.origin) assertValidStation(t, leg.origin)
assertValidStationProducts(t, leg.origin.products)
if (!(yield findStation(leg.origin.id))) { if (!(yield findStation(leg.origin.id))) {
console.error('unknown station', leg.origin.id, leg.origin.name) console.error('unknown station', leg.origin.id, leg.origin.name)
} }
@ -122,7 +109,6 @@ test('Berlin Jungfernheide to München Hbf', co(function* (t) {
t.equal(typeof leg.departurePlatform, 'string') t.equal(typeof leg.departurePlatform, 'string')
assertValidStation(t, leg.destination) assertValidStation(t, leg.destination)
assertValidStationProducts(t, leg.origin.products)
if (!(yield findStation(leg.destination.id))) { if (!(yield findStation(leg.destination.id))) {
console.error('unknown station', leg.destination.id, leg.destination.name) console.error('unknown station', leg.destination.id, leg.destination.name)
} }
@ -152,11 +138,9 @@ test('Berlin Jungfernheide to Torfstraße 17', co(function* (t) {
const leg = journey.legs[journey.legs.length - 1] const leg = journey.legs[journey.legs.length - 1]
assertValidStation(t, leg.origin) assertValidStation(t, leg.origin)
assertValidStationProducts(t, leg.origin.products)
if (!(yield findStation(leg.origin.id))) { if (!(yield findStation(leg.origin.id))) {
console.error('unknown station', leg.origin.id, leg.origin.name) console.error('unknown station', leg.origin.id, leg.origin.name)
} }
if (leg.origin.products) assertValidProducts(t, leg.origin.products)
assertValidWhen(t, leg.departure, when) assertValidWhen(t, leg.departure, when)
assertValidWhen(t, leg.arrival, when) assertValidWhen(t, leg.arrival, when)
@ -181,11 +165,9 @@ test('Berlin Jungfernheide to ATZE Musiktheater', co(function* (t) {
const leg = journey.legs[journey.legs.length - 1] const leg = journey.legs[journey.legs.length - 1]
assertValidStation(t, leg.origin) assertValidStation(t, leg.origin)
assertValidStationProducts(t, leg.origin.products)
if (!(yield findStation(leg.origin.id))) { if (!(yield findStation(leg.origin.id))) {
console.error('unknown station', leg.origin.id, leg.origin.name) console.error('unknown station', leg.origin.id, leg.origin.name)
} }
if (leg.origin.products) assertValidProducts(t, leg.origin.products)
assertValidWhen(t, leg.departure, when) assertValidWhen(t, leg.departure, when)
assertValidWhen(t, leg.arrival, when) assertValidWhen(t, leg.arrival, when)
@ -298,11 +280,9 @@ test('departures at Berlin Jungfernheide', co(function* (t) {
t.ok(Array.isArray(deps)) t.ok(Array.isArray(deps))
for (let dep of deps) { for (let dep of deps) {
assertValidStation(t, dep.station) assertValidStation(t, dep.station)
assertValidStationProducts(t, dep.station.products)
if (!(yield findStation(dep.station.id))) { if (!(yield findStation(dep.station.id))) {
console.error('unknown station', dep.station.id, dep.station.name) console.error('unknown station', dep.station.id, dep.station.name)
} }
if (dep.station.products) assertValidProducts(t, dep.station.products)
assertValidWhen(t, dep.when, when) assertValidWhen(t, dep.when, when)
} }

View file

@ -10,7 +10,7 @@ const createClient = require('..')
const insaProfile = require('../p/insa') const insaProfile = require('../p/insa')
const allProducts = require('../p/insa/products') const allProducts = require('../p/insa/products')
const { const {
assertValidStation, assertValidStation: _assertValidStation,
assertValidPoi, assertValidPoi,
assertValidAddress, assertValidAddress,
assertValidLocation, assertValidLocation,
@ -23,15 +23,15 @@ const {
const when = createWhen('Europe/Berlin', 'de-DE') const when = createWhen('Europe/Berlin', 'de-DE')
const assertValidStationProducts = (t, p) => { // todo: DRY with other tests, move into lib
t.ok(p) const assertValidStation = (t, s, coordsOptional = false) => {
t.equal(typeof p.nationalExp, 'boolean') _assertValidStation(t, s, coordsOptional)
t.equal(typeof p.national, 'boolean') t.ok(s.products)
t.equal(typeof p.regional, 'boolean') for (let product of allProducts) {
t.equal(typeof p.suburban, 'boolean') product = product.id
t.equal(typeof p.tram, 'boolean') const msg = `station.products[${product}] must be a boolean`
t.equal(typeof p.bus, 'boolean') t.equal(typeof s.products[product], 'boolean', msg)
t.equal(typeof p.tourismTrain, 'boolean') }
} }
const isMagdeburgHbf = s => { const isMagdeburgHbf = s => {
@ -54,15 +54,6 @@ const assertIsMagdeburgHbf = (t, s) => {
t.ok(isRoughlyEqual(s.location.longitude, 11.626891, 0.001)) t.ok(isRoughlyEqual(s.location.longitude, 11.626891, 0.001))
} }
// todo: DRY with assertValidStationProducts
// todo: DRY with other tests
const assertValidProducts = (t, p) => {
for (let product of allProducts) {
product = product.id
t.equal(typeof p[product], 'boolean', 'product ' + p + ' must be a boolean')
}
}
const test = tapePromise(tape) const test = tapePromise(tape)
const client = createClient(insaProfile) const client = createClient(insaProfile)
@ -82,12 +73,10 @@ test('Magdeburg Hbf to Magdeburg-Buckau', co(function*(t) {
const leg = journey.legs[0] // todo: all legs const leg = journey.legs[0] // todo: all legs
assertValidStation(t, leg.origin) assertValidStation(t, leg.origin)
assertValidStationProducts(t, leg.origin.products)
assertValidWhen(t, leg.departure, when) assertValidWhen(t, leg.departure, when)
t.equal(typeof leg.departurePlatform, 'string') t.equal(typeof leg.departurePlatform, 'string')
assertValidStation(t, leg.destination) assertValidStation(t, leg.destination)
assertValidStationProducts(t, leg.origin.products)
assertValidWhen(t, leg.arrival, when) assertValidWhen(t, leg.arrival, when)
t.equal(typeof leg.arrivalPlatform, 'string') t.equal(typeof leg.arrivalPlatform, 'string')
@ -120,9 +109,6 @@ test('Magdeburg Hbf to 39104 Magdeburg, Sternstr. 10', co(function*(t) {
const lastLeg = journey.legs[journey.legs.length - 1] const lastLeg = journey.legs[journey.legs.length - 1]
assertValidStation(t, firstLeg.origin) assertValidStation(t, firstLeg.origin)
assertValidStationProducts(t, firstLeg.origin.products)
if (firstLeg.origin.products)
assertValidProducts(t, firstLeg.origin.products)
assertValidWhen(t, firstLeg.departure, when) assertValidWhen(t, firstLeg.departure, when)
assertValidWhen(t, firstLeg.arrival, when) assertValidWhen(t, firstLeg.arrival, when)
assertValidWhen(t, lastLeg.departure, when) assertValidWhen(t, lastLeg.departure, when)
@ -168,9 +154,6 @@ test('Kloster Unser Lieben Frauen to Magdeburg Hbf', co(function*(t) {
assertValidWhen(t, lastLeg.arrival, when) assertValidWhen(t, lastLeg.arrival, when)
assertValidStation(t, lastLeg.destination) assertValidStation(t, lastLeg.destination)
assertValidStationProducts(t, lastLeg.destination.products)
if (lastLeg.destination.products)
assertValidProducts(t, lastLeg.destination.products)
t.end() t.end()
})) }))
@ -230,10 +213,6 @@ test('departures at Magdeburg Hbf', co(function*(t) {
t.ok(Array.isArray(deps)) t.ok(Array.isArray(deps))
for (let dep of deps) { for (let dep of deps) {
assertValidStation(t, dep.station) assertValidStation(t, dep.station)
assertValidStationProducts(t, dep.station.products)
if (dep.station.products) {
assertValidProducts(t, dep.station.products)
}
assertValidWhen(t, dep.when, when) assertValidWhen(t, dep.when, when)
} }
@ -366,9 +345,7 @@ test('radar', co(function* (t) {
// see #28 // see #28
// todo: check if this works by now // todo: check if this works by now
assertValidStation(t, f.origin, true) assertValidStation(t, f.origin, true)
assertValidStationProducts(t, f.origin.products)
assertValidStation(t, f.destination, true) assertValidStation(t, f.destination, true)
assertValidStationProducts(t, f.destination.products)
t.equal(typeof f.t, 'number') t.equal(typeof f.t, 'number')
} }
} }

View file

@ -14,7 +14,7 @@ const createClient = require('..')
const nahshProfile = require('../p/nahsh') const nahshProfile = require('../p/nahsh')
const allProducts = require('../p/nahsh/products') const allProducts = require('../p/nahsh/products')
const { const {
assertValidStation, assertValidStation: _assertValidStation,
assertValidPoi, assertValidPoi,
assertValidAddress, assertValidAddress,
assertValidLocation, assertValidLocation,
@ -24,18 +24,15 @@ const {
const when = createWhen('Europe/Berlin', 'de-DE') const when = createWhen('Europe/Berlin', 'de-DE')
const assertValidStationProducts = (t, p) => { // todo: DRY with other tests, move into lib
t.ok(p) const assertValidStation = (t, s, coordsOptional = false) => {
t.equal(typeof p.nationalExp, 'boolean') _assertValidStation(t, s, coordsOptional)
t.equal(typeof p.national, 'boolean') t.ok(s.products)
t.equal(typeof p.interregional, 'boolean') for (let product of allProducts) {
t.equal(typeof p.regional, 'boolean') product = product.id
t.equal(typeof p.suburban, 'boolean') const msg = `station.products[${product}] must be a boolean`
t.equal(typeof p.bus, 'boolean') t.equal(typeof s.products[product], 'boolean', msg)
t.equal(typeof p.ferry, 'boolean') }
t.equal(typeof p.subway, 'boolean')
t.equal(typeof p.tram, 'boolean')
t.equal(typeof p.onCall, 'boolean')
} }
const isKielHbf = (s) => { const isKielHbf = (s) => {
@ -56,15 +53,6 @@ const assertIsKielHbf = (t, s) => {
t.ok(isRoughlyEqual(s.location.longitude, 10.131976, .0005)) t.ok(isRoughlyEqual(s.location.longitude, 10.131976, .0005))
} }
// todo: DRY with assertValidStationProducts
// todo: DRY with other tests
const assertValidProducts = (t, p) => {
for (let product of allProducts) {
product = product.product // wat
t.equal(typeof p[product], 'boolean', 'product ' + p + ' must be a boolean')
}
}
const assertValidPrice = (t, p) => { const assertValidPrice = (t, p) => {
t.ok(p) t.ok(p)
if (p.amount !== null) { if (p.amount !== null) {
@ -113,7 +101,6 @@ test('Kiel Hbf to Flensburg', co(function* (t) {
const leg = journey.legs[0] // todo: all legs const leg = journey.legs[0] // todo: all legs
assertValidStation(t, leg.origin) assertValidStation(t, leg.origin)
assertValidStationProducts(t, leg.origin.products)
// todo // todo
// if (!(yield findStation(leg.origin.id))) { // if (!(yield findStation(leg.origin.id))) {
// console.error('unknown station', leg.origin.id, leg.origin.name) // console.error('unknown station', leg.origin.id, leg.origin.name)
@ -122,7 +109,6 @@ test('Kiel Hbf to Flensburg', co(function* (t) {
t.equal(typeof leg.departurePlatform, 'string') t.equal(typeof leg.departurePlatform, 'string')
assertValidStation(t, leg.destination) assertValidStation(t, leg.destination)
assertValidStationProducts(t, leg.origin.products)
// todo // todo
// if (!(yield findStation(leg.destination.id))) { // if (!(yield findStation(leg.destination.id))) {
// console.error('unknown station', leg.destination.id, leg.destination.name) // console.error('unknown station', leg.destination.id, leg.destination.name)
@ -158,12 +144,10 @@ test('Kiel Hbf to Husum, Zingel 10', co(function* (t) {
const lastLeg = journey.legs[journey.legs.length - 1] const lastLeg = journey.legs[journey.legs.length - 1]
assertValidStation(t, firstLeg.origin) assertValidStation(t, firstLeg.origin)
assertValidStationProducts(t, firstLeg.origin.products)
// todo // todo
// if (!(yield findStation(leg.origin.id))) { // if (!(yield findStation(leg.origin.id))) {
// console.error('unknown station', leg.origin.id, leg.origin.name) // console.error('unknown station', leg.origin.id, leg.origin.name)
// } // }
if (firstLeg.origin.products) assertValidProducts(t, firstLeg.origin.products)
assertValidWhen(t, firstLeg.departure, when) assertValidWhen(t, firstLeg.departure, when)
assertValidWhen(t, firstLeg.arrival, when) assertValidWhen(t, firstLeg.arrival, when)
assertValidWhen(t, lastLeg.departure, when) assertValidWhen(t, lastLeg.departure, when)
@ -206,8 +190,6 @@ test('Holstentor to Kiel Hbf', co(function* (t) {
assertValidWhen(t, lastLeg.arrival, when) assertValidWhen(t, lastLeg.arrival, when)
assertValidStation(t, lastLeg.destination) assertValidStation(t, lastLeg.destination)
assertValidStationProducts(t, lastLeg.destination.products)
if (lastLeg.destination.products) assertValidProducts(t, lastLeg.destination.products)
// todo // todo
// if (!(yield findStation(leg.destination.id))) { // if (!(yield findStation(leg.destination.id))) {
// console.error('unknown station', leg.destination.id, leg.destination.name) // console.error('unknown station', leg.destination.id, leg.destination.name)
@ -315,12 +297,10 @@ test('departures at Kiel Hbf', co(function* (t) {
t.ok(Array.isArray(deps)) t.ok(Array.isArray(deps))
for (let dep of deps) { for (let dep of deps) {
assertValidStation(t, dep.station) assertValidStation(t, dep.station)
assertValidStationProducts(t, dep.station.products)
// todo // todo
// if (!(yield findStation(dep.station.id))) { // if (!(yield findStation(dep.station.id))) {
// console.error('unknown station', dep.station.id, dep.station.name) // console.error('unknown station', dep.station.id, dep.station.name)
// } // }
if (dep.station.products) assertValidProducts(t, dep.station.products)
assertValidWhen(t, dep.when, when) assertValidWhen(t, dep.when, when)
} }
@ -420,9 +400,7 @@ test.skip('radar Kiel', co(function* (t) {
t.ok(Array.isArray(v.frames)) t.ok(Array.isArray(v.frames))
for (let f of v.frames) { for (let f of v.frames) {
assertValidStation(t, f.origin, true) assertValidStation(t, f.origin, true)
assertValidStationProducts(t, f.origin.products)
assertValidStation(t, f.destination, true) assertValidStation(t, f.destination, true)
assertValidStationProducts(t, f.destination.products)
t.equal(typeof f.t, 'number') t.equal(typeof f.t, 'number')
} }
} }

View file

@ -14,7 +14,7 @@ const createClient = require('..')
const oebbProfile = require('../p/oebb') const oebbProfile = require('../p/oebb')
const allProducts = require('../p/oebb/products') const allProducts = require('../p/oebb/products')
const { const {
assertValidStation, assertValidStation: _assertValidStation,
assertValidPoi, assertValidPoi,
assertValidAddress, assertValidAddress,
assertValidLocation, assertValidLocation,
@ -24,18 +24,17 @@ const {
const when = createWhen('Europe/Vienna', 'de-AT') const when = createWhen('Europe/Vienna', 'de-AT')
const assertValidStationProducts = (t, p) => { // todo: DRY with other tests, move into lib
t.ok(p) const assertValidStation = (t, s, coordsOptional = false, productsOptional = false) => {
t.equal(typeof p.nationalExp, 'boolean') _assertValidStation(t, s, coordsOptional)
t.equal(typeof p.national, 'boolean') if (s.products || !productsOptional) {
t.equal(typeof p.interregional, 'boolean') t.ok(s.products)
t.equal(typeof p.regional, 'boolean') for (let product of allProducts) {
t.equal(typeof p.suburban, 'boolean') product = product.id
t.equal(typeof p.bus, 'boolean') const msg = `station.products[${product}] must be a boolean`
t.equal(typeof p.ferry, 'boolean') t.equal(typeof s.products[product], 'boolean', msg)
t.equal(typeof p.subway, 'boolean') }
t.equal(typeof p.tram, 'boolean') }
t.equal(typeof p.onCall, 'boolean')
} }
// todo // todo
@ -73,15 +72,6 @@ const assertIsSalzburgHbf = (t, s) => {
t.ok(isRoughlyEqual(s.location.longitude, 13.045604, .0005)) t.ok(isRoughlyEqual(s.location.longitude, 13.045604, .0005))
} }
// todo: DRY with assertValidStationProducts
// todo: DRY with other tests
const assertValidProducts = (t, p) => {
for (let product of allProducts) {
product = product.id
t.equal(typeof p[product], 'boolean', 'product ' + p + ' must be a boolean')
}
}
const assertValidPrice = (t, p) => { const assertValidPrice = (t, p) => {
t.ok(p) t.ok(p)
if (p.amount !== null) { if (p.amount !== null) {
@ -133,7 +123,6 @@ test('Salzburg Hbf to Wien Westbahnhof', co(function* (t) {
const leg = journey.legs[0] // todo: all legs const leg = journey.legs[0] // todo: all legs
assertValidStation(t, leg.origin) assertValidStation(t, leg.origin)
assertValidStationProducts(t, leg.origin.products)
// todo // todo
// if (!(yield findStation(leg.origin.id))) { // if (!(yield findStation(leg.origin.id))) {
// console.error('unknown station', leg.origin.id, leg.origin.name) // console.error('unknown station', leg.origin.id, leg.origin.name)
@ -142,7 +131,6 @@ test('Salzburg Hbf to Wien Westbahnhof', co(function* (t) {
t.equal(typeof leg.departurePlatform, 'string') t.equal(typeof leg.departurePlatform, 'string')
assertValidStation(t, leg.destination) assertValidStation(t, leg.destination)
assertValidStationProducts(t, leg.origin.products)
// todo // todo
// if (!(yield findStation(leg.destination.id))) { // if (!(yield findStation(leg.destination.id))) {
// console.error('unknown station', leg.destination.id, leg.destination.name) // console.error('unknown station', leg.destination.id, leg.destination.name)
@ -178,12 +166,10 @@ test('Salzburg Hbf to 1220 Wien, Wagramer Straße 5', co(function* (t) {
const lastLeg = journey.legs[journey.legs.length - 1] const lastLeg = journey.legs[journey.legs.length - 1]
assertValidStation(t, firstLeg.origin) assertValidStation(t, firstLeg.origin)
assertValidStationProducts(t, firstLeg.origin.products)
// todo // todo
// if (!(yield findStation(leg.origin.id))) { // if (!(yield findStation(leg.origin.id))) {
// console.error('unknown station', leg.origin.id, leg.origin.name) // console.error('unknown station', leg.origin.id, leg.origin.name)
// } // }
if (firstLeg.origin.products) assertValidProducts(t, firstLeg.origin.products)
assertValidWhen(t, firstLeg.departure, when) assertValidWhen(t, firstLeg.departure, when)
assertValidWhen(t, firstLeg.arrival, when) assertValidWhen(t, firstLeg.arrival, when)
assertValidWhen(t, lastLeg.departure, when) assertValidWhen(t, lastLeg.departure, when)
@ -226,8 +212,6 @@ test('Albertina to Salzburg Hbf', co(function* (t) {
assertValidWhen(t, lastLeg.arrival, when) assertValidWhen(t, lastLeg.arrival, when)
assertValidStation(t, lastLeg.destination) assertValidStation(t, lastLeg.destination)
assertValidStationProducts(t, lastLeg.destination.products)
if (lastLeg.destination.products) assertValidProducts(t, lastLeg.destination.products)
// todo // todo
// if (!(yield findStation(leg.destination.id))) { // if (!(yield findStation(leg.destination.id))) {
// console.error('unknown station', leg.destination.id, leg.destination.name) // console.error('unknown station', leg.destination.id, leg.destination.name)
@ -363,12 +347,10 @@ test('departures at Salzburg Hbf', co(function* (t) {
t.ok(Array.isArray(deps)) t.ok(Array.isArray(deps))
for (let dep of deps) { for (let dep of deps) {
assertValidStation(t, dep.station) assertValidStation(t, dep.station)
assertValidStationProducts(t, dep.station.products)
// todo // todo
// if (!(yield findStation(dep.station.id))) { // if (!(yield findStation(dep.station.id))) {
// console.error('unknown station', dep.station.id, dep.station.name) // console.error('unknown station', dep.station.id, dep.station.name)
// } // }
if (dep.station.products) assertValidProducts(t, dep.station.products)
assertValidWhen(t, dep.when, when) assertValidWhen(t, dep.when, when)
} }
@ -421,7 +403,8 @@ test('locations named Salzburg', co(function* (t) {
test('location', co(function* (t) { test('location', co(function* (t) {
const loc = yield client.location(grazHbf) const loc = yield client.location(grazHbf)
assertValidStation(t, loc) // todo: find a way to always get products from the API
assertValidStation(t, loc, false, true)
t.equal(loc.id, grazHbf) t.equal(loc.id, grazHbf)
t.end() t.end()
@ -471,12 +454,10 @@ test('radar Salzburg', co(function* (t) {
t.ok(Array.isArray(v.frames)) t.ok(Array.isArray(v.frames))
for (let f of v.frames) { for (let f of v.frames) {
assertValidStation(t, f.origin, true) // there are stations which the API desn't return products for
// can contain stations in germany which don't have a products property, would break // todo: find a way to always get products from the API
// assertValidStationProducts(t, f.origin.products) assertValidStation(t, f.origin, true, true)
assertValidStation(t, f.destination, true) assertValidStation(t, f.destination, true, true)
// can contain stations in germany which don't have a products property, would break
// assertValidStationProducts(t, f.destination.products)
t.equal(typeof f.t, 'number') t.equal(typeof f.t, 'number')
} }
} }

View file

@ -10,6 +10,7 @@ const shorten = require('vbb-short-station-name')
const co = require('./co') const co = require('./co')
const createClient = require('..') const createClient = require('..')
const vbbProfile = require('../p/vbb') const vbbProfile = require('../p/vbb')
const allProducts = require('../p/vbb/products')
const { const {
assertValidStation: _assertValidStation, assertValidStation: _assertValidStation,
assertValidPoi, assertValidPoi,
@ -24,20 +25,16 @@ const {
const when = createWhen('Europe/Berlin', 'de-DE') const when = createWhen('Europe/Berlin', 'de-DE')
// todo: DRY with other tests, move into lib
const assertValidStation = (t, s, coordsOptional = false) => { const assertValidStation = (t, s, coordsOptional = false) => {
_assertValidStation(t, s, coordsOptional) _assertValidStation(t, s, coordsOptional)
t.equal(s.name, shorten(s.name)) t.equal(s.name, shorten(s.name))
} t.ok(s.products)
for (let product of allProducts) {
const assertValidStationProducts = (t, p) => { product = product.id
t.ok(p) const msg = `station.products[${product}] must be a boolean`
t.equal(typeof p.suburban, 'boolean') t.equal(typeof s.products[product], 'boolean', msg)
t.equal(typeof p.subway, 'boolean') }
t.equal(typeof p.tram, 'boolean')
t.equal(typeof p.bus, 'boolean')
t.equal(typeof p.ferry, 'boolean')
t.equal(typeof p.express, 'boolean')
t.equal(typeof p.regional, 'boolean')
} }
const assertValidLine = (t, l) => { const assertValidLine = (t, l) => {
@ -76,13 +73,11 @@ test('journeys  station to station', co(function* (t) {
t.equal(typeof leg.id, 'string') t.equal(typeof leg.id, 'string')
t.ok(leg.id) t.ok(leg.id)
assertValidStation(t, leg.origin) assertValidStation(t, leg.origin)
assertValidStationProducts(t, leg.origin.products)
t.ok(leg.origin.name.indexOf('(Berlin)') === -1) t.ok(leg.origin.name.indexOf('(Berlin)') === -1)
t.strictEqual(leg.origin.id, spichernstr) t.strictEqual(leg.origin.id, spichernstr)
assertValidWhen(t, leg.departure, when) assertValidWhen(t, leg.departure, when)
assertValidStation(t, leg.destination) assertValidStation(t, leg.destination)
assertValidStationProducts(t, leg.destination.products)
t.strictEqual(leg.destination.id, amrumerStr) t.strictEqual(leg.destination.id, amrumerStr)
assertValidWhen(t, leg.arrival, when) assertValidWhen(t, leg.arrival, when)
@ -246,7 +241,6 @@ test('journeys  station to address', co(function* (t) {
const leg = journey.legs[journey.legs.length - 1] const leg = journey.legs[journey.legs.length - 1]
assertValidStation(t, leg.origin) assertValidStation(t, leg.origin)
assertValidStationProducts(t, leg.origin.products)
assertValidWhen(t, leg.departure, when) assertValidWhen(t, leg.departure, when)
const dest = leg.destination const dest = leg.destination
@ -275,7 +269,6 @@ test('journeys  station to POI', co(function* (t) {
const leg = journey.legs[journey.legs.length - 1] const leg = journey.legs[journey.legs.length - 1]
assertValidStation(t, leg.origin) assertValidStation(t, leg.origin)
assertValidStationProducts(t, leg.origin.products)
assertValidWhen(t, leg.departure, when) assertValidWhen(t, leg.departure, when)
const dest = leg.destination const dest = leg.destination
@ -342,7 +335,6 @@ test('departures', co(function* (t) {
t.equal(dep.station.name, 'U Spichernstr.') t.equal(dep.station.name, 'U Spichernstr.')
assertValidStation(t, dep.station) assertValidStation(t, dep.station)
assertValidStationProducts(t, dep.station.products)
t.strictEqual(dep.station.id, spichernstr) t.strictEqual(dep.station.id, spichernstr)
assertValidWhen(t, dep.when, when) assertValidWhen(t, dep.when, when)
@ -494,10 +486,8 @@ test('radar', co(function* (t) {
t.ok(Array.isArray(v.frames)) t.ok(Array.isArray(v.frames))
for (let f of v.frames) { for (let f of v.frames) {
assertValidStation(t, f.origin, true) assertValidStation(t, f.origin, true)
assertValidStationProducts(t, f.origin.products)
t.strictEqual(f.origin.name.indexOf('(Berlin)'), -1) t.strictEqual(f.origin.name.indexOf('(Berlin)'), -1)
assertValidStation(t, f.destination, true) assertValidStation(t, f.destination, true)
assertValidStationProducts(t, f.destination.products)
t.strictEqual(f.destination.name.indexOf('(Berlin)'), -1) t.strictEqual(f.destination.name.indexOf('(Berlin)'), -1)
t.equal(typeof f.t, 'number') t.equal(typeof f.t, 'number')
} }