Skip to content

Commit

Permalink
Handle no version response (#1470)
Browse files Browse the repository at this point in the history
* Handle no versions returned from the API.
  • Loading branch information
huwshimi authored May 8, 2023
1 parent 168a2f9 commit 481f628
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 13 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "juju-dashboard",
"version": "0.11.1",
"version": "0.11.2",
"description": "A dashboard for Juju and JAAS (Juju as a service)",
"bugs": {
"url": "https://github.com/canonical-web-and-design/jaas-dashboard/issues"
Expand Down Expand Up @@ -48,7 +48,7 @@
]
},
"dependencies": {
"@canonical/jujulib": "3.2.0",
"@canonical/jujulib": "3.2.1",
"@canonical/macaroon-bakery": "1.3.2",
"@canonical/react-components": "0.41.0",
"@reduxjs/toolkit": "1.9.3",
Expand Down
22 changes: 22 additions & 0 deletions src/components/PrimaryNav/PrimaryNav.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,26 @@ describe("Primary Nav", () => {
);
expect(notification).not.toBeInTheDocument();
});

it("handles no update response", async () => {
jest
.spyOn(versionsAPI, "dashboardUpdateAvailable")
.mockRejectedValue(new Error());
const store = mockStore(
rootStateFactory
.withGeneralConfig()
.build({ general: { appVersion: "9.9.0" } })
);
render(
<Provider store={store}>
<MemoryRouter initialEntries={["/"]}>
<PrimaryNav />
</MemoryRouter>
</Provider>
);
const notification = await waitFor(() =>
screen.queryByTestId("dashboard-update")
);
expect(notification).not.toBeInTheDocument();
});
});
10 changes: 7 additions & 3 deletions src/components/PrimaryNav/PrimaryNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,13 @@ const PrimaryNav = () => {

useEffect(() => {
if (appVersion && !versionRequested.current) {
dashboardUpdateAvailable(appVersion || "").then((e) => {
setUpdateAvailable(e);
});
dashboardUpdateAvailable(appVersion || "")
?.then((updateAvailable) => {
setUpdateAvailable(updateAvailable ?? false);
})
.catch(() => {
setUpdateAvailable(false);
});
versionRequested.current = true;
}
}, [appVersion]);
Expand Down
11 changes: 8 additions & 3 deletions src/juju/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,14 @@ export async function fetchControllerList(
// check for updates
await Promise.all(
controllers.map(async (controller) => {
controller.updateAvailable = await jujuUpdateAvailable(
controller.version || ""
);
let updateAvailable = false;
try {
updateAvailable =
(await jujuUpdateAvailable(controller.version || "")) ?? false;
} catch (error) {
updateAvailable = false;
}
controller.updateAvailable = updateAvailable;
})
);
dispatch(
Expand Down
2 changes: 1 addition & 1 deletion src/store/juju/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type Controller = {
Public?: boolean;
uuid: string;
version?: string;
updateAvailable?: boolean;
updateAvailable?: boolean | null;
};

export type AdditionalController = {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1084,10 +1084,10 @@
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==

"@canonical/[email protected].0":
version "3.2.0"
resolved "https://registry.yarnpkg.com/@canonical/jujulib/-/jujulib-3.2.0.tgz#7e0d29060bb100a265fc54b077200a7f894e2c1a"
integrity sha512-YRrio9rxoaUQ9c3/RlQw3Sde8FtmqpClYsGtnhtftAnJ6BV1WKfbz6VLSCU5EO5srDZNVx2vxgBUzgk382kL1w==
"@canonical/[email protected].1":
version "3.2.1"
resolved "https://registry.yarnpkg.com/@canonical/jujulib/-/jujulib-3.2.1.tgz#64d7792fcb5f777539421e900c59471cb34de6e5"
integrity sha512-oDnWFCHQ03pUBBI/mk+Zd2nagg4SXCmWbLAOr7odkUSjhmwkbsLVzhekcISZNXf9Zz5aDeRGI7NiGXnrSDnyfA==
dependencies:
"@canonical/macaroon-bakery" "1.3.2"
btoa "1.2.1"
Expand Down

0 comments on commit 481f628

Please sign in to comment.