Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
professoralex13 committed Nov 13, 2024
1 parent 68b9e67 commit c68d8ba
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 85 deletions.
19 changes: 9 additions & 10 deletions src/database/src/output/airport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use serde::Serialize;
use crate::{
enums::{IfrCapability, RunwaySurfaceCode},
math::{Coordinates, Degrees, Feet},
sql_structs,
v2,
sql_structs, v2,
};

#[serde_with::skip_serializing_none]
Expand All @@ -19,18 +18,18 @@ pub struct Airport {
/// For most airports, this will be the same as the first two letters of the `ident`, such as `EG` for `EGLL`, or
/// `LF` for `LFPG`.
/// Airport type (see Appendix 3.38) (v2 only)
pub airport_type: String,
/// The notable exceptions to this are airports in the US, Canada, and Australia.
pub icao_code: String,
pub airport_type: Option<String>,
/// The geographic location of the airport's reference point
pub location: Coordinates,
/// The airport's general area (v2 only)
city: Option<String>,
continent: Option<String>,
country: Option<String>,
country_3letter: Option<String>,
state: Option<String>,
state_2letter: Option<String>,
pub city: Option<String>,
pub continent: Option<String>,
pub country: Option<String>,
pub country_3letter: Option<String>,
pub state: Option<String>,
pub state_2letter: Option<String>,
/// The formal name of the airport such as `KENNEDY INTL` for `KJFK` or `HEATHROW` for `EGLL`
pub name: String,
pub ifr_capability: IfrCapability,
Expand Down Expand Up @@ -90,7 +89,7 @@ impl From<v2::sql_structs::Airports> for Airport {
lat: airport.airport_ref_latitude,
long: airport.airport_ref_longitude,
},
airport_type: airport.airport_type,
airport_type: Some(airport.airport_type),
area_code: airport.area_code,
iata_ident: airport.ata_iata_code,
city: airport.city,
Expand Down
6 changes: 3 additions & 3 deletions src/database/src/output/database_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ pub struct DatabaseInfo {
/// The AIRAC cycle that this database is.
///
/// e.g. `2313` or `2107`
airac_cycle: String,
pub airac_cycle: String,
/// The effective date range of this AIRAC cycle.
effective_from_to: (String, String),
pub effective_from_to: (String, String),
/// The effective date range of the previous AIRAC cycle
previous_from_to: (String, String),
pub previous_from_to: (String, String),
}

impl DatabaseInfo {
Expand Down
28 changes: 4 additions & 24 deletions src/test/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,32 +287,12 @@ async function lifeCycle() {
}
}

beforeAll(async () => {
const navigationDataInterface = new NavigraphNavigationDataInterface()

const downloadUrl = process.env.NAVIGATION_DATA_SIGNED_URL ?? "local"
const downloadUrlV2 = process.env.NAVIGATION_DATA_SIGNED_URL_V2 ?? "local"

// Utility function to convert onReady to a promise
const waitForReady = (navDataInterface: NavigraphNavigationDataInterface): Promise<void> => {
return new Promise((resolve, _reject) => {
navDataInterface.onReady(() => resolve())
})
}

await waitForReady(navigationDataInterface)

if (downloadUrl !== "local") {
await navigationDataInterface.download_navigation_data(downloadUrl)
}

if (downloadUrlV2 !== "local") {
await navigationDataInterface.download_navigation_data(downloadUrlV2)
}
}, 30000)

void lifeCycle()

beforeAll(() => {
runLifecycle = true;
})

// Cancel the lifeCycle after all tests have completed
afterAll(() => {
runLifecycle = false
Expand Down
51 changes: 29 additions & 22 deletions src/test/v1.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,44 @@ const navigationDataInterface = new NavigraphNavigationDataInterface()
describe("DFDv1", () => {
// This will run once for each test file
beforeAll(async () => {
let pkgs = await navigationDataInterface.list_available_packages(true, false)
const downloadUrl = process.env.NAVIGATION_DATA_SIGNED_URL ?? "local"

// const target_package = pkgs.find((info) => info.cycle.format === 'dfd' && info.cycle.cycle === '2101')

// if(!target_package) {
// throw new Error('V1 Database with cycle 2101 was not found in available packages')
// }

navigationDataInterface
.set_active_package(pkgs[0].uuid)
.then(val => {
console.log(val)
})
.catch(err => {
console.error(err)
const waitForReady = (navDataInterface: NavigraphNavigationDataInterface): Promise<void> => {
return new Promise((resolve, _reject) => {
navDataInterface.onReady(() => resolve())
})
}

await waitForReady(navigationDataInterface)

if(downloadUrl === "local") {
let pkgs = await navigationDataInterface.list_available_packages(true, false)

const target_package = pkgs.find((info) => info.cycle.format === 'dfd' && info.cycle.cycle === '2410')

if(!target_package) {
throw new Error('V1 Database with cycle 2410 was not found in available packages')
}

navigationDataInterface.set_active_package(target_package.uuid);
} else {
await navigationDataInterface.download_navigation_data(downloadUrl, true)
}
}, 30000)

it("Active database", async () => {
const packageInfo = await navigationDataInterface.get_active_package()

expect(packageInfo).toStrictEqual({
is_bundled: !process.env.NAVIGATION_DATA_SIGNED_URL,
path: "/active",
uuid: "12313",
path: "\\work/navigation-data/active",
uuid: "481bc1fd-2712-3e42-9183-c4463ad1d952",
cycle: {
cycle: "2101",
cycle: "2410",
revision: "1",
name: "Navigraph Avionics",
format: "dfd",
validityPeriod: "2021-01-25/2021-02-20",
validityPeriod: "2024-10-03/2024-10-30",
},
} satisfies PackageInfo)
})
Expand All @@ -67,9 +74,9 @@ describe("DFDv1", () => {
const info = await navigationDataInterface.get_database_info()

expect(info).toStrictEqual({
airac_cycle: "2313",
effective_from_to: ["28-12-2023", "25-01-2024"],
previous_from_to: ["30-11-2023", "28-12-2023"],
airac_cycle: "2410",
effective_from_to: ["03-10-2024", "31-10-2024"],
previous_from_to: ["05-09-2024", "03-10-2024"],
} satisfies DatabaseInfo)
})

Expand Down Expand Up @@ -153,7 +160,7 @@ describe("DFDv1", () => {
it("Get airports in range", async () => {
const airports = await navigationDataInterface.get_airports_in_range({ lat: 51.468, long: -0.4551 }, 640)

expect(airports.length).toBe(1686)
expect(airports.length).toBe(1688)
})

it("Get waypoints in range", async () => {
Expand Down
70 changes: 44 additions & 26 deletions src/test/v2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,44 @@ const navigationDataInterface = new NavigraphNavigationDataInterface()
describe("DFDv2", () => {
// This will run once for each test file
beforeAll(async () => {
let pkgs = await navigationDataInterface.list_available_packages(true, false)
const downloadUrl = process.env.NAVIGATION_DATA_SIGNED_URL_V2 ?? "local"

// const target_package = pkgs.find(info => info.cycle.format === "dfdv2" && info.cycle.cycle === "2401")

// if (!target_package) {
// throw new Error("V2 Database with cycle 2401 was not found in available packages")
// }

navigationDataInterface
.set_active_package(pkgs[1].uuid)
.then(val => {
console.log(val)
})
.catch(err => {
console.error(err)
const waitForReady = (navDataInterface: NavigraphNavigationDataInterface): Promise<void> => {
return new Promise((resolve, _reject) => {
navDataInterface.onReady(() => resolve())
})
}

await waitForReady(navigationDataInterface)

if(downloadUrl === "local") {
let pkgs = await navigationDataInterface.list_available_packages(true, false)

const target_package = pkgs.find((info) => info.cycle.format === 'dfdv2' && info.cycle.cycle === '2410')

if(!target_package) {
throw new Error('V2 Database with cycle 2410 was not found in available packages')
}

navigationDataInterface.set_active_package(target_package.uuid);
} else {
await navigationDataInterface.download_navigation_data(downloadUrl, true)
}
}, 30000)

it("Active database", async () => {
const packageInfo = await navigationDataInterface.get_active_package()

expect(packageInfo).toStrictEqual({
is_bundled: !process.env.NAVIGATION_DATA_SIGNED_URL,
path: "/active",
uuid: "12313",
path: "\\work/navigation-data/active",
uuid: "37735bb9-635b-37be-be1b-c5f9a89b7672",
cycle: {
cycle: "2401",
cycle: "2410",
revision: "1",
name: "Navigraph Avionics",
format: "dfdv2",
validityPeriod: "2024-01-25/2024-02-21",
validityPeriod: "2024-10-03/2024-10-30"
},
} satisfies PackageInfo)
})
Expand All @@ -67,31 +74,39 @@ describe("DFDv2", () => {
const info = await navigationDataInterface.get_database_info()

expect(info).toStrictEqual({
airac_cycle: "2313",
effective_from_to: ["28-12-2023", "25-01-2024"],
previous_from_to: ["30-11-2023", "28-12-2023"],
airac_cycle: "2410",
effective_from_to: ["03-10-2024", "30-10-2024"],
previous_from_to: ["depricated", "depricated"],
} satisfies DatabaseInfo)
})

it("Fetch airport", async () => {
const airport = await navigationDataInterface.get_airport("KJFK")

expect(airport).toStrictEqual({
airport_type: "C",
area_code: "USA",
city: "NEW YORK",
continent: "NORTH AMERICA",
country: "UNITED STATES",
country_3letter: "USA",
ident: "KJFK",
icao_code: "K6",
location: {
lat: 40.63992778,
long: -73.77869167,
lat: 40.63992777777778,
long: -73.77869166666666,
},
name: "KENNEDY INTL",
ifr_capability: IfrCapability.Yes,
longest_runway_surface_code: RunwaySurfaceCode.Hard,
magnetic_variation: -13,
elevation: 13,
transition_altitude: 18000,
transition_level: 18000,
speed_limit: 250,
speed_limit_altitude: 10000,
state: "NEW YORK",
state_2letter: "NY",
iata_ident: "JFK",
} satisfies Airport)
})
Expand All @@ -103,11 +118,14 @@ describe("DFDv2", () => {

expect(waypoints[0]).toStrictEqual({
area_code: "SPA",
continent: "PACIFIC",
country: "NEW ZEALAND",
datum_code: "WGE",
icao_code: "NZ",
ident: "GLENN",
location: {
lat: -42.88116389,
long: 172.83973889,
lat: -42.88116388888889,
long: 172.8397388888889,
},
name: "GLENN",
} satisfies Waypoint)
Expand Down Expand Up @@ -162,7 +180,7 @@ describe("DFDv2", () => {
it("Get airports in range", async () => {
const airports = await navigationDataInterface.get_airports_in_range({ lat: 51.468, long: -0.4551 }, 640)

expect(airports.length).toBe(1686)
expect(airports.length).toBe(1506)
})

it("Get waypoints in range", async () => {
Expand Down

0 comments on commit c68d8ba

Please sign in to comment.