Skip to content

Commit

Permalink
tests: co/yield -> async/await
Browse files Browse the repository at this point in the history
  • Loading branch information
derhuerst committed Dec 10, 2018
1 parent 46becf2 commit b825690
Show file tree
Hide file tree
Showing 22 changed files with 505 additions and 571 deletions.
136 changes: 67 additions & 69 deletions test/bvg.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const tapePromise = require('tape-promise').default
const tape = require('tape')
const isRoughlyEqual = require('is-roughly-equal')

const co = require('./lib/co')
const createClient = require('..')
const bvgProfile = require('../p/bvg')
const products = require('../p/bvg/products')
Expand Down Expand Up @@ -66,14 +65,14 @@ const jannowitzbrücke = '900000100004'

const hour = 60 * 60 * 1000

test('journeys – Spichernstr. to Bismarckstr.', co(function* (t) {
const journeys = yield client.journeys(spichernstr, bismarckstr, {
test('journeys – Spichernstr. to Bismarckstr.', async (t) => {
const journeys = await client.journeys(spichernstr, bismarckstr, {
results: 3,
departure: when,
stopovers: true
})

yield testJourneysStationToStation({
await testJourneysStationToStation({
test: t,
journeys,
validate,
Expand All @@ -83,10 +82,10 @@ test('journeys – Spichernstr. to Bismarckstr.', co(function* (t) {
// todo: find a journey where there ticket info is always available

t.end()
}))
})

test('journeys – only subway', co(function* (t) {
const journeys = yield client.journeys(spichernstr, bismarckstr, {
test('journeys – only subway', async (t) => {
const journeys = await client.journeys(spichernstr, bismarckstr, {
results: 20,
departure: when,
products: {
Expand Down Expand Up @@ -117,7 +116,7 @@ test('journeys – only subway', co(function* (t) {
}

t.end()
}))
})

test('journeys – fails with no product', (t) => {
journeysFailsWithNoProduct({
Expand All @@ -131,8 +130,8 @@ test('journeys – fails with no product', (t) => {
t.end()
})

test('earlier/later journeys', co(function* (t) {
yield testEarlierLaterJourneys({
test('earlier/later journeys', async (t) => {
await testEarlierLaterJourneys({
test: t,
fetchJourneys: client.journeys,
validate,
Expand All @@ -142,20 +141,19 @@ test('earlier/later journeys', co(function* (t) {
})

t.end()
}))
})

test('journeys – leg cycle & alternatives', co(function* (t) {
yield testLegCycleAlternatives({
test('journeys – leg cycle & alternatives', async (t) => {
await testLegCycleAlternatives({
test: t,
fetchJourneys: client.journeys,
fromId: tiergarten,
toId: jannowitzbrücke
})
t.end()
}))

test('refreshJourney', co(function* (t) {
yield testRefreshJourney({
})
test('refreshJourney', async (t) => {
await testRefreshJourney({
test: t,
fetchJourneys: client.journeys,
refreshJourney: client.refreshJourney,
Expand All @@ -165,104 +163,104 @@ test('refreshJourney', co(function* (t) {
when
})
t.end()
}))
})

test('trip details', co(function* (t) {
const journeys = yield client.journeys(spichernstr, amrumerStr, {
test('trip details', async (t) => {
const journeys = await client.journeys(spichernstr, amrumerStr, {
results: 1, departure: when
})

const p = journeys[0].legs[0]
t.ok(p.id, 'precondition failed')
t.ok(p.line.name, 'precondition failed')
const trip = yield client.trip(p.id, p.line.name, {when})
const trip = await client.trip(p.id, p.line.name, {when})

validate(t, trip, 'journeyLeg', 'trip')
t.end()
}))
})

test('journeys – station to address', co(function* (t) {
test('journeys – station to address', async (t) => {
const torfstr = {
type: 'location',
address: '13353 Berlin-Wedding, Torfstr. 17',
latitude: 52.541797,
longitude: 13.350042
}
const journeys = yield client.journeys(spichernstr, torfstr, {
const journeys = await client.journeys(spichernstr, torfstr, {
results: 3,
departure: when
})

yield testJourneysStationToAddress({
await testJourneysStationToAddress({
test: t,
journeys,
validate,
fromId: spichernstr,
to: torfstr
})
t.end()
}))
})

test('journeys – station to POI', co(function* (t) {
test('journeys – station to POI', async (t) => {
const atze = {
type: 'location',
id: '900980720',
name: 'Berlin, Atze Musiktheater für Kinder',
latitude: 52.543333,
longitude: 13.351686
}
const journeys = yield client.journeys(spichernstr, atze, {
const journeys = await client.journeys(spichernstr, atze, {
results: 3,
departure: when
})

yield testJourneysStationToPoi({
await testJourneysStationToPoi({
test: t,
journeys,
validate,
fromId: spichernstr,
to: atze
})
t.end()
}))
})

test('journeys: via works – with detour', co(function* (t) {
test('journeys: via works – with detour', async (t) => {
// Going from Westhafen to Wedding via Württembergalle without detour
// is currently impossible. We check if the routing engine computes a detour.
const journeys = yield client.journeys(westhafen, wedding, {
const journeys = await client.journeys(westhafen, wedding, {
via: württembergallee,
results: 1,
departure: when,
stopovers: true
})

yield testJourneysWithDetour({
await testJourneysWithDetour({
test: t,
journeys,
validate,
detourIds: [württembergallee]
})
t.end()
}))
})

// todo: without detour test

test('departures', co(function* (t) {
const departures = yield client.departures(spichernstr, {
test('departures', async (t) => {
const departures = await client.departures(spichernstr, {
duration: 5, when
})

yield testDepartures({
await testDepartures({
test: t,
departures,
validate,
id: spichernstr
})
t.end()
}))
})

test('departures with station object', co(function* (t) {
const deps = yield client.departures({
test('departures with station object', async (t) => {
const deps = await client.departures({
type: 'station',
id: spichernstr,
name: 'U Spichernstr',
Expand All @@ -275,10 +273,10 @@ test('departures with station object', co(function* (t) {

validate(t, deps, 'departures', 'departures')
t.end()
}))
})

test('departures at Spichernstr. in direction of Westhafen', co(function* (t) {
yield testDeparturesInDirection({
test('departures at Spichernstr. in direction of Westhafen', async (t) => {
await testDeparturesInDirection({
test: t,
fetchDepartures: client.departures,
fetchTrip: client.trip,
Expand All @@ -288,17 +286,17 @@ test('departures at Spichernstr. in direction of Westhafen', co(function* (t) {
validate
})
t.end()
}))
})

test('departures at 7-digit station', co(function* (t) {
test('departures at 7-digit station', async (t) => {
const eisenach = '8010097' // see derhuerst/vbb-hafas#22
yield client.departures(eisenach, {when})
await client.departures(eisenach, {when})
t.pass('did not fail')
t.end()
}))
})

test('departures without related stations', co(function* (t) {
yield testDeparturesWithoutRelatedStations({
test('departures without related stations', async (t) => {
await testDeparturesWithoutRelatedStations({
test: t,
fetchDepartures: client.departures,
id: '900000024101', // Charlottenburg
Expand All @@ -307,28 +305,28 @@ test('departures without related stations', co(function* (t) {
linesOfRelatedStations: ['U7']
})
t.end()
}))
})

test('arrivals', co(function* (t) {
const arrivals = yield client.arrivals(spichernstr, {
test('arrivals', async (t) => {
const arrivals = await client.arrivals(spichernstr, {
duration: 5, when
})

yield testArrivals({
await testArrivals({
test: t,
arrivals,
validate,
id: spichernstr
})
t.end()
}))
})

test('nearby', co(function* (t) {
test('nearby', async (t) => {
const berlinerStr = '900000044201'
const landhausstr = '900000043252'

// Berliner Str./Bundesallee
const nearby = yield client.nearby({
const nearby = await client.nearby({
type: 'location',
latitude: 52.4873452,
longitude: 13.3310411
Expand All @@ -347,10 +345,10 @@ test('nearby', co(function* (t) {
t.ok(nearby[1].distance < 200)

t.end()
}))
})

test('locations', co(function* (t) {
const locations = yield client.locations('Alexanderplatz', {results: 20})
test('locations', async (t) => {
const locations = await client.locations('Alexanderplatz', {results: 20})

validate(t, locations, 'locations', 'locations')
t.ok(locations.length <= 20)
Expand All @@ -360,19 +358,19 @@ test('locations', co(function* (t) {
t.ok(locations.find(s => !s.name && s.address)) // addresses

t.end()
}))
})

test('station', co(function* (t) {
const s = yield client.station(spichernstr)
test('station', async (t) => {
const s = await client.station(spichernstr)

validate(t, s, ['stop', 'station'], 'station')
t.equal(s.id, spichernstr)

t.end()
}))
})

test('radar', co(function* (t) {
const vehicles = yield client.radar({
test('radar', async (t) => {
const vehicles = await client.radar({
north: 52.52411,
west: 13.41002,
south: 52.51942,
Expand All @@ -383,17 +381,17 @@ test('radar', co(function* (t) {

validate(t, vehicles, 'movements', 'vehicles')
t.end()
}))
})

test('reachableFrom', co(function* (t) {
test('reachableFrom', async (t) => {
const torfstr17 = {
type: 'location',
address: '13353 Berlin-Wedding, Torfstr. 17',
latitude: 52.541797,
longitude: 13.350042
}

yield testReachableFrom({
await testReachableFrom({
test: t,
reachableFrom: client.reachableFrom,
address: torfstr17,
Expand All @@ -402,4 +400,4 @@ test('reachableFrom', co(function* (t) {
validate
})
t.end()
}))
})
Loading

0 comments on commit b825690

Please sign in to comment.