Skip to content

Commit c68d8ba

Browse files
fix: tests
1 parent 68b9e67 commit c68d8ba

File tree

5 files changed

+89
-85
lines changed

5 files changed

+89
-85
lines changed

src/database/src/output/airport.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ use serde::Serialize;
33
use crate::{
44
enums::{IfrCapability, RunwaySurfaceCode},
55
math::{Coordinates, Degrees, Feet},
6-
sql_structs,
7-
v2,
6+
sql_structs, v2,
87
};
98

109
#[serde_with::skip_serializing_none]
@@ -19,18 +18,18 @@ pub struct Airport {
1918
/// For most airports, this will be the same as the first two letters of the `ident`, such as `EG` for `EGLL`, or
2019
/// `LF` for `LFPG`.
2120
/// Airport type (see Appendix 3.38) (v2 only)
22-
pub airport_type: String,
2321
/// The notable exceptions to this are airports in the US, Canada, and Australia.
2422
pub icao_code: String,
23+
pub airport_type: Option<String>,
2524
/// The geographic location of the airport's reference point
2625
pub location: Coordinates,
2726
/// The airport's general area (v2 only)
28-
city: Option<String>,
29-
continent: Option<String>,
30-
country: Option<String>,
31-
country_3letter: Option<String>,
32-
state: Option<String>,
33-
state_2letter: Option<String>,
27+
pub city: Option<String>,
28+
pub continent: Option<String>,
29+
pub country: Option<String>,
30+
pub country_3letter: Option<String>,
31+
pub state: Option<String>,
32+
pub state_2letter: Option<String>,
3433
/// The formal name of the airport such as `KENNEDY INTL` for `KJFK` or `HEATHROW` for `EGLL`
3534
pub name: String,
3635
pub ifr_capability: IfrCapability,
@@ -90,7 +89,7 @@ impl From<v2::sql_structs::Airports> for Airport {
9089
lat: airport.airport_ref_latitude,
9190
long: airport.airport_ref_longitude,
9291
},
93-
airport_type: airport.airport_type,
92+
airport_type: Some(airport.airport_type),
9493
area_code: airport.area_code,
9594
iata_ident: airport.ata_iata_code,
9695
city: airport.city,

src/database/src/output/database_info.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ pub struct DatabaseInfo {
99
/// The AIRAC cycle that this database is.
1010
///
1111
/// e.g. `2313` or `2107`
12-
airac_cycle: String,
12+
pub airac_cycle: String,
1313
/// The effective date range of this AIRAC cycle.
14-
effective_from_to: (String, String),
14+
pub effective_from_to: (String, String),
1515
/// The effective date range of the previous AIRAC cycle
16-
previous_from_to: (String, String),
16+
pub previous_from_to: (String, String),
1717
}
1818

1919
impl DatabaseInfo {

src/test/setup.ts

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -287,32 +287,12 @@ async function lifeCycle() {
287287
}
288288
}
289289

290-
beforeAll(async () => {
291-
const navigationDataInterface = new NavigraphNavigationDataInterface()
292-
293-
const downloadUrl = process.env.NAVIGATION_DATA_SIGNED_URL ?? "local"
294-
const downloadUrlV2 = process.env.NAVIGATION_DATA_SIGNED_URL_V2 ?? "local"
295-
296-
// Utility function to convert onReady to a promise
297-
const waitForReady = (navDataInterface: NavigraphNavigationDataInterface): Promise<void> => {
298-
return new Promise((resolve, _reject) => {
299-
navDataInterface.onReady(() => resolve())
300-
})
301-
}
302-
303-
await waitForReady(navigationDataInterface)
304-
305-
if (downloadUrl !== "local") {
306-
await navigationDataInterface.download_navigation_data(downloadUrl)
307-
}
308-
309-
if (downloadUrlV2 !== "local") {
310-
await navigationDataInterface.download_navigation_data(downloadUrlV2)
311-
}
312-
}, 30000)
313-
314290
void lifeCycle()
315291

292+
beforeAll(() => {
293+
runLifecycle = true;
294+
})
295+
316296
// Cancel the lifeCycle after all tests have completed
317297
afterAll(() => {
318298
runLifecycle = false

src/test/v1.spec.ts

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,37 +28,44 @@ const navigationDataInterface = new NavigraphNavigationDataInterface()
2828
describe("DFDv1", () => {
2929
// This will run once for each test file
3030
beforeAll(async () => {
31-
let pkgs = await navigationDataInterface.list_available_packages(true, false)
31+
const downloadUrl = process.env.NAVIGATION_DATA_SIGNED_URL ?? "local"
3232

33-
// const target_package = pkgs.find((info) => info.cycle.format === 'dfd' && info.cycle.cycle === '2101')
34-
35-
// if(!target_package) {
36-
// throw new Error('V1 Database with cycle 2101 was not found in available packages')
37-
// }
38-
39-
navigationDataInterface
40-
.set_active_package(pkgs[0].uuid)
41-
.then(val => {
42-
console.log(val)
43-
})
44-
.catch(err => {
45-
console.error(err)
33+
const waitForReady = (navDataInterface: NavigraphNavigationDataInterface): Promise<void> => {
34+
return new Promise((resolve, _reject) => {
35+
navDataInterface.onReady(() => resolve())
4636
})
37+
}
38+
39+
await waitForReady(navigationDataInterface)
40+
41+
if(downloadUrl === "local") {
42+
let pkgs = await navigationDataInterface.list_available_packages(true, false)
43+
44+
const target_package = pkgs.find((info) => info.cycle.format === 'dfd' && info.cycle.cycle === '2410')
45+
46+
if(!target_package) {
47+
throw new Error('V1 Database with cycle 2410 was not found in available packages')
48+
}
49+
50+
navigationDataInterface.set_active_package(target_package.uuid);
51+
} else {
52+
await navigationDataInterface.download_navigation_data(downloadUrl, true)
53+
}
4754
}, 30000)
4855

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

5259
expect(packageInfo).toStrictEqual({
5360
is_bundled: !process.env.NAVIGATION_DATA_SIGNED_URL,
54-
path: "/active",
55-
uuid: "12313",
61+
path: "\\work/navigation-data/active",
62+
uuid: "481bc1fd-2712-3e42-9183-c4463ad1d952",
5663
cycle: {
57-
cycle: "2101",
64+
cycle: "2410",
5865
revision: "1",
5966
name: "Navigraph Avionics",
6067
format: "dfd",
61-
validityPeriod: "2021-01-25/2021-02-20",
68+
validityPeriod: "2024-10-03/2024-10-30",
6269
},
6370
} satisfies PackageInfo)
6471
})
@@ -67,9 +74,9 @@ describe("DFDv1", () => {
6774
const info = await navigationDataInterface.get_database_info()
6875

6976
expect(info).toStrictEqual({
70-
airac_cycle: "2313",
71-
effective_from_to: ["28-12-2023", "25-01-2024"],
72-
previous_from_to: ["30-11-2023", "28-12-2023"],
77+
airac_cycle: "2410",
78+
effective_from_to: ["03-10-2024", "31-10-2024"],
79+
previous_from_to: ["05-09-2024", "03-10-2024"],
7380
} satisfies DatabaseInfo)
7481
})
7582

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

156-
expect(airports.length).toBe(1686)
163+
expect(airports.length).toBe(1688)
157164
})
158165

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

src/test/v2.spec.ts

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,37 +28,44 @@ const navigationDataInterface = new NavigraphNavigationDataInterface()
2828
describe("DFDv2", () => {
2929
// This will run once for each test file
3030
beforeAll(async () => {
31-
let pkgs = await navigationDataInterface.list_available_packages(true, false)
31+
const downloadUrl = process.env.NAVIGATION_DATA_SIGNED_URL_V2 ?? "local"
3232

33-
// const target_package = pkgs.find(info => info.cycle.format === "dfdv2" && info.cycle.cycle === "2401")
34-
35-
// if (!target_package) {
36-
// throw new Error("V2 Database with cycle 2401 was not found in available packages")
37-
// }
38-
39-
navigationDataInterface
40-
.set_active_package(pkgs[1].uuid)
41-
.then(val => {
42-
console.log(val)
43-
})
44-
.catch(err => {
45-
console.error(err)
33+
const waitForReady = (navDataInterface: NavigraphNavigationDataInterface): Promise<void> => {
34+
return new Promise((resolve, _reject) => {
35+
navDataInterface.onReady(() => resolve())
4636
})
37+
}
38+
39+
await waitForReady(navigationDataInterface)
40+
41+
if(downloadUrl === "local") {
42+
let pkgs = await navigationDataInterface.list_available_packages(true, false)
43+
44+
const target_package = pkgs.find((info) => info.cycle.format === 'dfdv2' && info.cycle.cycle === '2410')
45+
46+
if(!target_package) {
47+
throw new Error('V2 Database with cycle 2410 was not found in available packages')
48+
}
49+
50+
navigationDataInterface.set_active_package(target_package.uuid);
51+
} else {
52+
await navigationDataInterface.download_navigation_data(downloadUrl, true)
53+
}
4754
}, 30000)
4855

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

5259
expect(packageInfo).toStrictEqual({
5360
is_bundled: !process.env.NAVIGATION_DATA_SIGNED_URL,
54-
path: "/active",
55-
uuid: "12313",
61+
path: "\\work/navigation-data/active",
62+
uuid: "37735bb9-635b-37be-be1b-c5f9a89b7672",
5663
cycle: {
57-
cycle: "2401",
64+
cycle: "2410",
5865
revision: "1",
5966
name: "Navigraph Avionics",
6067
format: "dfdv2",
61-
validityPeriod: "2024-01-25/2024-02-21",
68+
validityPeriod: "2024-10-03/2024-10-30"
6269
},
6370
} satisfies PackageInfo)
6471
})
@@ -67,31 +74,39 @@ describe("DFDv2", () => {
6774
const info = await navigationDataInterface.get_database_info()
6875

6976
expect(info).toStrictEqual({
70-
airac_cycle: "2313",
71-
effective_from_to: ["28-12-2023", "25-01-2024"],
72-
previous_from_to: ["30-11-2023", "28-12-2023"],
77+
airac_cycle: "2410",
78+
effective_from_to: ["03-10-2024", "30-10-2024"],
79+
previous_from_to: ["depricated", "depricated"],
7380
} satisfies DatabaseInfo)
7481
})
7582

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

7986
expect(airport).toStrictEqual({
87+
airport_type: "C",
8088
area_code: "USA",
89+
city: "NEW YORK",
90+
continent: "NORTH AMERICA",
91+
country: "UNITED STATES",
92+
country_3letter: "USA",
8193
ident: "KJFK",
8294
icao_code: "K6",
8395
location: {
84-
lat: 40.63992778,
85-
long: -73.77869167,
96+
lat: 40.63992777777778,
97+
long: -73.77869166666666,
8698
},
8799
name: "KENNEDY INTL",
88100
ifr_capability: IfrCapability.Yes,
89101
longest_runway_surface_code: RunwaySurfaceCode.Hard,
102+
magnetic_variation: -13,
90103
elevation: 13,
91104
transition_altitude: 18000,
92105
transition_level: 18000,
93106
speed_limit: 250,
94107
speed_limit_altitude: 10000,
108+
state: "NEW YORK",
109+
state_2letter: "NY",
95110
iata_ident: "JFK",
96111
} satisfies Airport)
97112
})
@@ -103,11 +118,14 @@ describe("DFDv2", () => {
103118

104119
expect(waypoints[0]).toStrictEqual({
105120
area_code: "SPA",
121+
continent: "PACIFIC",
122+
country: "NEW ZEALAND",
123+
datum_code: "WGE",
106124
icao_code: "NZ",
107125
ident: "GLENN",
108126
location: {
109-
lat: -42.88116389,
110-
long: 172.83973889,
127+
lat: -42.88116388888889,
128+
long: 172.8397388888889,
111129
},
112130
name: "GLENN",
113131
} satisfies Waypoint)
@@ -162,7 +180,7 @@ describe("DFDv2", () => {
162180
it("Get airports in range", async () => {
163181
const airports = await navigationDataInterface.get_airports_in_range({ lat: 51.468, long: -0.4551 }, 640)
164182

165-
expect(airports.length).toBe(1686)
183+
expect(airports.length).toBe(1506)
166184
})
167185

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

0 commit comments

Comments
 (0)