2024-02-06 22:58:49 +01:00
|
|
|
import isRoughlyEqual from 'is-roughly-equal';
|
2018-04-24 15:42:53 +02:00
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
const testJourneysStationToAddress = async (cfg) => {
|
2024-02-06 22:58:49 +01:00
|
|
|
const {test: t, res, validate, fromId} = cfg;
|
|
|
|
const {address, latitude, longitude} = cfg.to;
|
2018-04-24 15:42:53 +02:00
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
validate(t, res, 'journeysResult', 'res');
|
|
|
|
const {journeys} = res;
|
2019-01-16 21:41:17 +08:00
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
t.ok(journeys.length >= 3, 'journeys must have >=3 items');
|
2018-04-24 15:42:53 +02:00
|
|
|
for (let i = 0; i < journeys.length; i++) {
|
2024-02-06 22:58:49 +01:00
|
|
|
const j = journeys[i];
|
2018-04-24 15:42:53 +02:00
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
const firstLeg = j.legs[0];
|
|
|
|
const orig = firstLeg.origin.station || firstLeg.origin;
|
|
|
|
t.ok(orig.id, fromId);
|
2018-04-24 15:42:53 +02:00
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
const d = j.legs[j.legs.length - 1].destination;
|
|
|
|
const n = `res.journeys[0].legs[${i}].destination`;
|
2018-04-24 15:42:53 +02:00
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
t.equal(d.type, 'location', n + '.type is invalid');
|
|
|
|
t.equal(d.address, address, n + '.address is invalid');
|
|
|
|
t.ok(isRoughlyEqual(0.0001, d.latitude, latitude), n + '.latitude is invalid');
|
|
|
|
t.ok(isRoughlyEqual(0.0001, d.longitude, longitude), n + '.longitude is invalid');
|
2018-04-24 15:42:53 +02:00
|
|
|
}
|
2024-02-06 22:58:49 +01:00
|
|
|
};
|
2018-04-24 15:42:53 +02:00
|
|
|
|
2022-05-07 16:17:37 +02:00
|
|
|
export {
|
|
|
|
testJourneysStationToAddress,
|
2024-02-06 22:58:49 +01:00
|
|
|
};
|