UNPKG

aviation-model

Version:

Public methods for querying the information from aviation-pg

177 lines (155 loc) 5.31 kB
"use strict"; var assert = require("assert"); var methods = require("../src/index.js"); var getAirportJson = methods.getAirportJson; var getAirportData = methods.getAirportData; var expectedAirport = { airport_id: "Alicante%E2%80%93Elche_Airport", latitude: "38°16′56″N", longitude: "00°33′29″W", name: "Alicante–Elche Airport", nickname: "Aeropuerto de Alicante-Elche", iata: "ALC", icao: "LEAL" }; var expectedInstance = { location: "38°16′56″N 00°33′29″W", airport_id: "Alicante%E2%80%93Elche_Airport", latitude: "38°16′56″N", longitude: "00°33′29″W", name: "Alicante–Elche Airport", nickname: "Aeropuerto de Alicante-Elche", iata: "ALC", icao: "LEAL", "dd_latitude": 38.282222222222224, "dd_longitude": -0.5580555555555556 }; var expectedSFOAirport = { "location": "37°37′08″N 122°22′30″W", "airport_id": "San_Francisco_International_Airport", "latitude": "37°37′08″N", "longitude": "122°22′30″W", "name": "San Francisco International Airport", "nickname": "IATA: SFO", "iata": "SFO", "icao": "KSFO", "dd_latitude": 37.61888888888889, "dd_longitude": -122.375 }; var expectedLocation = expectedAirport.latitude + " " + expectedAirport.longitude; describe("Airports\n", function () { describe("getAirportData method", function () { it("should return all the airport data by airline_id.", function (done) { getAirportData({ value: "Alicante%E2%80%93Elche_Airport", type: "airport_id" }, function (err, data) { if (err) { throw err; } assert.deepEqual(JSON.stringify(data, null, 2), JSON.stringify(expectedInstance, null, 2), "the location method fails. expected:\n" + JSON.stringify(expectedInstance, null, 2) + "\n\nbut got: \n" + JSON.stringify(data, null, 2)); done(); }); }); it("should return all the airport data for SFO by airline_id.", function (done) { getAirportData({ value: "San_Francisco_International_Airport", type: "airport_id" }, function (err, data) { if (err) { throw err; } assert.deepEqual(JSON.stringify(data, null, 2), JSON.stringify(expectedSFOAirport, null, 2), "the location method fails. expected:" + JSON.stringify(expectedSFOAirport, null, 2) + "\n\nbut got: \n" + JSON.stringify(data, null, 2)); done(); }); }); it("should use the name method with the ICAO code.", function (done) { getAirportData({ value: "LEAL", type: "icao", method: "name" }, function (err, data) { if (err) { throw err; } assert.deepEqual(data, expectedAirport.name, "the location method fails. expected:" + expectedAirport.name + "\n\nbut got: \n" + data); done(); }); }); it("should use the location method with the IATA code", function (done) { getAirportData({ value: "ALC", type: "iata", method: "location" }, function (err, data) { if (err) { throw err; } assert.deepEqual(data, expectedLocation, "the location method fails, expected:" + expectedLocation + "\n\nbut got: \n" + data); done(); }); }); it("should use the latitude method with the IATA code", function (done) { getAirportData({ value: "ALC", type: "iata", method: "latitude" }, function (err, data) { if (err) { throw err; } assert.deepEqual(data, expectedAirport.latitude, "the location method fails, expected:" + expectedAirport.latitude + " \n\nbut got: \n" + data); done(); }); }); it("should use the longitude method with the IATA code", function (done) { getAirportData({ value: "ALC", type: "iata", method: "longitude" }, function (err, data) { if (err) { throw err; } assert.deepEqual(data, expectedAirport.longitude, "the location method fails, expected:" + expectedAirport.longitude + " \n\nbut got: \n" + data); done(); }); }); }); }); describe("getAirportJson", function () { it("should return the expected airport data.", function (done) { getAirportJson({ airport_id: "Alicante%E2%80%93Elche_Airport" }, function (err, airport) { if (err) { throw err; } assert.deepEqual(airport, expectedInstance, "the airport instance doesn't match the expected value"); assert.equal(airport.name, expectedInstance.name, "getLatitude method doesn't work."); assert.equal(airport.latitude, expectedInstance.latitude, "getLatitude method doesn't work."); assert.equal(airport.longitude, expectedInstance.longitude, "getLatitude method doesn't work."); assert.equal(airport.location, expectedInstance.latitude + " " + expectedInstance.longitude, "getLatitude method doesn't work."); done(); }); }); it("should return the error for none.", function (done) { getAirportJson({ airport_id: "none" }, function (err) { assert(err, true); done(); }); }); });