Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/commands/studio/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class Module extends IModule {
public register(context: Context, configurator: Configurator): void {
const listCommand = configurator.command("list");
listCommand.command("packages")
.description("Command to list all packages")
.description("[Deprecated] Use 'config package list' instead. Command to list all packages")
.deprecationNotice("'list packages' is deprecated and will be removed in a future release. Use 'config package list' instead.")
.option("--json", "Return response as json type", "")
.option("--includeDependencies", "Include variables and dependencies", "")
.option("--packageKeys <packageKeys...>", "Lists only given package keys")
Expand All @@ -39,7 +40,8 @@ class Module extends IModule {
.action(this.pullAsset);

pullCommand.command("package")
.description("Command to pull a package")
.description("[Deprecated] Use 'config package export' instead. Command to pull a package")
.deprecationNotice("'pull package' is deprecated and will be removed in a future release. Use 'config package export' instead.")
.requiredOption("--key <key>", "Key of the package you want to pull")
.option("--store", "Pull package with store deployment metadata")
.option("--newKey <newKey>", "Define a new key for your package")
Expand All @@ -59,15 +61,17 @@ class Module extends IModule {
.action(this.pushAssets);

pushCommand.command("package")
.description("Command to push a package to Studio")
.description("[Deprecated] Use 'config package import' instead. Command to push a package to Studio")
.deprecationNotice("'push package' is deprecated and will be removed in a future release. Use 'config package import' instead.")
.option("--newKey <newKey>", "Define a new key for your package")
.option("--overwrite", "Overwrite package and its assets")
.requiredOption("-f, --file <file>", "The file you want to push")
.requiredOption("--spaceKey <spaceKey>", "The key of the destination space")
.action(this.pushPackage);

pushCommand.command("packages")
.description("Command to push packages to Studio")
.description("[Deprecated] Use 'config package import' (single package) instead. Command to push packages to Studio")
.deprecationNotice("'push packages' is deprecated and will be removed in a future release. Use 'config package import' (single package) instead.")
.requiredOption("--spaceKey <spaceKey>", "The key of the destination space")
.action(this.pushPackages);

Expand Down
76 changes: 76 additions & 0 deletions tests/commands/studio/module.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import Module = require("../../../src/commands/studio/module");
import { testContext } from "../../utls/test-context";
import { createMockConfigurator } from "../../utls/configurator-mock";

describe("Studio Module", () => {
describe("register", () => {
it("registers the studio command groups without throwing", () => {
const mockConfigurator = createMockConfigurator();

expect(() => new Module().register(testContext, mockConfigurator)).not.toThrow();

expect(mockConfigurator.command).toHaveBeenCalledWith("list");
expect(mockConfigurator.command).toHaveBeenCalledWith("pull");
expect(mockConfigurator.command).toHaveBeenCalledWith("push");
expect(mockConfigurator.command).toHaveBeenCalledWith("package");
expect(mockConfigurator.command).toHaveBeenCalledWith("packages");
expect(mockConfigurator.command).toHaveBeenCalledWith("widget");
});

it("wires an action handler for every leaf subcommand", () => {
const mockConfigurator = createMockConfigurator();

new Module().register(testContext, mockConfigurator);

// list (packages/spaces/assets) + pull (asset/package) + push (asset/assets/package/packages/widget)
const expectedLeafCommands = 10;
expect(mockConfigurator.action).toHaveBeenCalledTimes(expectedLeafCommands);
for (const call of mockConfigurator.action.mock.calls) {
expect(typeof call[0]).toBe("function");
}
});

it("deprecates the package push/pull/list commands, pointing at their config counterparts (never t2tc)", () => {
const mockConfigurator = createMockConfigurator();

new Module().register(testContext, mockConfigurator);

expect(mockConfigurator.deprecationNotice).toHaveBeenCalledTimes(4);
expect(mockConfigurator.deprecationNotice).toHaveBeenCalledWith(
"'pull package' is deprecated and will be removed in a future release. Use 'config package export' instead."
);
expect(mockConfigurator.deprecationNotice).toHaveBeenCalledWith(
"'push package' is deprecated and will be removed in a future release. Use 'config package import' instead."
);
expect(mockConfigurator.deprecationNotice).toHaveBeenCalledWith(
"'push packages' is deprecated and will be removed in a future release. Use 'config package import' (single package) instead."
);
expect(mockConfigurator.deprecationNotice).toHaveBeenCalledWith(
"'list packages' is deprecated and will be removed in a future release. Use 'config package list' instead."
);

for (const call of mockConfigurator.deprecationNotice.mock.calls) {
expect(call[0]).not.toMatch(/t2tc/);
}
});

it("prefixes the deprecated commands' descriptions with the recommended replacement", () => {
const mockConfigurator = createMockConfigurator();

new Module().register(testContext, mockConfigurator);

expect(mockConfigurator.description).toHaveBeenCalledWith(
"[Deprecated] Use 'config package export' instead. Command to pull a package"
);
expect(mockConfigurator.description).toHaveBeenCalledWith(
"[Deprecated] Use 'config package import' instead. Command to push a package to Studio"
);
expect(mockConfigurator.description).toHaveBeenCalledWith(
"[Deprecated] Use 'config package list' instead. Command to list all packages"
);
expect(mockConfigurator.description).toHaveBeenCalledWith(
"[Deprecated] Use 'config package import' (single package) instead. Command to push packages to Studio"
);
});
});
});
Loading