From 62ec9c1e6ea322f79487876d40cba5bdecef730c Mon Sep 17 00:00:00 2001 From: Vladimir Cucu <108150922+vladimir-cucu@users.noreply.github.com> Date: Wed, 19 Jun 2024 09:21:02 +0300 Subject: [PATCH] WD-12291 - fix: remove error notification when there are 0 models (#1781) --- src/juju/api.test.ts | 20 ++++++++++++++++++++ src/juju/api.ts | 4 ++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/juju/api.test.ts b/src/juju/api.test.ts index 1e5f8f2ec..a1ca30582 100644 --- a/src/juju/api.test.ts +++ b/src/juju/api.test.ts @@ -806,6 +806,26 @@ describe("Juju API", () => { ); }); + it("should fetch model statuses successfully when there are 0 models", async () => { + state.juju.models = {}; + const dispatch = vi.fn(); + const conn = { + facades: { + modelManager: { + modelInfo: vi.fn(), + }, + }, + } as unknown as Connection; + const response = fetchAllModelStatuses( + "wss://example.com/api", + [], + conn, + dispatch, + () => state, + ); + await expect(response).resolves.toBeUndefined(); + }); + it("updates controller cloud and region", async () => { const dispatch = vi.fn().mockReturnValue({ then: vi.fn().mockReturnValue({ catch: vi.fn() }), diff --git a/src/juju/api.ts b/src/juju/api.ts index e42ea9bc7..39b103764 100644 --- a/src/juju/api.ts +++ b/src/juju/api.ts @@ -406,9 +406,9 @@ export async function fetchAllModelStatuses( }); return new Promise((resolve, reject) => { queue.onDone(() => { - // If errors appear in more than 10% of models, the promise should be + // If errors exist and appear in more than 10% of models, the promise is // rejected and the error further handled in modelPollerMiddleware(). - modelErrorCount >= 0.1 * modelUUIDList.length + modelErrorCount && modelErrorCount >= 0.1 * modelUUIDList.length ? reject( new Error( modelErrorCount === modelUUIDList.length