|
| 1 | +import { ux, cliux, configHandler } from "@contentstack/cli-utilities"; |
| 2 | +import { expect, test } from "@oclif/test"; |
| 3 | + |
| 4 | +import * as mock from "../../mock/common.mock.json"; |
| 5 | + |
| 6 | +import messages, { $t } from "../../../../src/messages"; |
| 7 | +import { getDeveloperHubUrl } from "../../../../src/util/inquirer"; |
| 8 | + |
| 9 | +const region: { cma: string; cda: string; name: string } = |
| 10 | + configHandler.get("region"); |
| 11 | +const developerHubBaseUrl = getDeveloperHubUrl(); |
| 12 | + |
| 13 | +describe("app:deploy", () => { |
| 14 | + describe("Deploy an with custom hosting", () => { |
| 15 | + test |
| 16 | + .stdout({ print: process.env.PRINT === "true" || false }) |
| 17 | + .stub(ux.action, "stop", () => {}) |
| 18 | + .stub(ux.action, "start", () => {}) |
| 19 | + .stub(cliux, "inquire", async (...args: any) => { |
| 20 | + const [prompt]: any = args; |
| 21 | + const cases = { |
| 22 | + App: mock.apps[1].name, |
| 23 | + Organization: mock.organizations[0].name, |
| 24 | + }; |
| 25 | + |
| 26 | + return (cases as Record<string, any>)[prompt.name]; |
| 27 | + }) |
| 28 | + .nock(region.cma, (api) => |
| 29 | + api |
| 30 | + .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") |
| 31 | + .reply(200, { organizations: mock.organizations }) |
| 32 | + ) |
| 33 | + .nock(`https://${developerHubBaseUrl}`, (api) => |
| 34 | + api |
| 35 | + .get("/manifests?limit=50&asc=name&include_count=true&skip=0") |
| 36 | + .reply(200, { |
| 37 | + data: mock.apps, |
| 38 | + }) |
| 39 | + ) |
| 40 | + .nock(`https://${developerHubBaseUrl}`, (api) => |
| 41 | + api |
| 42 | + .post(`/manifests/${mock.apps[1].uid}/deployments`, { |
| 43 | + hosting_type: "Custom hosting", |
| 44 | + }) |
| 45 | + .reply(200, { |
| 46 | + data: mock.apps, |
| 47 | + }) |
| 48 | + ) |
| 49 | + .command(["app:deploy"]) |
| 50 | + .do(({ stdout }) => { |
| 51 | + expect(stdout).to.contain( |
| 52 | + $t(messages.HOSTING_TYPE, { |
| 53 | + hosting_type: "Custom Hosting", |
| 54 | + deployment_url: "https://example.com" |
| 55 | + }) |
| 56 | + ); |
| 57 | + }) |
| 58 | + .it("should install an organization app"); |
| 59 | + }); |
| 60 | +}); |
0 commit comments