Skip to content

Commit

Permalink
DB E2E tests: adjust assertValidTickets ✅
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulSut authored and derhuerst committed Mar 12, 2024
1 parent 191b9ab commit d3bc9d3
Showing 1 changed file with 16 additions and 27 deletions.
43 changes: 16 additions & 27 deletions test/e2e/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

}
};

Expand Down

0 comments on commit d3bc9d3

Please sign in to comment.