Skip to content

Commit

Permalink
fixed getAirlineLogo and getCountryFlag methods and added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanExtreme002 committed Dec 22, 2023
1 parent 215f438 commit a8afb76
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 14 deletions.
4 changes: 2 additions & 2 deletions nodejs/FlightRadar24/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class FlightRadar24API {

if (!statusCode.toString().startsWith("4")) {
const splitUrl = firstLogoUrl.split(".");
return [(await response.getContent()), splitUrl[splitUrl.length]];
return [(await response.getContent()), splitUrl[splitUrl.length - 1]];
}

// Get the image by the second airline logo URL.
Expand Down Expand Up @@ -273,7 +273,7 @@ class FlightRadar24API {

if (!statusCode.toString().startsWith("4")) {
const splitUrl = flagUrl.split(".");
return [(await response.getContent()), splitUrl[splitUrl.length]];
return [(await response.getContent()), splitUrl[splitUrl.length - 1]];
}
}

Expand Down
16 changes: 11 additions & 5 deletions nodejs/FlightRadar24/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,21 @@ class APIRequest {
* Return the received content from the request.
*/
async getContent() {
const content = await this.__response.text();
this.__content = content;

if (this.__content !== null) {
return this.__content;
}

let contentType = this.getHeaders()["content-type"];
contentType = contentType == null ? "" : contentType;

// Return a dictionary if the content type is JSON.
if (contentType.includes("application/json")) {
this.__content = JSON.parse(content);
this.__content = await this.__response.json();
}
else if (contentType.includes("text")) {
this.__content = await this.__response.text();
}
else {
this.__content = await this.__response.arrayBuffer();
}
return this.__content;
}
Expand Down
48 changes: 41 additions & 7 deletions nodejs/tests/testApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ describe("Testing FlightRadarAPI version " + version, function() {

for (const iata of expected) {
const details = await frApi.getAirportDetails(iata, 1);
expect(details).to.have.any.keys(targetKeys);
expect(details["airport"]["pluginData"]).to.have.any.keys("details");
expect(details).to.include.all.keys(targetKeys);
expect(details["airport"]["pluginData"]).to.include.all.keys("details");
}
});
});
Expand All @@ -59,7 +59,7 @@ describe("Testing FlightRadarAPI version " + version, function() {

for (const key in results) {
const zone = results[key];
expect(zone).to.have.any.keys(targetKeys);
expect(zone).to.include.all.keys(targetKeys);
}
});
});
Expand All @@ -84,7 +84,7 @@ describe("Testing FlightRadarAPI version " + version, function() {

for (const flight of someFlights) {
const details = await frApi.getFlightDetails(flight);
expect(details).to.have.any.keys(targetKeys);
expect(details).to.include.all.keys(targetKeys);
}
});
});
Expand Down Expand Up @@ -138,17 +138,51 @@ describe("Testing FlightRadarAPI version " + version, function() {
});

describe("Getting Airline Logo", function() {
// TODO: Implement it
const targetAirlines = [["WN", "SWA"], ["G3", "GLO"], ["AD", "AZU"], ["AA", "AAL"], ["TK", "THY"]];
const expected = targetAirlines.length * 0.8;

const icao = [];

for (const airline of targetAirlines) {
icao.push(airline[1]);
}

let message = "Expected getting logos from at least " + Math.trunc(expected);
message += " of the following airlines: " + icao.join(", ") + ".";

it(message, async function() {
let found = 0;

for (const airline of targetAirlines) {
const result = await frApi.getAirlineLogo(airline[0], airline[1]);
found = result != null && result[0].byteLength > 512 ? found + 1 : found;
}
expect(found).to.be.above(expected - 1);
});
});

describe("Getting Country Flag", function() {
// TODO: Implement it
const targetCountries = ["United States", "Brazil", "Egypt", "Japan", "South Korea", "Canada"];
const expected = targetCountries.length * 0.8;

let message = "Expected getting flags from at least " + Math.trunc(expected);
message += " of the following countries: " + targetCountries.join(", ") + ".";

it(message, async function() {
let found = 0;

for (const country of targetCountries) {
const result = await frApi.getCountryFlag(country);
found = result != null && result[0].byteLength > 512 ? found + 1 : found;
}
expect(found).to.be.above(expected - 1);
});
});

describe("Getting Bounds by Point", function() {
const expected = "52.58594974202871,52.54997688140807,13.253064418048115,13.3122478541492";

it("Formula for getting bounds is correct.", async function() {
it("Formula for calculating bounds is correct.", async function() {
const bounds = frApi.getBoundsByPoint(52.567967, 13.282644, 2000);
expect(bounds).to.be.equal(expected);
});
Expand Down

0 comments on commit a8afb76

Please sign in to comment.