From 9365c00aaf5625144d41cf4676ae4bf7eb24da22 Mon Sep 17 00:00:00 2001 From: Paul Sutter Date: Tue, 26 Dec 2023 13:49:04 +0100 Subject: [PATCH] =?UTF-8?q?DB:=20add=20end-to-end=20test=20for=20tickets?= =?UTF-8?q?=20=E2=9C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Jannis R --- test/e2e/db.js | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/test/e2e/db.js b/test/e2e/db.js index b5b96f93..a0f0426b 100644 --- a/test/e2e/db.js +++ b/test/e2e/db.js @@ -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();