Skip to content

Commit

Permalink
Re-instate remove getInstalledPkgStatus, just without subscriptions.
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Nelson <[email protected]>
  • Loading branch information
absoludity committed Apr 18, 2023
1 parent 6618051 commit e41c5a7
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
34 changes: 34 additions & 0 deletions dashboard/src/actions/installedpackages.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
GetInstalledPackageSummariesResponse,
InstalledPackageDetail,
InstalledPackageReference,
InstalledPackageStatus,
InstalledPackageStatus_StatusReason,
InstalledPackageSummary,
ReconciliationOptions,
VersionReference,
Expand Down Expand Up @@ -396,3 +398,35 @@ describe("rollbackInstalledPackage", () => {
expect(store.getActions()).toEqual(expectedActions);
});
});

describe("getInstalledPkgStatus", () => {
it("fetches the package and dispatches the status", async () => {
const installedPkgRef = {
context: { cluster: "default-c", namespace: "default-ns" },
identifier: "my-release",
plugin: { name: "bad-plugin", version: "0.0.1" } as Plugin,
} as InstalledPackageReference;
const status = {
reason: InstalledPackageStatus_StatusReason.INSTALLED,
} as InstalledPackageStatus;
const installedPackageDetail = { status } as InstalledPackageDetail;
InstalledPackage.GetInstalledPackageDetail = jest.fn().mockReturnValue({
installedPackageDetail,
});

const expectedActions = [
{ type: getType(actions.installedpackages.requestInstalledPackageStatus) },
{
type: getType(actions.installedpackages.receiveInstalledPackageStatus),
payload: status,
},
];

const getInstalledPkgStatusAction =
actions.installedpackages.getInstalledPkgStatus(installedPkgRef);
await store.dispatch(getInstalledPkgStatusAction);

expect(InstalledPackage.GetInstalledPackageDetail).toHaveBeenCalledWith(installedPkgRef);
expect(store.getActions()).toEqual(expectedActions);
});
});
22 changes: 22 additions & 0 deletions dashboard/src/actions/installedpackages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,28 @@ export function getInstalledPackage(
};
}

export function getInstalledPkgStatus(
installedPackageRef?: InstalledPackageReference,
): ThunkAction<Promise<void>, IStoreState, null, InstalledPackagesAction> {
return async dispatch => {
dispatch(requestInstalledPackageStatus());
try {
// Get the details of an installed package for the status.
const { installedPackageDetail } = await InstalledPackage.GetInstalledPackageDetail(
installedPackageRef,
);
dispatch(receiveInstalledPackageStatus(installedPackageDetail!.status!));
} catch (e: any) {
dispatch(
handleErrorAction(
e,
errorInstalledPackage(new FetchError("Unable to refresh installed package", [e])),
),
);
}
};
}

export function deleteInstalledPackage(
installedPackageRef: InstalledPackageReference,
): ThunkAction<Promise<boolean>, IStoreState, null, InstalledPackagesAction> {
Expand Down

0 comments on commit e41c5a7

Please sign in to comment.