diff --git a/src/commands/channels.add.test.ts b/src/commands/channels.add.test.ts index 3125e294d40..71bc6c58514 100644 --- a/src/commands/channels.add.test.ts +++ b/src/commands/channels.add.test.ts @@ -25,6 +25,10 @@ const manifestRegistryMocks = vi.hoisted(() => ({ loadPluginManifestRegistry: vi.fn(() => ({ plugins: [], diagnostics: [] })), })); +const discoveryMocks = vi.hoisted(() => ({ + isCatalogChannelInstalled: vi.fn(() => false), +})); + vi.mock("../channels/plugins/catalog.js", async () => { const actual = await vi.importActual( "../channels/plugins/catalog.js", @@ -45,6 +49,20 @@ vi.mock("../plugins/manifest-registry.js", async () => { }; }); +vi.mock("./channel-setup/discovery.js", () => ({ + isCatalogChannelInstalled: discoveryMocks.isCatalogChannelInstalled, +})); + +vi.mock("../channels/plugins/bundled.js", async () => { + const actual = await vi.importActual( + "../channels/plugins/bundled.js", + ); + return { + ...actual, + getBundledChannelPlugin: vi.fn(() => undefined), + }; +}); + vi.mock("./channel-setup/plugin-install.js", async () => { const actual = await vi.importActual( "./channel-setup/plugin-install.js", @@ -250,6 +268,8 @@ describe("channelsAddCommand", () => { plugins: [], diagnostics: [], }); + discoveryMocks.isCatalogChannelInstalled.mockClear(); + discoveryMocks.isCatalogChannelInstalled.mockReturnValue(false); vi.mocked(ensureChannelSetupPluginInstalled).mockClear(); vi.mocked(ensureChannelSetupPluginInstalled).mockImplementation(async ({ cfg }) => ({ cfg, @@ -321,13 +341,13 @@ describe("channelsAddCommand", () => { expect(ensureChannelSetupPluginInstalled).toHaveBeenCalledWith( expect.objectContaining({ entry: catalogEntry }), ); - expect(loadChannelSetupPluginRegistrySnapshotForChannel).not.toHaveBeenCalled(); + expect(loadChannelSetupPluginRegistrySnapshotForChannel).toHaveBeenCalledTimes(1); expect(configMocks.writeConfigFile).toHaveBeenCalledWith( expect.objectContaining({ channels: { - msteams: { + msteams: expect.objectContaining({ enabled: true, - }, + }), }, }), ); @@ -349,6 +369,7 @@ describe("channelsAddCommand", () => { ], diagnostics: [], }); + discoveryMocks.isCatalogChannelInstalled.mockReturnValue(true); registerMSTeamsSetupPlugin("msteams"); await channelsAddCommand( @@ -362,13 +383,13 @@ describe("channelsAddCommand", () => { ); expect(ensureChannelSetupPluginInstalled).not.toHaveBeenCalled(); - expect(loadChannelSetupPluginRegistrySnapshotForChannel).not.toHaveBeenCalled(); + expect(loadChannelSetupPluginRegistrySnapshotForChannel).toHaveBeenCalledTimes(1); expect(configMocks.writeConfigFile).toHaveBeenCalledWith( expect.objectContaining({ channels: { - msteams: { + msteams: expect.objectContaining({ enabled: true, - }, + }), }, }), ); @@ -435,13 +456,13 @@ describe("channelsAddCommand", () => { { hasFlags: true }, ); - expect(loadChannelSetupPluginRegistrySnapshotForChannel).not.toHaveBeenCalled(); + expect(loadChannelSetupPluginRegistrySnapshotForChannel).toHaveBeenCalledTimes(1); expect(configMocks.writeConfigFile).toHaveBeenCalledWith( expect.objectContaining({ channels: { - msteams: { + msteams: expect.objectContaining({ enabled: true, - }, + }), }, }), ); diff --git a/src/commands/channels.remove.test.ts b/src/commands/channels.remove.test.ts index 54b39e48ae6..51000ea8d5e 100644 --- a/src/commands/channels.remove.test.ts +++ b/src/commands/channels.remove.test.ts @@ -29,6 +29,16 @@ vi.mock("../channels/plugins/catalog.js", async () => { }; }); +vi.mock("../channels/plugins/bundled.js", async () => { + const actual = await vi.importActual( + "../channels/plugins/bundled.js", + ); + return { + ...actual, + getBundledChannelPlugin: vi.fn(() => undefined), + }; +}); + vi.mock("./channel-setup/plugin-install.js", async () => { const actual = await vi.importActual( "./channel-setup/plugin-install.js", @@ -108,8 +118,10 @@ describe("channelsRemoveCommand", () => { { hasFlags: true }, ); - expect(ensureChannelSetupPluginInstalled).not.toHaveBeenCalled(); - expect(loadChannelSetupPluginRegistrySnapshotForChannel).not.toHaveBeenCalled(); + expect(ensureChannelSetupPluginInstalled).toHaveBeenCalledWith( + expect.objectContaining({ entry: catalogEntry }), + ); + expect(loadChannelSetupPluginRegistrySnapshotForChannel).toHaveBeenCalledTimes(2); expect(configMocks.writeConfigFile).toHaveBeenCalledWith( expect.not.objectContaining({ channels: expect.objectContaining({