Skip to content

Commit

Permalink
feat: package management tests
Browse files Browse the repository at this point in the history
  • Loading branch information
professoralex13 committed Nov 14, 2024
1 parent 628e975 commit 3f573b2
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/js/interface/NavigraphNavigationDataInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ export class NavigraphNavigationDataInterface {
}

/**
* Sets the active package in the database
* Deletes a package from the work folder
*
* @param uuid - Sets active package to the uuid
* @param uuid - UUID of the package to delete
* @returns A promise that returns void
*/
public async delete_package(uuid: string): Promise<void> {
Expand Down
86 changes: 86 additions & 0 deletions src/test/package_management.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { NavigraphNavigationDataInterface, PackageInfo } from "../js"

const navigationDataInterface = new NavigraphNavigationDataInterface()

describe("Package Management", () => {
// This will run once for each test file
beforeAll(async () => {
const waitForReady = (navDataInterface: NavigraphNavigationDataInterface): Promise<void> => {
return new Promise((resolve, _reject) => {
navDataInterface.onReady(() => resolve())
})
}

await waitForReady(navigationDataInterface)
}, 30000)

it("List packages contains bundled items", async () => {
const packages = await navigationDataInterface.list_available_packages();

const bundledV1 = packages.find((item) => item.cycle.cycle === '2101' && item.cycle.format === 'dfd');
const bundledV2 = packages.find((item) => item.cycle.cycle === '2401' && item.cycle.format === 'dfdv2');

expect(bundledV1).toStrictEqual({
cycle: {
cycle: '2101',
format: 'dfd',
name: "Navigraph Avionics",
revision: "1",
validityPeriod: "2021-01-25/2021-02-20",
},
is_bundled: true,
path: "\\work/navigation-data/269b26b0-ba1b-3859-a9c0-4484dc766233",
uuid: "269b26b0-ba1b-3859-a9c0-4484dc766233"
} satisfies PackageInfo)

expect(bundledV2).toStrictEqual({
cycle: {
cycle: '2401',
format: 'dfdv2',
name: "Navigraph Avionics",
revision: "1",
validityPeriod: "2024-01-25/2024-02-21",
},
is_bundled: true,
path: "\\work/navigation-data/b8a9ecaa-a137-3059-b9f1-b7f2d5ddac37",
uuid: "b8a9ecaa-a137-3059-b9f1-b7f2d5ddac37"
} satisfies PackageInfo)
})

it("Clean up Packages", async () => {
const active = await navigationDataInterface.get_active_package();

await navigationDataInterface.clean_packages();

let packages = await navigationDataInterface.list_available_packages();

for (const item of packages) {
expect(item.is_bundled == true || item.cycle.format == active?.cycle.format).toBe(true);
}

await navigationDataInterface.clean_packages(0);

packages = await navigationDataInterface.list_available_packages();

for (const item of packages) {
expect(item.is_bundled == true || item.uuid == active?.uuid).toBe(true);
}
}, 40000);

it("Delete packages", async () => {
const intialPackages = await navigationDataInterface.list_available_packages();
const activePackage = await navigationDataInterface.get_active_package();

for (const item of intialPackages) {
await navigationDataInterface.delete_package(item.uuid);

const newPackages = await navigationDataInterface.list_available_packages();

for (const newPackage of newPackages) {
expect(newPackage.uuid !== item.uuid || item.uuid === activePackage?.uuid).toBe(true)
}
}

expect(await navigationDataInterface.list_available_packages()).toHaveLength(activePackage ? 1 : 0);
}, 30000);
})

0 comments on commit 3f573b2

Please sign in to comment.