db-vendo-client/test/e2e/cmta.js

264 lines
5.6 KiB
JavaScript
Raw Normal View History

2022-05-07 16:17:37 +02:00
import tap from 'tap'
2018-08-24 20:09:16 +02:00
2022-05-07 16:17:37 +02:00
import {createWhen} from './lib/util.js'
import {createClient} from '../../index.js'
import {profile as cmtaProfile} from '../../p/cmta/index.js'
import {createValidateFptfWith as createValidate} from './lib/validate-fptf-with.js'
import {testJourneysStationToStation} from './lib/journeys-station-to-station.js'
import {testJourneysStationToAddress} from './lib/journeys-station-to-address.js'
import {testJourneysStationToPoi} from './lib/journeys-station-to-poi.js'
import {testEarlierLaterJourneys} from './lib/earlier-later-journeys.js'
import {testRefreshJourney} from './lib/refresh-journey.js'
import {journeysFailsWithNoProduct} from './lib/journeys-fails-with-no-product.js'
import {testDepartures} from './lib/departures.js'
import {testArrivals} from './lib/arrivals.js'
import {testJourneysWithDetour} from './lib/journeys-with-detour.js'
import {testReachableFrom} from './lib/reachable-from.js'
2018-08-24 20:09:16 +02:00
const T_MOCK = 1652175000 * 1000 // 2022-05-10T11:30+02:00
const when = createWhen(cmtaProfile.timezone, cmtaProfile.locale, T_MOCK)
2018-08-24 20:09:16 +02:00
const cfg = {
when,
stationCoordsOptional: false,
2022-05-07 16:17:37 +02:00
products: cmtaProfile.products,
2019-02-15 14:53:01 +01:00
minLatitude: 26,
maxLatitude: 33,
minLongitude: -100,
maxLongitude: -95
2018-08-24 20:09:16 +02:00
}
2019-02-15 14:53:01 +01:00
const validate = createValidate(cfg)
2018-08-24 20:09:16 +02:00
const client = createClient(cmtaProfile, 'public-transport/hafas-client:test')
const broadieOaks = '2370'
const domain = '5919'
const capitol591 = '591'
2021-05-20 16:42:43 +01:00
tap.test('journeys  Broadie Oaks to Domain', async (t) => {
const res = await client.journeys(broadieOaks, domain, {
results: 4,
2018-08-24 20:09:16 +02:00
departure: when,
stopovers: true
})
2018-11-21 19:07:37 +01:00
await testJourneysStationToStation({
2018-08-24 20:09:16 +02:00
test: t,
res,
2018-08-24 20:09:16 +02:00
validate,
fromId: broadieOaks,
toId: domain
})
t.end()
2018-11-21 19:07:37 +01:00
})
2018-08-24 20:09:16 +02:00
// todo: journeys, only one product
2021-12-29 18:53:50 +01:00
tap.test('journeys fails with no product', async (t) => {
await journeysFailsWithNoProduct({
2018-08-24 20:09:16 +02:00
test: t,
fetchJourneys: client.journeys,
fromId: broadieOaks,
toId: domain,
when,
2022-05-07 16:17:37 +02:00
products: cmtaProfile.products,
2018-08-24 20:09:16 +02:00
})
t.end()
})
2021-05-20 16:42:43 +01:00
tap.test('Domain to 1104 Elm Street, Austin, TX 78703', async (t) => {
2018-08-24 20:09:16 +02:00
const someAddress = {
type: 'location',
address: '1104 ELM ST, Austin, TX 78703',
latitude: 30.279220,
longitude: -97.758292
}
const res = await client.journeys(domain, someAddress, {
2018-08-24 20:09:16 +02:00
results: 3,
departure: when
})
2018-11-21 19:07:37 +01:00
await testJourneysStationToAddress({
2018-08-24 20:09:16 +02:00
test: t,
res,
2018-08-24 20:09:16 +02:00
validate,
fromId: domain,
to: someAddress
})
t.end()
2018-11-21 19:07:37 +01:00
})
2018-08-24 20:09:16 +02:00
2021-08-24 00:43:20 +02:00
tap.test('Domain to WHOLE FOODS MARKET - ARBOR TRAILS', async (t) => {
2018-08-24 20:09:16 +02:00
const wholeFoodsMarket = {
type: 'location',
2021-08-24 00:43:20 +02:00
id: '9893387',
2019-02-07 17:47:50 +01:00
poi: true,
2021-08-24 00:43:20 +02:00
name: 'WHOLE FOODS MARKET - ARBOR TRAILS',
latitude: 30.22026,
longitude: -97.84174,
2018-08-24 20:09:16 +02:00
}
const res = await client.journeys(domain, wholeFoodsMarket, {
2018-08-24 20:09:16 +02:00
results: 3,
departure: when
})
2018-11-21 19:07:37 +01:00
await testJourneysStationToPoi({
2018-08-24 20:09:16 +02:00
test: t,
res,
2018-08-24 20:09:16 +02:00
validate,
fromId: domain,
to: wholeFoodsMarket
})
t.end()
2018-11-21 19:07:37 +01:00
})
2018-08-24 20:09:16 +02:00
// todo: walkingSpeed "2107 MELRIDGE PL" -> 000002148
2018-08-24 20:09:16 +02:00
// todo: via works with detour
// todo: without detour
2021-05-20 16:42:43 +01:00
tap.test('earlier/later journeys', async (t) => {
2018-11-21 19:07:37 +01:00
await testEarlierLaterJourneys({
2018-08-24 20:09:16 +02:00
test: t,
fetchJourneys: client.journeys,
validate,
fromId: broadieOaks,
toId: domain,
when
2018-08-24 20:09:16 +02:00
})
t.end()
2018-11-21 19:07:37 +01:00
})
2018-08-24 20:09:16 +02:00
2021-05-20 16:42:43 +01:00
tap.test('refreshJourney', async (t) => {
2018-11-21 19:07:37 +01:00
await testRefreshJourney({
2018-08-24 20:09:16 +02:00
test: t,
fetchJourneys: client.journeys,
refreshJourney: client.refreshJourney,
validate,
fromId: broadieOaks,
toId: domain,
when
})
t.end()
2018-11-21 19:07:37 +01:00
})
2018-08-24 20:09:16 +02:00
2021-05-20 16:42:43 +01:00
tap.test('trip details', async (t) => {
const res = await client.journeys(broadieOaks, domain, {
2018-08-24 20:09:16 +02:00
results: 1, departure: when
})
const p = res.journeys[0].legs.find(l => !l.walking)
t.ok(p.tripId, 'precondition failed')
2018-08-24 20:09:16 +02:00
t.ok(p.line.name, 'precondition failed')
const tripRes = await client.trip(p.tripId, {when})
validate(t, tripRes, 'tripResult', 'res')
2018-08-24 20:09:16 +02:00
t.end()
2018-11-21 19:07:37 +01:00
})
2018-08-24 20:09:16 +02:00
2021-05-20 16:42:43 +01:00
tap.test('departures at Broadie Oaks', async (t) => {
const res = await client.departures(broadieOaks, {
duration: 10, when,
2018-08-24 20:09:16 +02:00
})
2018-11-21 19:07:37 +01:00
await testDepartures({
2018-08-24 20:09:16 +02:00
test: t,
res,
2018-08-24 20:09:16 +02:00
validate,
id: broadieOaks
})
t.end()
2018-11-21 19:07:37 +01:00
})
2018-08-24 20:09:16 +02:00
2021-05-20 16:42:43 +01:00
tap.test('departures with station object', async (t) => {
const res = await client.departures({
2018-08-24 20:09:16 +02:00
type: 'station',
id: broadieOaks,
name: 'Magdeburg Hbf',
location: {
type: 'location',
latitude: 1.23,
longitude: 2.34
}
}, {when})
validate(t, res, 'departuresResponse', 'res')
2018-08-24 20:09:16 +02:00
t.end()
2018-11-21 19:07:37 +01:00
})
2018-08-24 20:09:16 +02:00
2021-05-20 16:42:43 +01:00
tap.test('arrivals at Broadie Oaks', async (t) => {
const res = await client.arrivals(broadieOaks, {
2018-08-24 20:09:16 +02:00
duration: 10, when
})
2018-11-21 19:07:37 +01:00
await testArrivals({
2018-08-24 20:09:16 +02:00
test: t,
res,
2018-08-24 20:09:16 +02:00
validate,
id: broadieOaks
})
t.end()
2018-11-21 19:07:37 +01:00
})
2018-08-24 20:09:16 +02:00
// todo: nearby
2021-05-20 16:42:43 +01:00
tap.test('locations named "Capitol"', async (t) => {
2018-11-21 19:07:37 +01:00
const locations = await client.locations('Capitol', {
2018-08-24 20:09:16 +02:00
results: 10
})
validate(t, locations, 'locations', 'locations')
t.ok(locations.length <= 10)
t.ok(locations.find(s => s.type === 'stop' || s.type === 'station'))
2019-02-07 17:47:50 +01:00
t.ok(locations.find(s => s.poi)) // POIs
2018-08-24 20:09:16 +02:00
t.ok(locations.some((l) => {
return l.station && l.station.id === capitol591 || l.id === capitol591
2018-08-24 20:09:16 +02:00
}))
t.end()
2018-11-21 19:07:37 +01:00
})
2018-08-24 20:09:16 +02:00
2021-05-20 16:42:43 +01:00
tap.test('station Domain', async (t) => {
const s = await client.stop(domain)
2018-08-24 20:09:16 +02:00
validate(t, s, ['stop', 'station'], 'station')
t.equal(s.id, domain)
t.end()
2018-11-21 19:07:37 +01:00
})
2018-08-24 20:09:16 +02:00
2021-05-20 16:42:43 +01:00
tap.test('radar', async (t) => {
const res = await client.radar({
2018-08-24 20:09:16 +02:00
north: 30.240877,
west: -97.804588,
south: 30.225378,
east: -97.786692
}, {
duration: 5 * 60, when, results: 10
})
validate(t, res, 'radarResult', 'res')
2018-08-24 20:09:16 +02:00
t.end()
2018-11-21 19:07:37 +01:00
})
2021-05-20 16:42:43 +01:00
tap.test('reachableFrom', async (t) => {
2018-11-21 19:07:37 +01:00
await testReachableFrom({
test: t,
reachableFrom: client.reachableFrom,
address: {
type: 'location',
address: '604 W 9TH ST, Austin, TX 78701',
latitude: 30.272910,
longitude: -97.747883
},
when,
maxDuration: 15,
validate
})
t.end()
2018-11-21 19:07:37 +01:00
})