2020-06-30 22:05:30 +02:00
|
|
|
|
'use strict'
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
const tap = require('tap')
|
2020-06-30 22:05:30 +02:00
|
|
|
|
const assert = require('assert')
|
|
|
|
|
|
|
|
|
|
const {createWhen} = require('./lib/util')
|
|
|
|
|
const createClient = require('../..')
|
|
|
|
|
const rejseplanenProfile = require('../../p/rejseplanen')
|
|
|
|
|
const products = require('../../p/rejseplanen/products')
|
|
|
|
|
const createValidate = require('./lib/validate-fptf-with')
|
|
|
|
|
const testJourneysStationToStation = require('./lib/journeys-station-to-station')
|
|
|
|
|
const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product')
|
|
|
|
|
const testJourneysStationToAddress = require('./lib/journeys-station-to-address')
|
|
|
|
|
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
|
|
|
|
|
const testDepartures = require('./lib/departures')
|
|
|
|
|
const testArrivals = require('./lib/arrivals')
|
|
|
|
|
|
2022-04-23 14:40:51 +02:00
|
|
|
|
const T_MOCK = 1641897000 * 1000 // 2022-01-11T11:30:00+01
|
|
|
|
|
const when = createWhen(rejseplanenProfile.timezone, rejseplanenProfile.locale, T_MOCK)
|
2020-06-30 22:05:30 +02:00
|
|
|
|
|
|
|
|
|
const validate = createValidate({
|
|
|
|
|
when,
|
|
|
|
|
products,
|
|
|
|
|
minLatitude: 52.7,
|
|
|
|
|
maxLatitude: 58.85,
|
|
|
|
|
minLongitude: 5.8,
|
|
|
|
|
maxLongitude: 15.7,
|
|
|
|
|
}, {})
|
|
|
|
|
|
|
|
|
|
const client = createClient(rejseplanenProfile, 'public-transport/hafas-client:test')
|
|
|
|
|
|
|
|
|
|
const næstved = '8600810'
|
|
|
|
|
const randers = '8600040'
|
|
|
|
|
const aalborg = '8600020'
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('journeys – Næstved to Aalborg', async (t) => {
|
2020-06-30 22:05:30 +02:00
|
|
|
|
const res = await client.journeys(næstved, aalborg, {
|
|
|
|
|
results: 4,
|
|
|
|
|
departure: when,
|
|
|
|
|
stopovers: true,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await testJourneysStationToStation({
|
|
|
|
|
test: t,
|
|
|
|
|
res,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: næstved,
|
|
|
|
|
toId: aalborg,
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// todo: journeys, only one product
|
|
|
|
|
|
2021-12-29 18:53:50 +01:00
|
|
|
|
tap.test('journeys – fails with no product', async (t) => {
|
|
|
|
|
await journeysFailsWithNoProduct({
|
2020-06-30 22:05:30 +02:00
|
|
|
|
test: t,
|
|
|
|
|
fetchJourneys: client.journeys,
|
|
|
|
|
fromId: næstved,
|
|
|
|
|
toId: aalborg,
|
|
|
|
|
when,
|
|
|
|
|
products,
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('Randers to Møllegade 3, København', async (t) => {
|
2020-06-30 22:05:30 +02:00
|
|
|
|
const møllegade3 = {
|
|
|
|
|
type: 'location',
|
|
|
|
|
id: '901011579',
|
|
|
|
|
address: 'Møllegade 3, 2200 København N, Københavns Kommune',
|
|
|
|
|
latitude: 55.69052, longitude: 12.555494,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const res = await client.journeys(randers, møllegade3, {
|
|
|
|
|
results: 3,
|
|
|
|
|
departure: when,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await testJourneysStationToAddress({
|
|
|
|
|
test: t,
|
|
|
|
|
res,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: randers,
|
|
|
|
|
to: møllegade3,
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// todo: journeys: via works – with detour
|
|
|
|
|
// todo: without detour
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('earlier/later journeys', async (t) => {
|
2020-06-30 22:05:30 +02:00
|
|
|
|
await testEarlierLaterJourneys({
|
|
|
|
|
test: t,
|
|
|
|
|
fetchJourneys: client.journeys,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: randers,
|
|
|
|
|
toId: næstved,
|
|
|
|
|
when,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('trip', async (t) => {
|
2020-06-30 22:05:30 +02:00
|
|
|
|
const { journeys } = await client.journeys(aalborg, næstved, {
|
|
|
|
|
results: 1, departure: when,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const p = journeys[0].legs.find(l => !l.walking)
|
|
|
|
|
t.ok(p.tripId, 'precondition failed')
|
|
|
|
|
t.ok(p.line.name, 'precondition failed')
|
|
|
|
|
|
2021-12-29 21:23:28 +01:00
|
|
|
|
const tripRes = await client.trip(p.tripId, p.line.name, {when})
|
|
|
|
|
|
|
|
|
|
validate(t, tripRes, 'tripResult', 'res')
|
2020-06-30 22:05:30 +02:00
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('departures at Næstved.', async (t) => {
|
2021-12-29 21:11:07 +01:00
|
|
|
|
const res = await client.departures(næstved, {
|
2020-06-30 22:05:30 +02:00
|
|
|
|
duration: 20, when,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await testDepartures({
|
|
|
|
|
test: t,
|
2021-12-29 21:11:07 +01:00
|
|
|
|
res,
|
2020-06-30 22:05:30 +02:00
|
|
|
|
validate,
|
2021-08-24 00:43:20 +02:00
|
|
|
|
ids: [
|
|
|
|
|
næstved,
|
|
|
|
|
'8650810', // Næstved St. (togbus)
|
|
|
|
|
'8651810', // Næstved St. (togbus)
|
|
|
|
|
],
|
2020-06-30 22:05:30 +02:00
|
|
|
|
})
|
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('arrivals at Næstved.', async (t) => {
|
2021-12-29 21:11:07 +01:00
|
|
|
|
const res = await client.arrivals(næstved, {
|
2020-06-30 22:05:30 +02:00
|
|
|
|
duration: 20, when
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await testArrivals({
|
|
|
|
|
test: t,
|
2021-12-29 21:11:07 +01:00
|
|
|
|
res,
|
2020-06-30 22:05:30 +02:00
|
|
|
|
validate,
|
2021-08-24 00:43:20 +02:00
|
|
|
|
ids: [
|
|
|
|
|
næstved,
|
|
|
|
|
'8650810', // Næstved St. (togbus)
|
|
|
|
|
'8651810', // Næstved St. (togbus)
|
|
|
|
|
],
|
2020-06-30 22:05:30 +02:00
|
|
|
|
})
|
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// todo: nearby
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('locations named "næstved"', async (t) => {
|
2020-06-30 22:05:30 +02:00
|
|
|
|
const locations = await client.locations('næstved', {
|
|
|
|
|
results: 20,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
validate(t, locations, 'locations', 'locations')
|
|
|
|
|
t.ok(locations.length <= 20)
|
|
|
|
|
|
|
|
|
|
t.ok(locations.find(s => s.type === 'stop' || s.type === 'station'))
|
|
|
|
|
t.ok(locations.find(s => s.poi))
|
|
|
|
|
t.ok(locations.some((loc) => {
|
|
|
|
|
if (loc.station && loc.station.id === næstved) return true
|
|
|
|
|
return loc.id === næstved
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('stop Næstved', async (t) => {
|
2020-06-30 22:05:30 +02:00
|
|
|
|
const s = await client.stop(næstved)
|
|
|
|
|
|
|
|
|
|
validate(t, s, ['stop', 'station'], 'stop')
|
|
|
|
|
t.equal(s.id, næstved)
|
|
|
|
|
|
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('radar', async (t) => {
|
2020-06-30 22:05:30 +02:00
|
|
|
|
const vehicles = await client.radar({
|
|
|
|
|
north: 55.695,
|
|
|
|
|
west: 12.498,
|
|
|
|
|
south: 55.639,
|
|
|
|
|
east: 12.621,
|
|
|
|
|
}, {
|
|
|
|
|
duration: 5 * 60, when, results: 10,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
validate(t, vehicles, 'movements', 'vehicles')
|
|
|
|
|
t.end()
|
|
|
|
|
})
|