test: mock channel install boundaries

This commit is contained in:
Peter Steinberger
2026-04-17 06:51:33 +01:00
parent b1a3ad49a4
commit b945248650
2 changed files with 44 additions and 11 deletions

View File

@@ -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<typeof import("../channels/plugins/catalog.js")>(
"../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<typeof import("../channels/plugins/bundled.js")>(
"../channels/plugins/bundled.js",
);
return {
...actual,
getBundledChannelPlugin: vi.fn(() => undefined),
};
});
vi.mock("./channel-setup/plugin-install.js", async () => {
const actual = await vi.importActual<typeof import("./channel-setup/plugin-install.js")>(
"./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,
},
}),
},
}),
);

View File

@@ -29,6 +29,16 @@ vi.mock("../channels/plugins/catalog.js", async () => {
};
});
vi.mock("../channels/plugins/bundled.js", async () => {
const actual = await vi.importActual<typeof import("../channels/plugins/bundled.js")>(
"../channels/plugins/bundled.js",
);
return {
...actual,
getBundledChannelPlugin: vi.fn(() => undefined),
};
});
vi.mock("./channel-setup/plugin-install.js", async () => {
const actual = await vi.importActual<typeof import("./channel-setup/plugin-install.js")>(
"./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({