Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/Services/Air/AirParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,15 @@
const prices = priceResult['air:AirPricingSolution'];
const priceKeys = Object.keys(prices);

const pricing = prices[priceKeys[0]]['air:AirPricingInfo'];
const cheapestKey = priceKeys.length > 1
? priceKeys.reduce((minKey, key) => (

Check warning on line 205 in src/Services/Air/AirParser.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add an initial value to this "reduce()" call.

See more on https://sonarcloud.io/project/issues?id=Travelport-Ukraine_uapi-json&issues=AZzhal6q9JS2QyFtjpI_&open=AZzhal6q9JS2QyFtjpI_&pullRequest=680
parseFloat(prices[key].TotalPrice.slice(3)) < parseFloat(prices[minKey].TotalPrice.slice(3))

Check warning on line 206 in src/Services/Air/AirParser.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `Number.parseFloat` over `parseFloat`.

See more on https://sonarcloud.io/project/issues?id=Travelport-Ukraine_uapi-json&issues=AZzhal6q9JS2QyFtjpJA&open=AZzhal6q9JS2QyFtjpJA&pullRequest=680

Check warning on line 206 in src/Services/Air/AirParser.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `Number.parseFloat` over `parseFloat`.

See more on https://sonarcloud.io/project/issues?id=Travelport-Ukraine_uapi-json&issues=AZzhal6q9JS2QyFtjpJB&open=AZzhal6q9JS2QyFtjpJB&pullRequest=680
? key
: minKey
))
: priceKeys[0];

const pricing = prices[cheapestKey]['air:AirPricingInfo'];

