DB: add end-to-end test for tickets

Co-Authored-By: Jannis R <mail@jannisr.de>
This commit is contained in:
Paul Sutter 2023-12-26 13:49:04 +01:00 committed by Jannis R
parent 248adb5f72
commit 9365c00aaf
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5

View file

@ -57,6 +57,49 @@ const assertValidPrice = (t, p) => {
}
};
const assertValidTickets = (test, tickets) => {
test.ok(tickets);
for (let fare of tickets) {
if (fare.name !== undefined) {
test.equal(typeof fare.name, 'string');
test.ok(fare.name);
} else {
test.fail('Mandatory field "name" is missing');
}
if (fare.priceObj !== undefined) {
if (fare.priceObj.amount !== undefined) {
test.equal(typeof fare.priceObj.amount, 'number');
test.ok(fare.priceObj.amount > 0);
} else {
test.fail('Mandatory field "amount" in "priceObj" is missing');
}
// Check optional currency field
if (fare.priceObj.currency !== undefined) {
test.equal(typeof fare.priceObj.currency, 'string');
}
} else {
test.fail('Mandatory field "priceObj" in "ticket" is missing');
}
// Check optional fields
if (tickets.addData !== undefined) {
test.equal(typeof tickets.addData, 'string');
}
if (fare.addDataTicketInfo !== undefined) {
test.equal(typeof fare.addDataTicketInfo, 'string');
}
if (fare.addDataTicketDetails !== undefined) {
test.equal(typeof fare.addDataTicketDetails, 'string');
}
if (fare.addDataTravelInfo !== undefined) {
test.equal(typeof fare.addDataTravelInfo, 'string');
}
if (fare.firstClass !== undefined) {
test.equal(typeof fare.firstClass, 'boolean');
}
}
};
const client = createClient(dbProfile, 'public-transport/hafas-client:test');
const berlinHbf = '8011160';
@ -93,6 +136,29 @@ tap.test('journeys  Berlin Schwedter Str. to München Hbf', async (t) => {
if (journey.price) {
assertValidPrice(t, journey.price);
}
if (journey.tickets) {
assertValidTickets(t, journey.tickets);
}
}
t.end();
});
tap.test('refreshJourney valid tickets', async (t) => {
const journeysRes = await client.journeys(berlinHbf, münchenHbf, {
results: 4,
departure: when,
stopovers: true,
});
const refreshWithoutTicketsRes = await client.refreshJourney(journeysRes.journeys[0].refreshToken, {
tickets: false,
});
const refreshWithTicketsRes = await client.refreshJourney(journeysRes.journeys[0].refreshToken, {
tickets: true,
});
for (let res of [refreshWithoutTicketsRes, refreshWithTicketsRes]) {
if (res.journey.tickets !== undefined) {
assertValidTickets(t, res.journey.tickets);
}
}
t.end();