Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dx | 683 fix breaking test cases #293

Merged
merged 10 commits into from
Aug 6, 2024
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ $ npm install -g @contentstack/apps-cli
$ csdx COMMAND
running command...
$ csdx (--version|-v)
@contentstack/apps-cli/1.3.1 darwin-arm64 node-v18.20.2
@contentstack/apps-cli/1.3.2 darwin-arm64 node-v18.20.2
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down Expand Up @@ -69,7 +69,7 @@ EXAMPLES
$ csdx app:update
```

_See code: [src/commands/app/index.ts](https://github.com/contentstack/apps-cli/blob/v1.3.1/src/commands/app/index.ts)_
_See code: [src/commands/app/index.ts](https://github.com/contentstack/apps-cli/blob/v1.3.2/src/commands/app/index.ts)_

## `csdx app:create`

Expand Down Expand Up @@ -109,7 +109,7 @@ EXAMPLES
$ csdx app:create --name App-4 --app-type organization --org <UID> --boilerplate <Ecommerce App Boilerplate>
```

_See code: [src/commands/app/create.ts](https://github.com/contentstack/apps-cli/blob/v1.3.1/src/commands/app/create.ts)_
_See code: [src/commands/app/create.ts](https://github.com/contentstack/apps-cli/blob/v1.3.2/src/commands/app/create.ts)_

## `csdx app:delete`

Expand All @@ -134,7 +134,7 @@ EXAMPLES
$ csdx app:delete --app-uid <value> --org <value> -d ./boilerplate
```

_See code: [src/commands/app/delete.ts](https://github.com/contentstack/apps-cli/blob/v1.3.1/src/commands/app/delete.ts)_
_See code: [src/commands/app/delete.ts](https://github.com/contentstack/apps-cli/blob/v1.3.2/src/commands/app/delete.ts)_

## `csdx app:deploy`

Expand Down Expand Up @@ -172,7 +172,7 @@ EXAMPLES
$ csdx app:deploy --org <UID> --app-uid <APP-UID-1> --hosting-type <Hosting with Launch> --launch-project <new> --config <config-path>
```

_See code: [src/commands/app/deploy.ts](https://github.com/contentstack/apps-cli/blob/v1.3.1/src/commands/app/deploy.ts)_
_See code: [src/commands/app/deploy.ts](https://github.com/contentstack/apps-cli/blob/v1.3.2/src/commands/app/deploy.ts)_

## `csdx app:get`

Expand Down Expand Up @@ -202,7 +202,7 @@ EXAMPLES
$ csdx app:get --org <value> --app-uid <value> --app-type organization
```

_See code: [src/commands/app/get.ts](https://github.com/contentstack/apps-cli/blob/v1.3.1/src/commands/app/get.ts)_
_See code: [src/commands/app/get.ts](https://github.com/contentstack/apps-cli/blob/v1.3.2/src/commands/app/get.ts)_

## `csdx app:install`

Expand All @@ -228,7 +228,7 @@ EXAMPLES
$ csdx app:install --org <UID> --app-uid <APP-UID-1> --stack-api-key <STACK-API-KEY-1>
```

_See code: [src/commands/app/install.ts](https://github.com/contentstack/apps-cli/blob/v1.3.1/src/commands/app/install.ts)_
_See code: [src/commands/app/install.ts](https://github.com/contentstack/apps-cli/blob/v1.3.2/src/commands/app/install.ts)_

## `csdx app:reinstall`

Expand All @@ -254,7 +254,7 @@ EXAMPLES
$ csdx app:reinstall --org <UID> --app-uid <APP-UID-1> --stack-api-key <STACK-API-KEY-1>
```

_See code: [src/commands/app/reinstall.ts](https://github.com/contentstack/apps-cli/blob/v1.3.1/src/commands/app/reinstall.ts)_
_See code: [src/commands/app/reinstall.ts](https://github.com/contentstack/apps-cli/blob/v1.3.2/src/commands/app/reinstall.ts)_

## `csdx app:uninstall`

Expand All @@ -281,7 +281,7 @@ EXAMPLES
$ csdx app:uninstall --org <UID> --app-uid <APP-UID-1> --installation-uid <INSTALLATION-UID-1>
```

_See code: [src/commands/app/uninstall.ts](https://github.com/contentstack/apps-cli/blob/v1.3.1/src/commands/app/uninstall.ts)_
_See code: [src/commands/app/uninstall.ts](https://github.com/contentstack/apps-cli/blob/v1.3.2/src/commands/app/uninstall.ts)_

## `csdx app:update`

Expand All @@ -304,5 +304,5 @@ EXAMPLES
$ csdx app:update --app-manifest ./boilerplate/manifest.json
```

_See code: [src/commands/app/update.ts](https://github.com/contentstack/apps-cli/blob/v1.3.1/src/commands/app/update.ts)_
_See code: [src/commands/app/update.ts](https://github.com/contentstack/apps-cli/blob/v1.3.2/src/commands/app/update.ts)_
<!-- commandsstop -->
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/apps-cli",
"version": "1.3.1",
"version": "1.3.2",
"description": "App ClI",
"author": "Contentstack CLI",
"homepage": "https://github.com/contentstack/contentstack-apps-cli",
Expand Down
9 changes: 9 additions & 0 deletions src/commands/app/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ export default class Create extends BaseCommand<typeof Create> {
) {
await this.boilerplateFlow();
} else {
if(this.sharedConfig.folderPath === undefined) {
const dataDir = this.flags["data-dir"] ?? process.cwd();
let targetPath = resolve(dataDir, this.sharedConfig.defaultAppName);
if (existsSync(targetPath)) {
this.log(this.messages.DIR_EXIST, "warn");
targetPath = await getDirName(targetPath);
}
this.sharedConfig.folderPath = targetPath;
}
this.manageManifestToggeling();
await this.registerTheAppOnDeveloperHub(false);
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/app/reinstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export default class Reinstall extends AppCLIBaseCommand {
this.displayStackUrl();
} catch (error: any) {
this.log(error?.errorMessage || error?.message || error, "error");
process.exit(1);
this.exit(1);
}
}

Expand Down
82 changes: 62 additions & 20 deletions test/unit/commands/app/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import config from "../../../../src/config";
import messages from "../../../../src/messages";
import * as mock from "../../mock/common.mock.json";
import manifestData from "../../../../src/config/manifest.json";
import orgManifestData from "../../../unit/config/org_manifest.json";
import { getDeveloperHubUrl } from "../../../../src/util/inquirer";

const { origin, pathname } = new URL(config.appBoilerplateGithubUrl);
Expand Down Expand Up @@ -64,7 +65,13 @@ describe("app:create", () => {
data: { ...manifestData, name: "test-app", version: 1 },
})
)
.command(["app:create", "--data-dir", process.cwd()])
.command([
"app:create",
"--name",
"test-app",
"--data-dir",
process.cwd(),
])
.do(({ stdout }) =>
expect(stdout).to.contain(messages.APP_CREATION_SUCCESS)
)
Expand Down Expand Up @@ -106,16 +113,23 @@ describe("app:create", () => {
.nock(`https://${developerHubBaseUrl}`, (api) =>
api
.post("/manifests", {
...manifestData,
...orgManifestData,
name: "test-app",
target_type: "organization",
})

.reply(200, {
data: { ...manifestData, name: "test-app", version: 1 },
data: {
...orgManifestData,
name: "test-app",
version: 1,
},
})
)
.command([
"app:create",
"--name",
"test-app",
"--data-dir",
process.cwd(),
"--app-type",
Expand All @@ -127,14 +141,14 @@ describe("app:create", () => {
.it("should create a organization level app");
});

describe("Creating a app without boilerplate", () => {
describe("Creating an app without boilerplate", () => {
test
.stdout({ print: process.env.PRINT === "true" || false })
.stub(ux.action, "stop", () => {})
.stub(ux.action, "start", () => {})
.stub(fs, "renameSync", () => new PassThrough())
.stub(fs, "writeFileSync", () => new PassThrough())
.stub(cliux, "inquire", async (...args: any) => {
.stub(cliux, "inquire", async (...args) => {
const [prompt]: any = args;
const cases = {
appName: "test-app",
Expand All @@ -151,12 +165,20 @@ describe("app:create", () => {
)
.nock(`https://${developerHubBaseUrl}`, (api) =>
api
.post("/manifests", { ...manifestData, name: "test-app" })
.post("/manifests", (body) => {
return body.name === "test-app" && body.target_type === "stack";
})
.reply(200, {
data: { ...manifestData, name: "test-app", version: 1 },
})
)
.command(["app:create", "--data-dir", process.cwd()])
.command([
"app:create",
"--name",
"test-app",
"--data-dir",
process.cwd(),
])
.do(({ stdout }) =>
expect(stdout).to.contain(messages.APP_CREATION_SUCCESS)
)
Expand Down Expand Up @@ -216,7 +238,6 @@ describe("app:create", () => {
cloneBoilerplate: false,
Organization: "test org 1",
};

return (cases as Record<string, any>)[prompt.name];
})
.nock(region.cma, (api) =>
Expand All @@ -225,14 +246,20 @@ describe("app:create", () => {
.reply(200, { organizations: mock.organizations })
)
.nock(`https://${developerHubBaseUrl}`, (api) =>
api.post("/manifests", { ...manifestData, name: "test-app" }).reply(400)
api
.post("/manifests", (body) => {
return body.name === "test-app" && body.target_type === "stack";
})
.reply(400, {
errorMessage: "App creation failed due to constraints.",
})
)
.command(["app:create", "--data-dir", process.cwd()])
.exit(1)
.do(({ stdout }) =>
expect(stdout).to.contain(messages.APP_CREATION_CONSTRAINT_FAILURE)
)
.it("App creation should fail!");
.do(({ stdout }) => {
expect(stdout).to.contain(messages.APP_CREATION_CONSTRAINT_FAILURE);
})
.it("App creation should fail and rollback");
});

describe("Pass external config using '--config' flag", () => {
Expand All @@ -256,7 +283,13 @@ describe("app:create", () => {
.reply(200, { organizations: mock.organizations })
)
.nock(`https://${developerHubBaseUrl}`, (api) =>
api.post("/manifests", { ...manifestData, name: "test-app" }).reply(400)
api
.post("/manifests", (body) => {
return body.name === "test-app" && body.target_type === "stack";
})
.reply(400, {
errorMessage: "App creation failed due to constraints.",
})
)
.command([
"app:create",
Expand All @@ -266,9 +299,10 @@ describe("app:create", () => {
resolve(process.cwd(), "test", "unit", "mock", "config.json"),
])
.exit(1)
.do(({ stdout }) =>
expect(stdout).to.contain(messages.APP_CREATION_CONSTRAINT_FAILURE)
)
.do(({ stdout }) => {
// Ensure the error message is what you expect
expect(stdout).to.contain(messages.APP_CREATION_CONSTRAINT_FAILURE);
})
.it("App creation should fail!");
});

Expand All @@ -286,7 +320,7 @@ describe("app:create", () => {
.stub(fs, "writeFileSync", () => new PassThrough())
.stub(fs, "createWriteStream", () => new PassThrough())
.stub(tmp, "fileSync", () => ({ name: zipPath }))
.stub(cliux, "inquire", async (...args: any) => {
.stub(cliux, "inquire", async (...args) => {
const [prompt]: any = args;
const cases = {
appName: "test-app",
Expand All @@ -306,12 +340,20 @@ describe("app:create", () => {
)
.nock(`https://${developerHubBaseUrl}`, (api) =>
api
.post("/manifests", { ...manifestData, name: "test-app" })
.post("/manifests", (body) => {
return body.name === "test-app" && body.target_type === "stack";
})
.reply(200, {
data: { ...manifestData, name: "test-app", version: 1 },
})
)
.command(["app:create", "--data-dir", process.cwd()])
.command([
"app:create",
"--name",
"test-app",
"--data-dir",
process.cwd(),
])
.exit(1)
.do(({ stdout }) =>
expect(stdout).to.contain("Dependency installation failed.!")
Expand Down
17 changes: 8 additions & 9 deletions test/unit/commands/app/reinstall.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ux, cliux, configHandler } from "@contentstack/cli-utilities";
import { expect, test } from "@oclif/test";
import * as mock from "../../mock/common.mock.json";
import messages, { $t } from "../../../../src/messages";
import { getDeveloperHubUrl } from "../../../../lib/util/inquirer";
import { getDeveloperHubUrl } from "../../../../src/util/inquirer";

const region: { cma: string; cda: string; name: string } =
configHandler.get("region");
Expand Down Expand Up @@ -235,6 +235,7 @@ describe("app:reinstall", () => {
const cases = {
App: mock.apps[1].name,
Organization: mock.organizations[0].name,
Stack: mock.stacks[0].name,
};

return (cases as Record<string, any>)[prompt.name];
Expand All @@ -245,25 +246,23 @@ describe("app:reinstall", () => {
.reply(200, { organizations: mock.organizations })
)
.nock(`https://${developerHubBaseUrl}`, (api) =>
api
.get("/manifests?limit=50&asc=name&include_count=true&skip=0")
.reply(200, {
data: mock.apps,
})
api.get(`/manifests/${mock.apps[1].uid}`).reply(200, {
data: mock.apps[1],
})
)
.nock(`https://${developerHubBaseUrl}`, (api) =>
api
.put(`/manifests/${mock.apps[1].uid}/install`, {
.put(`/manifests/${mock.apps[1].uid}/reinstall`, {
target_type: mock.apps[1].target_type,
target_uid: mock.stacks[0].uid,
target_uid: mock.organizations[0].uid,
})
.replyWithError({
status: 400,
message: "You are already using the latest version.",
error: "Bad Request",
})
)
.command(["app:install"])
.command(["app:reinstall", "--app-uid", mock.apps[1].uid])
.exit(1)
.do(({ stdout }) => {
expect(stdout).to.contain("You are already using the latest version.");
Expand Down
Loading
Loading