return Object.keys(pricing)
.reduce((acc, right) => ({
Expand Down Expand Up @@ -381,6 +389,10 @@

const pricingInfo = pricingInfos.find((info) => info.$.Key === reservationKey);

if (!pricingInfo) {
return;
}

pricingInfo['air:PassengerType'].push({
$: {
BookingTravelerRef: 'P_' + index,
Expand Down Expand Up @@ -816,8 +828,8 @@

function airCancelTicket(obj) {
if (
!obj['air:VoidResultInfo']
|| obj['air:VoidResultInfo'].ResultType !== 'Success'

Check warning on line 832 in src/Services/Air/AirParser.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer using an optional chain expression instead, as it's more concise and easier to read.

See more on https://sonarcloud.io/project/issues?id=Travelport-Ukraine_uapi-json&issues=AZzhal6q9JS2QyFtjpJC&open=AZzhal6q9JS2QyFtjpJC&pullRequest=680
) {
throw new AirRuntimeError.TicketCancelResultUnknown(obj);
}
Expand Down Expand Up @@ -925,8 +937,8 @@
const providerInfoKey = providerInfo.Key;
const resRemarks = remarks[providerInfoKey] || [];
const splitBookings = (
providerInfo['universal:ProviderReservationDetails']
&& providerInfo['universal:ProviderReservationDetails'].DivideDetails === 'true'

Check warning on line 941 in src/Services/Air/AirParser.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer using an optional chain expression instead, as it's more concise and easier to read.

See more on https://sonarcloud.io/project/issues?id=Travelport-Ukraine_uapi-json&issues=AZzhal6q9JS2QyFtjpJD&open=AZzhal6q9JS2QyFtjpJD&pullRequest=680
)
? resRemarks.reduce(
(acc, remark) => {
Expand Down
39 changes: 39 additions & 0 deletions test/Air/AirParser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,45 @@
test(jsonResult);
}).catch((err) => assert(false, 'Error during parsing' + err.stack));
});

it('should correctly select cheapest solution when it is not first', () => {
const passengers = [{
lastName: 'ENEKEN',
firstName: 'SKYWALKER',
passCountry: 'UA',
passNumber: 'ES221731',
birthDate: '19680725',
Age: 30,
gender: 'M',
ageCategory: 'ADT',
}];

const uParser = new Parser(null, 'v52_0', { passengers });
const parseFunction = airParser.AIR_PRICE_REQUEST_PRICING_SOLUTION_XML;
const xml = fs.readFileSync(`${xmlFolder}/AirPricingSolution.2AirPrice.cheapest-second.xml`).toString();
return uParser.parse(xml).then((json) => {
const jsonResult = parseFunction.call(uParser, json);
const airprice = jsonResult['air:AirPricingSolution'];
const airpricexml = jsonResult['air:AirPricingSolution_XML'];
assert(airprice, 'no air:AirPricingSolution');
assert(airpricexml, 'no xml object');
assert(airprice.TotalPrice, 'No total price');
assert(airprice.Key, 'No key');
assert(airprice.Taxes, 'No taxes');
assert(airpricexml['air:AirPricingInfo_XML'], 'no air:AirPricingInfo_XML');
assert(airpricexml['air:AirSegment_XML'], 'no air:AirSegment_XML');
// The cheapest solution (ou8oAxJKTlGiEXhqo3pIZA== with EUR178.88) should be selected,
// not the first one (FBdwwNHxRbC87v3+2SGmfQ== with EUR227.88).
assert.equal(airprice.TotalPrice, 'EUR178.88', 'Should select cheapest solution');
assert.equal(airprice.Key, 'ou8oAxJKTlGiEXhqo3pIZA==', 'Should use key of cheapest solution');
// Verify passenger type refs are present in the result XML and associated
// with the correct pricing info key from the cheapest solution.
const pricingInfoXml = airpricexml['air:AirPricingInfo_XML'];
assert(pricingInfoXml.indexOf('BookingTravelerRef') !== -1, 'BookingTravelerRef should be present');

Check warning on line 1199 in test/Air/AirParser.test.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use `.includes()`, rather than `.indexOf()`, when checking for existence.

See more on https://sonarcloud.io/project/issues?id=Travelport-Ukraine_uapi-json&issues=AZzhalyu9JS2QyFtjpI7&open=AZzhalyu9JS2QyFtjpI7&pullRequest=680
// AirPricingInfo key of the cheapest solution should appear in the XML
assert(pricingInfoXml.indexOf('0cSmjfEaSVecrbEn/Ae8Eg==') !== -1, 'AirPricingInfo key of cheapest solution should be present');

Check warning on line 1201 in test/Air/AirParser.test.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use `.includes()`, rather than `.indexOf()`, when checking for existence.

See more on https://sonarcloud.io/project/issues?id=Travelport-Ukraine_uapi-json&issues=AZzhalyu9JS2QyFtjpI8&open=AZzhalyu9JS2QyFtjpI8&pullRequest=680
}).catch((err) => assert(false, 'Error during parsing' + err.stack));
});
});

it('should test a request with hosttoken', () => {
Expand Down Expand Up @@ -1316,7 +1355,7 @@

// Passengers
pricingInfo.passengers.forEach(
(p) => {

Check failure on line 1358 in test/Air/AirParser.test.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this code to not nest functions more than 4 levels deep.

See more on https://sonarcloud.io/project/issues?id=Travelport-Ukraine_uapi-json&issues=AZzhalyu9JS2QyFtjpI9&open=AZzhalyu9JS2QyFtjpI9&pullRequest=680
expect(p).to.be.an('object');
expect(p).to.include.all.keys(['uapi_passenger_ref', 'isTicketed']);
expect(p.uapi_passenger_ref).to.be.a('string');
Expand All @@ -1332,7 +1371,7 @@

expect(pricingInfo.passengersCount).to.be.an('object');
Object.keys(pricingInfo.passengersCount).forEach(
(ptc) => expect(pricingInfo.passengersCount[ptc]).to.be.a('number')

Check failure on line 1374 in test/Air/AirParser.test.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this code to not nest functions more than 4 levels deep.

See more on https://sonarcloud.io/project/issues?id=Travelport-Ukraine_uapi-json&issues=AZzhalyu9JS2QyFtjpI-&open=AZzhalyu9JS2QyFtjpI-&pullRequest=680
);
expect(pricingInfo.taxesInfo).to.be.an('array');
pricingInfo.taxesInfo.forEach(
Expand Down
Loading