From d3bc9d351db7c4f1ccdebb42dafa1604e8502f7f Mon Sep 17 00:00:00 2001 From: Paul Sutter Date: Sun, 18 Feb 2024 17:59:12 +0100 Subject: [PATCH] =?UTF-8?q?DB=20E2E=20tests:=20adjust=20assertValidTickets?= =?UTF-8?q?=20=E2=9C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/e2e/db.js | 43 ++++++++++++++++--------------------------- 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/test/e2e/db.js b/test/e2e/db.js index ab340f3e..31ed956e 100644 --- a/test/e2e/db.js +++ b/test/e2e/db.js @@ -58,45 +58,34 @@ const assertValidPrice = (t, p) => { }; const assertValidTickets = (test, tickets) => { - test.ok(tickets); + test.ok(Array.isArray(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'); + test.equal(typeof fare.name, 'string', 'Mandatory field "name" is missing or not a string'); + test.ok(fare.name); + + test.ok(isObj(fare.priceObj), 'Mandatory field "priceObj" is missing or not an object'); + test.equal(typeof fare.priceObj.amount, 'number', 'Mandatory field "amount" in "priceObj" is missing or not a number'); + test.ok(fare.priceObj.amount > 0); + if ('currency' in fare.priceObj) { + test.equal(typeof fare.priceObj.currency, 'string'); } + // Check optional fields - if (tickets.addData !== undefined) { - test.equal(typeof tickets.addData, 'string'); + if ('addData' in fare) { + test.equal(typeof fare.addData, 'string'); } - if (fare.addDataTicketInfo !== undefined) { + if ('addDataTicketInfo' in fare) { test.equal(typeof fare.addDataTicketInfo, 'string'); } - if (fare.addDataTicketDetails !== undefined) { + if ('addDataTicketDetails' in fare) { test.equal(typeof fare.addDataTicketDetails, 'string'); } - if (fare.addDataTravelInfo !== undefined) { + if ('addDataTravelInfo' in fare) { test.equal(typeof fare.addDataTravelInfo, 'string'); } - if (fare.firstClass !== undefined) { + if ('addDataTravelDetails' in fare) { test.equal(typeof fare.firstClass, 'boolean'); } - } };