Skip to content

Commit

Permalink
DB E2E/integration tests: disable price/fare/ticket validation ✅
Browse files Browse the repository at this point in the history
related: #331
  • Loading branch information
derhuerst committed Dec 17, 2024
1 parent dfab132 commit 8432ff1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 22 deletions.
19 changes: 12 additions & 7 deletions test/e2e/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const cfg = {
maxLatitude: 55.030671,
minLongitude: 6.896517,
maxLongitude: 16.180237,
validateJourneyTickets: false, // don't validate a journey's tickets
};

const validate = createValidate(cfg);
Expand Down Expand Up @@ -122,17 +123,21 @@ tap.test('journeys – Berlin Schwedter Str. to München Hbf', async (t) => {
});
// todo: find a journey where there pricing info is always available
for (let journey of res.journeys) {
if (journey.price) {
assertValidPrice(t, journey.price);
}
if (journey.tickets) {
assertValidTickets(t, journey.tickets);
}
// It seems like the DB endpoint doesn't return (valid) prices/fares/tickets anymore.
// see https://github.com/public-transport/hafas-client/issues/331
// if (journey.price) {
// assertValidPrice(t, journey.price);
// }
// if (journey.tickets) {
// assertValidTickets(t, journey.tickets);
// }
}
t.end();
});

tap.test('refreshJourney – valid tickets', async (t) => {
// It seems like the DB endpoint doesn't return (valid) prices/fares/tickets anymore.
// see https://github.com/public-transport/hafas-client/issues/331
tap.skip('refreshJourney – valid tickets', async (t) => {
const T_MOCK = 1710831600 * 1000; // 2024-03-19T08:00:00+01:00
const when = createWhen(dbProfile.timezone, dbProfile.locale, T_MOCK);

Expand Down
32 changes: 17 additions & 15 deletions test/e2e/lib/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,23 +411,25 @@ const createValidateJourneyLeg = (cfg) => {
return validateJourneyLeg;
};

const validateJourney = (val, j, name = 'journey') => {
const withFakeId = Object.assign({
id: 'foo', // todo: let hafas-client parse a journey ID
}, j);
defaultValidators.journey(val, withFakeId, name);
// todo: j.refreshToken

if ('tickets' in j) {
a.ok(Array.isArray(j.tickets), name + '.tickets must be an array');
a.ok(j.tickets.length > 0, name + '.tickets must not be empty');

for (let i = 0; i < j.tickets.length; i++) {
val.ticket(val, j.tickets[i], name + `.tickets[${i}]`);
const createValidateJourney = (cfg) => {
const validateJourney = (val, j, name = 'journey') => {
const withFakeId = Object.assign({
id: 'foo', // todo: let hafas-client parse a journey ID
}, j);
defaultValidators.journey(val, withFakeId, name);
// todo: j.refreshToken

if (cfg.validateJourneyTickets !== false && 'tickets' in j) {
a.ok(Array.isArray(j.tickets), name + '.tickets must be an array');
a.ok(j.tickets.length > 0, name + '.tickets must not be empty');

for (let i = 0; i < j.tickets.length; i++) {
val.ticket(val, j.tickets[i], name + `.tickets[${i}]`);
}
}
}
};
return validateJourney;
};
const createValidateJourney = () => validateJourney;

const validateJourneys = (val, js, name = 'journeys') => {
a.ok(Array.isArray(js), name + ' must be an array');
Expand Down

0 comments on commit 8432ff1

Please sign in to comment.