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