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
16 changes: 6 additions & 10 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,22 @@ jobs:
working-directory: ./packages/contentstack-query-export
run: npm run test:unit

- name: Run tests for Contentstack Apps CLI
working-directory: ./packages/contentstack-apps-cli
run: npm run test:unit:report:json

- name: Run tests for Contentstack Content Type plugin
working-directory: ./packages/contentstack-content-type
run: npm run test:unit

- name: Run tests for Contentstack Regex Validate plugin
working-directory: ./packages/contentstack-cli-cm-regex-validate
run: npm run test:unit

- name: Run tests for Contentstack Tsgen plugin
working-directory: ./packages/contentstack-cli-tsgen
run: npm run test

- name: Run tests for Contentstack Migrate RTE
working-directory: ./packages/contentstack-migrate-rte
run: npm test
run: npm run test

- name: Run tests for Contentstack Bulk Operations
working-directory: ./packages/contentstack-bulk-operations
run: npm test
run: npm run test

- name: Run tests for Contentstack Apps CLI
working-directory: ./packages/contentstack-apps-cli
run: npm run test:unit:report
14 changes: 5 additions & 9 deletions packages/contentstack-apps-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"chalk": "^4.1.2",
"lodash": "^4.18.1",
"shelljs": "^0.10.0",
"tmp": "^0.2.5",
"tmp": "^0.2.7",
"winston": "^3.19.0"
},
"devDependencies": {
Expand All @@ -49,10 +49,9 @@
"eslint": "^8.57.1",
"eslint-config-oclif": "^6.0.157",
"eslint-config-oclif-typescript": "^3.1.14",
"fancy-test": "3.0.16",
"mocha": "^10.8.2",
"nyc": "^15.1.0",
"oclif": "^4.23.0",
"oclif": "^4.23.8",
"shx": "^0.4.0",
"ts-node": "^10.9.2",
"tslib": "^2.8.1",
Expand All @@ -62,9 +61,6 @@
"bin": "csdx",
"dirname": "apps-cli",
"commands": "./lib/commands",
"hooks": {
"init": "./lib/hooks/init/load-chalk.js"
},
"plugins": [],
"topicSeparator": ":",
"additionalHelpFlags": [
Expand All @@ -80,11 +76,11 @@
}
},
"scripts": {
"build": "npm run clean && shx rm -rf lib && tsc -b",
"build": "pnpm clean && tsc -b",
"lint": "eslint . --ext .ts --config .eslintrc",
"postpack": "shx rm -f oclif.manifest.json",
"posttest": "npm run lint",
"prepack": "npm run build && oclif manifest && oclif readme",
"posttest": "pnpm lint",
"prepack": "pnpm build && oclif manifest && oclif readme",
"test": "mocha --forbid-only \"test/**/*.test.ts\"",
"version": "oclif readme && git add README.md",
"clean": "rm -rf ./lib tsconfig.tsbuildinfo oclif.manifest.json",
Expand Down
11 changes: 10 additions & 1 deletion packages/contentstack-apps-cli/test/helpers/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,13 @@ process.env.NODE_ENV = 'development'

global.oclif = global.oclif || {}
global.oclif.columns = 80
global.commonMock = require(path.join(__dirname, '../unit/mock/common.mock.json'))
global.commonMock = require(path.join(__dirname, '../unit/mock/common.mock.json'))

const { configHandler } = require('@contentstack/cli-utilities')
if (!configHandler.get('region')) {
configHandler.set('region', {
name: 'NA',
cma: 'https://api.contentstack.io',
cda: 'https://cdn.contentstack.io',
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,15 @@ import { runCommand } from "@oclif/test";
import { cliux, configHandler } from "@contentstack/cli-utilities";
import messages, { $t } from "../../../../src/messages";
const mock = (global as any).commonMock;
import { getDeveloperHubUrl } from "../../../../src/util/inquirer";
import sinon from "sinon";
import { stubAuthentication } from "../../helpers/auth-stub-helper";
import Deploy from "../../../../src/commands/app/deploy";
import { BaseCommand } from "../../../../src/base-command";
import { join } from "path";

const region = configHandler.get("region");
// Commands run from lib/ (oclif.commands); stub the same classes/modules the running command uses
let BaseCommandToStub: typeof BaseCommand;
let LibDeploy: typeof Deploy;
let libCommonUtils: any;
let libInquirer: any;
try {
BaseCommandToStub = require(join(process.cwd(), "lib", "base-command")).BaseCommand;
} catch {
BaseCommandToStub = BaseCommand;
}
try {
LibDeploy = require(join(process.cwd(), "lib", "commands", "app", "deploy")).default;
} catch {
LibDeploy = Deploy;
}
try {
libCommonUtils = require(join(process.cwd(), "lib", "util", "common-utils"));
} catch {
libCommonUtils = require("../../../../src/util/common-utils");
}
try {
libInquirer = require(join(process.cwd(), "lib", "util", "inquirer"));
} catch {
libInquirer = require("../../../../src/util/inquirer");
}
const developerHubBaseUrl = getDeveloperHubUrl();
import * as libCommonUtils from "../../../../src/util/common-utils";
import * as libInquirer from "../../../../src/util/inquirer";

let region!: { cma: string; name: string; cda: string };
let developerHubBaseUrl!: string;

describe("app:deploy", () => {
let sandbox: sinon.SinonSandbox;
Expand All @@ -52,6 +27,8 @@ describe("app:deploy", () => {

// Stub authentication using shared helper
stubAuthentication(sandbox);
region = configHandler.get("region");
developerHubBaseUrl = libInquirer.getDeveloperHubUrl();

sandbox.stub(cliux, "loader").callsFake(() => {});
sandbox.stub(cliux, "inquire").callsFake((prompt: any) => {
Expand All @@ -64,7 +41,7 @@ describe("app:deploy", () => {
return Promise.resolve(cases[prompt.name]);
});

// Stub utilities used by the running command (lib/util); stub same module it requires
// Stub utilities used by the running command (src/util); same module instances oclif loads via tsPath
sandbox.stub(libCommonUtils, "getProjects").resolves([]);
sandbox.stub(libCommonUtils, "updateApp").resolves();
sandbox.stub(libCommonUtils, "disconnectApp").resolves();
Expand All @@ -76,14 +53,14 @@ describe("app:deploy", () => {
sandbox.stub(libInquirer, "getAppUrl").resolves("https://example.com");
sandbox.stub(libInquirer, "askProjectType").resolves("existing");
sandbox.stub(libInquirer, "askConfirmation").resolves(false);
sandbox.stub(libInquirer, "selectProject").resolves(null);
sandbox.stub(libInquirer, "selectProject").resolves(undefined);
sandbox.stub(libInquirer, "askProjectName").resolves("test-project");

// Stub Launch.run
sandbox.stub(require("@contentstack/cli-launch").Launch, "run").resolves();

// Stub getApolloClient on the class that actually runs (lib Deploy) so no real GraphQL runs
sandbox.stub(LibDeploy.prototype, "getApolloClient").resolves({
// Stub getApolloClient so no real GraphQL runs
sandbox.stub(Deploy.prototype, "getApolloClient").resolves({
query: () =>
Promise.resolve({
data: {
Expand All @@ -94,7 +71,7 @@ describe("app:deploy", () => {
}),
} as any);

// Stub SDK init so no real HTTP is made (cli-utilities exports use getters so we can't stub those).
// Stub SDK init so no real HTTP is made
const mockManagementSdk = {
organization: () => ({
fetchAll: () =>
Expand All @@ -116,15 +93,15 @@ describe("app:deploy", () => {
}),
}),
};
sandbox.stub(BaseCommandToStub.prototype, "initCmaSDK").callsFake(async function (this: any) {
sandbox.stub(BaseCommand.prototype, "initCmaSDK").callsFake(async function (this: any) {
this.managementSdk = mockManagementSdk;
this.managementAppSdk = mockManagementSdk;
});
sandbox.stub(BaseCommandToStub.prototype, "initMarketplaceSDK").callsFake(async function (this: any) {
sandbox.stub(BaseCommand.prototype, "initMarketplaceSDK").callsFake(async function (this: any) {
this.marketplaceAppSdk = mockMarketplaceSdk;
});

// Nock CMA and developer hub (SDK may use :443 or different param order)
// Nock CMA and developer hub
const cmaOrigin = region.cma.replace(/\/$/, "");
const orgReply = {
organizations: mock.organizations,
Expand Down Expand Up @@ -213,7 +190,7 @@ describe("app:deploy", () => {
sandbox.stub(process, "exit").callsFake(((code?: number) => {
throw new Error(`process.exit(${code})`);
}) as any);
sandbox.stub(LibDeploy.prototype, "getApolloClient").resolves({
sandbox.stub(Deploy.prototype, "getApolloClient").resolves({
query: () =>
Promise.resolve({
data: { projects: { edges: [] } },
Expand All @@ -240,11 +217,11 @@ describe("app:deploy", () => {
}),
}),
};
sandbox.stub(BaseCommandToStub.prototype, "initCmaSDK").callsFake(async function (this: any) {
sandbox.stub(BaseCommand.prototype, "initCmaSDK").callsFake(async function (this: any) {
this.managementSdk = mockMgmt;
this.managementAppSdk = mockMgmt;
});
sandbox.stub(BaseCommandToStub.prototype, "initMarketplaceSDK").callsFake(async function (this: any) {
sandbox.stub(BaseCommand.prototype, "initMarketplaceSDK").callsFake(async function (this: any) {
this.marketplaceAppSdk = mockMkt;
});
stubAuthentication(sandbox);
Expand Down Expand Up @@ -287,7 +264,7 @@ describe("app:deploy", () => {
sandbox.stub(process, "exit").callsFake(((code?: number) => {
throw new Error(`process.exit(${code})`);
}) as any);
sandbox.stub(LibDeploy.prototype, "getApolloClient").resolves({
sandbox.stub(Deploy.prototype, "getApolloClient").resolves({
query: () =>
Promise.resolve({
data: {
Expand Down Expand Up @@ -330,11 +307,11 @@ describe("app:deploy", () => {
}),
}),
};
sandbox.stub(BaseCommandToStub.prototype, "initCmaSDK").callsFake(async function (this: any) {
sandbox.stub(BaseCommand.prototype, "initCmaSDK").callsFake(async function (this: any) {
this.managementSdk = mockMgmt;
this.managementAppSdk = mockMgmt;
});
sandbox.stub(BaseCommandToStub.prototype, "initMarketplaceSDK").callsFake(async function (this: any) {
sandbox.stub(BaseCommand.prototype, "initMarketplaceSDK").callsFake(async function (this: any) {
this.marketplaceAppSdk = mockMkt;
});
stubAuthentication(sandbox);
Expand All @@ -355,14 +332,15 @@ describe("app:deploy", () => {
sandbox.stub(libInquirer, "askProjectType").resolves("new");
sandbox.stub(libInquirer, "askProjectName").resolves("new-project");
sandbox.stub(libInquirer, "askConfirmation").resolves(false);
sandbox.stub(libInquirer, "selectProject").resolves(null);
sandbox.stub(libInquirer, "selectProject").resolves(undefined);

sandbox.stub(libCommonUtils, "getProjects").resolves([
{
name: "new-project",
uid: "project-2",
url: "https://new-project.com",
environmentUid: "env-2",
developerHubAppUid: null,
},
]);
sandbox.stub(libCommonUtils, "setupConfig").returns({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,6 @@ import { BaseCommand } from "../../../../src/base-command";

const region = configHandler.get("region");

// Commands run from lib/ (oclif); stub the same class the running command uses
let BaseCommandToStub: typeof BaseCommand;
let LibUpdate: typeof Update;
try {
BaseCommandToStub = require(join(process.cwd(), "lib", "base-command")).BaseCommand;
} catch {
BaseCommandToStub = BaseCommand;
}
try {
LibUpdate = require(join(process.cwd(), "lib", "commands", "app", "update")).default;
} catch {
LibUpdate = Update;
}

/** Optional override: return a custom marketplace SDK mock for this test. */
let marketplaceMockOverride: any = null;

Expand Down Expand Up @@ -55,11 +41,11 @@ function stubUpdateInit(sandbox: sinon.SinonSandbox) {
}),
}),
};
sandbox.stub(BaseCommandToStub.prototype, "initCmaSDK").callsFake(async function (this: any) {
sandbox.stub(BaseCommand.prototype, "initCmaSDK").callsFake(async function (this: any) {
this.managementSdk = mockManagementSdk;
this.managementAppSdk = mockManagementSdk;
});
sandbox.stub(BaseCommandToStub.prototype, "initMarketplaceSDK").callsFake(async function (this: any) {
sandbox.stub(BaseCommand.prototype, "initMarketplaceSDK").callsFake(async function (this: any) {
this.marketplaceAppSdk = marketplaceMockOverride ?? defaultMarketplaceSdk;
});
}
Expand Down Expand Up @@ -95,7 +81,7 @@ describe("app:update", () => {
sandbox.stub(fs, "writeFileSync").callsFake(() => {});

sandbox
.stub(LibUpdate.prototype, "updateAppOnDeveloperHub")
.stub(Update.prototype, "updateAppOnDeveloperHub")
.callsFake(async function (this: any) {
this.log(this.messages.APP_UPDATE_SUCCESS, "info");
});
Expand Down Expand Up @@ -193,7 +179,7 @@ describe("app:update", () => {
describe("Update app with wrong app-uid API failure", () => {
beforeEach(() => {
sandbox
.stub(LibUpdate.prototype, "updateAppOnDeveloperHub")
.stub(Update.prototype, "updateAppOnDeveloperHub")
.callsFake(async function (this: any) {
this.log(this.messages.INVALID_APP_ID, "error");
throw { status: 400 };
Expand All @@ -214,7 +200,7 @@ describe("app:update", () => {
describe("Update app API failure", () => {
beforeEach(() => {
sandbox
.stub(LibUpdate.prototype, "updateAppOnDeveloperHub")
.stub(Update.prototype, "updateAppOnDeveloperHub")
.callsFake(async function (this: any) {
this.log(this.messages.APP_INVALID_ORG, "error");
throw { status: 403 };
Expand All @@ -234,7 +220,7 @@ describe("app:update", () => {
describe("Update app with duplicate app name (409 status)", () => {
beforeEach(() => {
sandbox
.stub(LibUpdate.prototype, "updateAppOnDeveloperHub")
.stub(Update.prototype, "updateAppOnDeveloperHub")
.callsFake(async function (this: any) {
this.log(
this.$t(this.messages.DUPLICATE_APP_NAME, {
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-audit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"dependencies": {
"@contentstack/cli-command": "~1.8.2",
"@contentstack/cli-utilities": "~1.18.3",
"@oclif/core": "^4.10.5",
"@oclif/core": "^4.11.4",
"chalk": "^4.1.2",
"fast-csv": "^4.3.6",
"fs-extra": "^11.3.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-bootstrap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@contentstack/cli-command": "~1.8.2",
"@contentstack/cli-config": "~1.20.3",
"@contentstack/cli-utilities": "~1.18.3",
"@oclif/core": "^4.10.5",
"@oclif/core": "^4.11.4",
"inquirer": "8.2.7",
"mkdirp": "^2.1.6",
"tar": "^7.5.11"
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-branches/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
"@contentstack/cli-command": "~1.8.2",
"@oclif/core": "^4.10.5",
"@oclif/core": "^4.11.4",
"@contentstack/cli-utilities": "~1.18.3",
"chalk": "^4.1.2",
"just-diff": "^6.0.2",
Expand Down
Loading
Loading