Skip to content

Commit

Permalink
Merge pull request #260 from contentstack/test/DX-543-deploy-command-…
Browse files Browse the repository at this point in the history
…unit-tests

dx-543 | deploy command unit tests
  • Loading branch information
harshithad0703 authored Jun 28, 2024
2 parents 43e2bb6 + 2feb7d0 commit 6afde49
Show file tree
Hide file tree
Showing 4 changed files with 386 additions and 22 deletions.
153 changes: 132 additions & 21 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
Expand Up @@ -32,7 +32,7 @@
"winston": "^3.11.0"
},
"devDependencies": {
"@oclif/test": "^4.0.3",
"@oclif/test": "^2.5.6",
"@types/adm-zip": "^0.5.5",
"@types/chai": "^4.3.11",
"@types/lodash": "^4.17.4",
Expand Down
145 changes: 145 additions & 0 deletions test/unit/commands/app/deploy.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
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 "../../../../src/util/inquirer";
// import { join } from "path";

const region: { cma: string; cda: string; name: string } =
configHandler.get("region");
const developerHubBaseUrl = getDeveloperHubUrl();

describe("app:deploy", () => {
describe("Deploy an app with custom hosting", () => {
test
.stdout({ print: process.env.PRINT === "true" || false })
.stub(ux.action, "stop", () => {})
.stub(ux.action, "start", () => {})
.stub(cliux, "inquire", async (...args: any) => {
const [prompt]: any = args;
const cases = {
App: mock.apps[1].name,
Organization: mock.organizations[0].name,
"hosting types": "Custom Hosting",
appUrl: "https://example.com",
};
return (cases as Record<string, any>)[prompt.name];
})
.nock(region.cma, (api) =>
api
.get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0")
.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.apps2,
})
)
.nock(`https://${developerHubBaseUrl}`, (api) =>
api.put(`/manifests/${mock.apps2[1].uid}`).reply(200, mock.deploy_custom_host)
)
.command(["app:deploy"])
.do(({ stdout }) => {
expect(stdout).to.contain(
$t(messages.APP_DEPLOYED, { app: mock.apps[1].name })
);
})
.it("should deploy the app with custom hosting");
});

describe("Deploy an app with custom hosting using flags in command", () => {
test
.stdout({ print: process.env.PRINT === "true" || false })
.stub(ux.action, "stop", () => {})
.stub(ux.action, "start", () => {})
.stub(cliux, "inquire", async (...args: any) => {
const [prompt]: any = args;
const cases = {
App: mock.apps[1].name,
Organization: mock.organizations[0].name,
"hosting types": "Custom Hosting",
appUrl: "https://example.com",
};
return (cases as Record<string, any>)[prompt.name];
})
.nock(region.cma, (api) =>
api
.get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0")
.reply(200, { organizations: mock.organizations })
)
.nock(`https://${developerHubBaseUrl}`, (api) =>
api
.get(`/manifests/${mock.apps2[1].uid}`)
.reply(200, {
data: mock.apps2[1],
})
)
.nock(`https://${developerHubBaseUrl}`, (api) =>
api.put(`/manifests/${mock.apps2[1].uid}`).reply(200, mock.deploy_custom_host)
)
.command([
"app:deploy",
"--org",
mock.organizations[0].uid,
"--app-uid",
mock.apps[1].uid,
"--hosting-type",
"Custom Hosting",
"--app-url",
"https://example.com",
])
.do(({ stdout }) => {
expect(stdout).to.contain(
$t(messages.APP_DEPLOYED, { app: mock.apps[1].name })
);
})
.it("should deploy the app with custom hosting using flags in command");
});

describe("Deploy an app with Hosting with Launch with existing project", () => {
test
.stdout({ print: process.env.PRINT === "true" || false })
.stub(ux.action, "stop", () => {})
.stub(ux.action, "start", () => {})
.stub(cliux, "inquire", async (...args: any) => {
const [prompt]: any = args;
const cases = {
App: mock.apps2[1].name,
Organization: mock.organizations[0].name,
"hosting types": "Hosting with Launch",
"provider": "launch",
"selected_launch_project":"existing",
"deployment_url": "https://example.com",
"environment_uid": "environment_uid",
"project_uid": "project_uid",
};
return (cases as Record<string, any>)[prompt.name];
})
.nock(region.cma, (api) =>
api
.get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0")
.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.apps2,
})
)
.nock(`https://${developerHubBaseUrl}`, (api) =>
api.put(`/manifests/${mock.apps2[1].uid}`).reply(200, mock.deploy_launch_host)
)
.command(["app:deploy"])
.do(({ stdout }) => {
expect(stdout).to.contain(
$t(messages.APP_DEPLOYED, { app: mock.apps2[1].name })
);
})
.it("should deploy the app with Hosting with Launch with existing project");
});
});
Loading

0 comments on commit 6afde49

Please sign in to comment.