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'); } - } };