mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
tests: make requests deterministic 💚
This commit is contained in:
parent
0c3acaba46
commit
fea27d3a4a
8 changed files with 18 additions and 6 deletions
|
@ -159,7 +159,8 @@ test('earlier/later journeys', async (t) => {
|
|||
fetchJourneys: client.journeys,
|
||||
validate,
|
||||
fromId: luxembourg,
|
||||
toId: ettelbruck
|
||||
toId: ettelbruck,
|
||||
when,
|
||||
})
|
||||
|
||||
t.end()
|
||||
|
|
|
@ -49,7 +49,7 @@ test('departures at Hagen Bauhaus', async (t) => {
|
|||
|
||||
test('trip details', async (t) => {
|
||||
const deps = await client.departures(hagenBauhaus, {
|
||||
results: 1, duration: 120, departure: when
|
||||
results: 1, duration: 120, when
|
||||
})
|
||||
|
||||
const p = deps[0] || {}
|
||||
|
|
|
@ -407,6 +407,7 @@ test('stop', async (t) => {
|
|||
|
||||
test('line with additionalName', async (t) => {
|
||||
const departures = await client.departures(potsdamHbf, {
|
||||
when,
|
||||
duration: 12 * 60, // 12 minutes
|
||||
products: {bus: false, suburban: false, tram: false}
|
||||
})
|
||||
|
|
|
@ -136,7 +136,8 @@ test('earlier/later journeys', async (t) => {
|
|||
fetchJourneys: client.journeys,
|
||||
validate,
|
||||
fromId: ingolstadtHbf,
|
||||
toId: telemannstr
|
||||
toId: telemannstr,
|
||||
when,
|
||||
})
|
||||
|
||||
t.end()
|
||||
|
|
|
@ -3,15 +3,17 @@
|
|||
const isRoughlyEqual = require('is-roughly-equal')
|
||||
|
||||
const testJourneysWalkingSpeed = async (cfg) => {
|
||||
const {test: t, journeys, validate, from, to, products, minTimeDifference} = cfg
|
||||
const {test: t, journeys, validate, from, to, when, products, minTimeDifference} = cfg
|
||||
|
||||
const {journeys: [journeyWithFastWalking]} = await journeys(from, to, {
|
||||
departure: when,
|
||||
results: 1, products, walkingSpeed: 'fast'
|
||||
})
|
||||
const legWithFastWalking = journeyWithFastWalking.legs.find(l => l.walking)
|
||||
t.ok(legWithFastWalking, 'no walking leg in journey with fast walking')
|
||||
|
||||
const {journeys: [journeyWithSlowWalking]} = await journeys(from, to, {
|
||||
departure: when,
|
||||
results: 1, products, walkingSpeed: 'slow'
|
||||
})
|
||||
const legWithSlowWalking = journeyWithSlowWalking.legs.find(l => l.walking)
|
||||
|
|
|
@ -10,9 +10,14 @@ const hour = 60 * 60 * 1000
|
|||
const day = 24 * hour
|
||||
const week = 7 * day
|
||||
|
||||
const T_MOCK = 1592225430 * 1000
|
||||
|
||||
// next Monday 10 am
|
||||
const createWhen = (timezone, locale) => {
|
||||
return DateTime.fromMillis(Date.now(), {
|
||||
const t = process.env.VCR_MODE && !process.env.VCR_OFF
|
||||
? T_MOCK
|
||||
: Date.now()
|
||||
return DateTime.fromMillis(t, {
|
||||
zone: timezone,
|
||||
locale,
|
||||
}).startOf('week').plus({weeks: 1, hours: 10}).toJSDate()
|
||||
|
|
|
@ -133,6 +133,7 @@ test('journeys: walkingSpeed', async (t) => {
|
|||
validate,
|
||||
from: havelchaussee,
|
||||
to: wannsee,
|
||||
when,
|
||||
products: {bus: false},
|
||||
minTimeDifference: 5 * 60 * 1000
|
||||
})
|
||||
|
|
|
@ -78,7 +78,8 @@ test('earlier/later journeys', async (t) => {
|
|||
fetchJourneys: client.journeys,
|
||||
validate,
|
||||
fromId: ewaldstrasse,
|
||||
toId: kornmarkt
|
||||
toId: kornmarkt,
|
||||
when
|
||||
})
|
||||
|
||||
t.end()
|
||||
|
|
Loading…
Add table
Reference in a new issue