Skip to content

Commit

Permalink
unit tests for isInitialAppInstall utility
Browse files Browse the repository at this point in the history
  • Loading branch information
Craig O'Donnell committed Feb 27, 2024
1 parent dd489f4 commit 9fae344
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 2 deletions.
12 changes: 10 additions & 2 deletions web/src/utilities/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,12 +612,19 @@ export const Utilities = {
},

isInitialAppInstall(app) {
if (!app) {
return false;
}

if (app.downstream?.currentVersion) {
// a version has already been deployed
return false;
}

if (app.downstream?.pendingVersions?.length === 0) {
if (
!app.downstream?.pendingVersions ||
app.downstream.pendingVersions.length === 0
) {
// there's no version that's been deployed or is pending, so it's an initial install
return true;
}
Expand All @@ -626,7 +633,8 @@ export const Utilities = {
if (
firstPendingVersion.status === "pending_cluster_management" ||
firstPendingVersion.status === "pending_config" ||
firstPendingVersion.status === "pending_preflight"
firstPendingVersion.status === "pending_preflight" ||
firstPendingVersion.status === "pending_download"
) {
// the first pending version is still in the process of being installed
return true;
Expand Down
100 changes: 100 additions & 0 deletions web/src/utilities/utilities.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,104 @@ describe("Utilities", () => {
expect(Utilities.shouldShowClusterUpgradeModal(apps)).toBe(true);
});
});

describe("isInitialAppInstall", () => {
it("should return false if app is null", () => {
expect(Utilities.isInitialAppInstall(null)).toBe(false);
});

it("should return false if there is a current version", () => {
const app = {
downstream: {
currentVersion: {
status: "deployed",
},
},
};
expect(Utilities.isInitialAppInstall(app)).toBe(false);
});

it("should return true if there is no pending versions", () => {
let app = {
downstream: {
pendingVersions: [],
},
};
expect(Utilities.isInitialAppInstall(app)).toBe(true);

app = {
downstream: {},
};
expect(Utilities.isInitialAppInstall(app)).toBe(true);
});

it("should return true if first pending version has status `pending_cluster_management`, `pending_config`, `pending_preflight`, or `pending_download`", () => {
let app = {
downstream: {
pendingVersions: [
{
status: "pending_cluster_management",
},
],
},
};
expect(Utilities.isInitialAppInstall(app)).toBe(true);

app = {
downstream: {
pendingVersions: [
{
status: "pending_config",
},
],
},
};
expect(Utilities.isInitialAppInstall(app)).toBe(true);

app = {
downstream: {
pendingVersions: [
{
status: "pending_preflight",
},
],
},
};
expect(Utilities.isInitialAppInstall(app)).toBe(true);

app = {
downstream: {
pendingVersions: [
{
status: "pending_download",
},
],
},
};
});

it("should return false if first pending version does not have status `pending_cluster_management`, `pending_config`, `pending_preflight`, or `pending_download`", () => {
let app = {
downstream: {
pendingVersions: [
{
status: "pending",
},
],
},
};
expect(Utilities.isInitialAppInstall(app)).toBe(false);

app = {
downstream: {
pendingVersions: [
{
status: "unknown",
},
],
},
};
expect(Utilities.isInitialAppInstall(app)).toBe(false);
});
});
});

0 comments on commit 9fae344

Please sign in to comment.