mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
vbb tests: code style 👕
This commit is contained in:
parent
c9739cf27d
commit
7cf1261347
1 changed files with 210 additions and 217 deletions
139
test/vbb.js
139
test/vbb.js
|
@ -1,10 +1,10 @@
|
|||
'use strict'
|
||||
|
||||
const test = require('tape')
|
||||
const a = require('assert')
|
||||
const isRoughlyEqual = require('is-roughly-equal')
|
||||
const stations = require('vbb-stations-autocomplete')
|
||||
const floor = require('floordate')
|
||||
const tapePromise = require('tape-promise').default
|
||||
const tape = require('tape')
|
||||
|
||||
const createClient = require('..')
|
||||
const vbbProfile = require('../p/vbb')
|
||||
|
@ -20,16 +20,18 @@ const {
|
|||
assertValidWhen
|
||||
} = require('./util')
|
||||
|
||||
// todo
|
||||
const findStation = (query) => stations(query, true, false)
|
||||
|
||||
const test = tapePromise(tape)
|
||||
const client = createClient(vbbProfile)
|
||||
|
||||
test('journeys – station to station', (t) => {
|
||||
test('journeys – station to station', async (t) => {
|
||||
// U Spichernstr. to U Amrumer Str.
|
||||
client.journeys('900000042101', '900000009101', {
|
||||
const journeys = await client.journeys('900000042101', '900000009101', {
|
||||
results: 3, when, passedStations: true
|
||||
})
|
||||
.then((journeys) => {
|
||||
|
||||
t.ok(Array.isArray(journeys))
|
||||
t.strictEqual(journeys.length, 3)
|
||||
|
||||
|
@ -65,14 +67,12 @@ test('journeys – station to station', (t) => {
|
|||
t.ok(Array.isArray(part.passed))
|
||||
for (let passed of part.passed) assertValidPassed(t, passed)
|
||||
}
|
||||
})
|
||||
.catch(t.ifError)
|
||||
.then(() => t.end())
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('journeys – only subway', (t) => {
|
||||
test('journeys – only subway', async (t) => {
|
||||
// U Spichernstr. to U Bismarckstr.
|
||||
client.journeys('900000042101', '900000024201', {
|
||||
const journeys = await client.journeys('900000042101', '900000024201', {
|
||||
results: 20, when,
|
||||
products: {
|
||||
suburban: false,
|
||||
|
@ -84,7 +84,7 @@ test('journeys – only subway', (t) => {
|
|||
regional: false
|
||||
}
|
||||
})
|
||||
.then((journeys) => {
|
||||
|
||||
t.ok(Array.isArray(journeys))
|
||||
t.ok(journeys.length > 1)
|
||||
|
||||
|
@ -97,14 +97,13 @@ test('journeys – only subway', (t) => {
|
|||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(t.ifError)
|
||||
.then(() => t.end())
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('journeys – fails with no product', (t) => {
|
||||
test('journeys – fails with no product', async (t) => {
|
||||
try {
|
||||
// U Spichernstr. to U Bismarckstr.
|
||||
client.journeys('900000042101', '900000024201', {
|
||||
await client.journeys('900000042101', '900000024201', {
|
||||
when,
|
||||
products: {
|
||||
suburban: false,
|
||||
|
@ -116,22 +115,23 @@ test('journeys – fails with no product', (t) => {
|
|||
regional: false
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
} catch (err) {
|
||||
t.ok(err, 'error thrown')
|
||||
t.end()
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
test('journey part details', (t) => {
|
||||
test('journey part details', async (t) => {
|
||||
// U Spichernstr. to U Amrumer Str.
|
||||
client.journeys('900000042101', '900000009101', {results: 1, when})
|
||||
.then((journeys) => {
|
||||
const part = journeys[0].parts[0]
|
||||
t.ok(part.id, 'precondition failed')
|
||||
t.ok(part.line.name, 'precondition failed')
|
||||
return client.journeyPart(part.id, part.line.name, {when})
|
||||
const journeys = await client.journeys('900000042101', '900000009101', {
|
||||
results: 1, when
|
||||
})
|
||||
.then((part) => {
|
||||
|
||||
const p = journeys[0].parts[0]
|
||||
t.ok(p.id, 'precondition failed')
|
||||
t.ok(p.line.name, 'precondition failed')
|
||||
const part = await client.journeyPart(p.id, p.line.name, {when})
|
||||
|
||||
t.equal(typeof part.id, 'string')
|
||||
t.ok(part.id)
|
||||
|
||||
|
@ -142,20 +142,19 @@ test('journey part details', (t) => {
|
|||
|
||||
t.ok(Array.isArray(part.passed))
|
||||
for (let passed of part.passed) assertValidPassed(t, passed)
|
||||
})
|
||||
.catch(t.ifError)
|
||||
.then(() => t.end())
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
|
||||
|
||||
test('journeys – station to address', (t) => {
|
||||
test('journeys – station to address', async (t) => {
|
||||
// U Spichernstr. to Torfstraße 17
|
||||
client.journeys('900000042101', {
|
||||
const journeys = await client.journeys('900000042101', {
|
||||
type: 'address', name: 'Torfstraße 17',
|
||||
latitude: 52.5416823, longitude: 13.3491223
|
||||
}, {results: 1, when})
|
||||
.then((journeys) => {
|
||||
|
||||
t.ok(Array.isArray(journeys))
|
||||
t.strictEqual(journeys.length, 1)
|
||||
const journey = journeys[0]
|
||||
|
@ -170,20 +169,19 @@ test('journeys – station to address', (t) => {
|
|||
t.ok(isRoughlyEqual(.0001, dest.coordinates.latitude, 52.5416823))
|
||||
t.ok(isRoughlyEqual(.0001, dest.coordinates.longitude, 13.3491223))
|
||||
assertValidWhen(t, part.arrival)
|
||||
})
|
||||
.catch(t.ifError)
|
||||
.then(() => t.end())
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
|
||||
|
||||
test('journeys – station to POI', (t) => {
|
||||
test('journeys – station to POI', async (t) => {
|
||||
// U Spichernstr. to ATZE Musiktheater
|
||||
client.journeys('900000042101', {
|
||||
const journeys = await client.journeys('900000042101', {
|
||||
type: 'poi', name: 'ATZE Musiktheater', id: 9980720,
|
||||
latitude: 52.543333, longitude: 13.351686
|
||||
}, {results: 1, when})
|
||||
.then((journeys) => {
|
||||
|
||||
t.ok(Array.isArray(journeys))
|
||||
t.strictEqual(journeys.length, 1)
|
||||
const journey = journeys[0]
|
||||
|
@ -198,16 +196,16 @@ test('journeys – station to POI', (t) => {
|
|||
t.ok(isRoughlyEqual(.0001, dest.coordinates.latitude, 52.543333))
|
||||
t.ok(isRoughlyEqual(.0001, dest.coordinates.longitude, 13.351686))
|
||||
assertValidWhen(t, part.arrival)
|
||||
})
|
||||
.catch(t.ifError)
|
||||
.then(() => t.end())
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
|
||||
|
||||
test('departures', (t) => {
|
||||
client.departures('900000042101', {duration: 5, when}) // U Spichernstr.
|
||||
.then((deps) => {
|
||||
test('departures', async (t) => {
|
||||
// U Spichernstr.
|
||||
const deps = await client.departures('900000042101', {duration: 5, when})
|
||||
|
||||
t.ok(Array.isArray(deps))
|
||||
t.deepEqual(deps, deps.sort((a, b) => t.when > b.when))
|
||||
for (let dep of deps) {
|
||||
|
@ -222,26 +220,23 @@ test('departures', (t) => {
|
|||
t.ok(findStation(dep.direction))
|
||||
assertValidLine(t, dep.line)
|
||||
}
|
||||
})
|
||||
.catch(t.ifError)
|
||||
.then(() => t.end())
|
||||
})
|
||||
|
||||
test('departures at 7-digit station', (t) => {
|
||||
const eisenach = '8010097' // see derhuerst/vbb-hafas#22
|
||||
client.departures(eisenach, {when})
|
||||
.then(() => {
|
||||
t.pass('did not fail')
|
||||
t.end()
|
||||
})
|
||||
.catch(t.ifError)
|
||||
|
||||
test('departures at 7-digit station', async (t) => {
|
||||
const eisenach = '8010097' // see derhuerst/vbb-hafas#22
|
||||
await client.departures(eisenach, {when})
|
||||
t.pass('did not fail')
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
|
||||
|
||||
test('nearby', (t) => {
|
||||
client.nearby(52.4873452,13.3310411, {distance: 200}) // Berliner Str./Bundesallee
|
||||
.then((nearby) => {
|
||||
test('nearby', async (t) => {
|
||||
// Berliner Str./Bundesallee
|
||||
const nearby = await client.nearby(52.4873452,13.3310411, {distance: 200})
|
||||
|
||||
t.ok(Array.isArray(nearby))
|
||||
for (let n of nearby) assertValidLocation(t, n, false)
|
||||
|
||||
|
@ -254,16 +249,15 @@ test('nearby', (t) => {
|
|||
t.equal(nearby[1].name, 'Landhausstr.')
|
||||
t.ok(nearby[1].distance > 100)
|
||||
t.ok(nearby[1].distance < 200)
|
||||
})
|
||||
.catch(t.ifError)
|
||||
.then(() => t.end())
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
|
||||
|
||||
test('locations', (t) => {
|
||||
client.locations('Alexanderplatz', {results: 10})
|
||||
.then((locations) => {
|
||||
test('locations', async (t) => {
|
||||
const locations = await client.locations('Alexanderplatz', {results: 10})
|
||||
|
||||
t.ok(Array.isArray(locations))
|
||||
t.ok(locations.length > 0)
|
||||
t.ok(locations.length <= 10)
|
||||
|
@ -271,16 +265,17 @@ test('locations', (t) => {
|
|||
t.ok(locations.find((s) => s.type === 'station'))
|
||||
t.ok(locations.find((s) => s.type === 'poi'))
|
||||
t.ok(locations.find((s) => s.type === 'address'))
|
||||
})
|
||||
.catch(t.ifError)
|
||||
.then(() => t.end())
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
|
||||
|
||||
test('radar', (t) => {
|
||||
client.radar(52.52411, 13.41002, 52.51942, 13.41709, {duration: 5 * 60, when})
|
||||
.then((vehicles) => {
|
||||
test('radar', async (t) => {
|
||||
const vehicles = await client.radar(52.52411, 13.41002, 52.51942, 13.41709, {
|
||||
duration: 5 * 60, when
|
||||
})
|
||||
|
||||
t.ok(Array.isArray(vehicles))
|
||||
t.ok(vehicles.length > 0)
|
||||
for (let v of vehicles) {
|
||||
|
@ -323,7 +318,5 @@ test('radar', (t) => {
|
|||
t.equal(typeof f.t, 'number')
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(t.ifError)
|
||||
.then(() => t.end())
|
||||
t.end()
|
||||
})
|
||||
|
|
Loading…
Add table
Reference in a new issue