Skip to content

Commit 3f573b2

Browse files
feat: package management tests
1 parent 628e975 commit 3f573b2

File tree

2 files changed

+88
-2
lines changed

2 files changed

+88
-2
lines changed

src/js/interface/NavigraphNavigationDataInterface.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ export class NavigraphNavigationDataInterface {
109109
}
110110

111111
/**
112-
* Sets the active package in the database
112+
* Deletes a package from the work folder
113113
*
114-
* @param uuid - Sets active package to the uuid
114+
* @param uuid - UUID of the package to delete
115115
* @returns A promise that returns void
116116
*/
117117
public async delete_package(uuid: string): Promise<void> {

src/test/package_management.spec.ts

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import { NavigraphNavigationDataInterface, PackageInfo } from "../js"
2+
3+
const navigationDataInterface = new NavigraphNavigationDataInterface()
4+
5+
describe("Package Management", () => {
6+
// This will run once for each test file
7+
beforeAll(async () => {
8+
const waitForReady = (navDataInterface: NavigraphNavigationDataInterface): Promise<void> => {
9+
return new Promise((resolve, _reject) => {
10+
navDataInterface.onReady(() => resolve())
11+
})
12+
}
13+
14+
await waitForReady(navigationDataInterface)
15+
}, 30000)
16+
17+
it("List packages contains bundled items", async () => {
18+
const packages = await navigationDataInterface.list_available_packages();
19+
20+
const bundledV1 = packages.find((item) => item.cycle.cycle === '2101' && item.cycle.format === 'dfd');
21+
const bundledV2 = packages.find((item) => item.cycle.cycle === '2401' && item.cycle.format === 'dfdv2');
22+
23+
expect(bundledV1).toStrictEqual({
24+
cycle: {
25+
cycle: '2101',
26+
format: 'dfd',
27+
name: "Navigraph Avionics",
28+
revision: "1",
29+
validityPeriod: "2021-01-25/2021-02-20",
30+
},
31+
is_bundled: true,
32+
path: "\\work/navigation-data/269b26b0-ba1b-3859-a9c0-4484dc766233",
33+
uuid: "269b26b0-ba1b-3859-a9c0-4484dc766233"
34+
} satisfies PackageInfo)
35+
36+
expect(bundledV2).toStrictEqual({
37+
cycle: {
38+
cycle: '2401',
39+
format: 'dfdv2',
40+
name: "Navigraph Avionics",
41+
revision: "1",
42+
validityPeriod: "2024-01-25/2024-02-21",
43+
},
44+
is_bundled: true,
45+
path: "\\work/navigation-data/b8a9ecaa-a137-3059-b9f1-b7f2d5ddac37",
46+
uuid: "b8a9ecaa-a137-3059-b9f1-b7f2d5ddac37"
47+
} satisfies PackageInfo)
48+
})
49+
50+
it("Clean up Packages", async () => {
51+
const active = await navigationDataInterface.get_active_package();
52+
53+
await navigationDataInterface.clean_packages();
54+
55+
let packages = await navigationDataInterface.list_available_packages();
56+
57+
for (const item of packages) {
58+
expect(item.is_bundled == true || item.cycle.format == active?.cycle.format).toBe(true);
59+
}
60+
61+
await navigationDataInterface.clean_packages(0);
62+
63+
packages = await navigationDataInterface.list_available_packages();
64+
65+
for (const item of packages) {
66+
expect(item.is_bundled == true || item.uuid == active?.uuid).toBe(true);
67+
}
68+
}, 40000);
69+
70+
it("Delete packages", async () => {
71+
const intialPackages = await navigationDataInterface.list_available_packages();
72+
const activePackage = await navigationDataInterface.get_active_package();
73+
74+
for (const item of intialPackages) {
75+
await navigationDataInterface.delete_package(item.uuid);
76+
77+
const newPackages = await navigationDataInterface.list_available_packages();
78+
79+
for (const newPackage of newPackages) {
80+
expect(newPackage.uuid !== item.uuid || item.uuid === activePackage?.uuid).toBe(true)
81+
}
82+
}
83+
84+
expect(await navigationDataInterface.list_available_packages()).toHaveLength(activePackage ? 1 : 0);
85+
}, 30000);
86+
})

0 commit comments

Comments
 (0)