|
| 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 | +// import { join } from "path"; |
| 9 | + |
| 10 | +const region: { cma: string; cda: string; name: string } = |
| 11 | + configHandler.get("region"); |
| 12 | +const developerHubBaseUrl = getDeveloperHubUrl(); |
| 13 | + |
| 14 | +describe("app:deploy", () => { |
| 15 | + describe("Deploy an app with custom hosting", () => { |
| 16 | + test |
| 17 | + .stdout({ print: process.env.PRINT === "true" || false }) |
| 18 | + .stub(ux.action, "stop", () => {}) |
| 19 | + .stub(ux.action, "start", () => {}) |
| 20 | + .stub(cliux, "inquire", async (...args: any) => { |
| 21 | + const [prompt]: any = args; |
| 22 | + const cases = { |
| 23 | + App: mock.apps[1].name, |
| 24 | + Organization: mock.organizations[0].name, |
| 25 | + "hosting types": "Custom Hosting", |
| 26 | + appUrl: "https://example.com", |
| 27 | + }; |
| 28 | + return (cases as Record<string, any>)[prompt.name]; |
| 29 | + }) |
| 30 | + .nock(region.cma, (api) => |
| 31 | + api |
| 32 | + .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") |
| 33 | + .reply(200, { organizations: mock.organizations }) |
| 34 | + ) |
| 35 | + .nock(`https://${developerHubBaseUrl}`, (api) => |
| 36 | + api |
| 37 | + .get("/manifests?limit=50&asc=name&include_count=true&skip=0") |
| 38 | + .reply(200, { |
| 39 | + data: mock.apps2, |
| 40 | + }) |
| 41 | + ) |
| 42 | + .nock(`https://${developerHubBaseUrl}`, (api) => |
| 43 | + api.put(`/manifests/${mock.apps2[1].uid}`).reply(200, mock.deploy_custom_host) |
| 44 | + ) |
| 45 | + .command(["app:deploy"]) |
| 46 | + .do(({ stdout }) => { |
| 47 | + expect(stdout).to.contain( |
| 48 | + $t(messages.APP_DEPLOYED, { app: mock.apps[1].name }) |
| 49 | + ); |
| 50 | + }) |
| 51 | + .it("should deploy the app with custom hosting"); |
| 52 | + }); |
| 53 | + |
| 54 | + describe("Deploy an app with custom hosting using flags in command", () => { |
| 55 | + test |
| 56 | + .stdout({ print: process.env.PRINT === "true" || false }) |
| 57 | + .stub(ux.action, "stop", () => {}) |
| 58 | + .stub(ux.action, "start", () => {}) |
| 59 | + .stub(cliux, "inquire", async (...args: any) => { |
| 60 | + const [prompt]: any = args; |
| 61 | + const cases = { |
| 62 | + App: mock.apps[1].name, |
| 63 | + Organization: mock.organizations[0].name, |
| 64 | + "hosting types": "Custom Hosting", |
| 65 | + appUrl: "https://example.com", |
| 66 | + }; |
| 67 | + return (cases as Record<string, any>)[prompt.name]; |
| 68 | + }) |
| 69 | + .nock(region.cma, (api) => |
| 70 | + api |
| 71 | + .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") |
| 72 | + .reply(200, { organizations: mock.organizations }) |
| 73 | + ) |
| 74 | + .nock(`https://${developerHubBaseUrl}`, (api) => |
| 75 | + api |
| 76 | + .get(`/manifests/${mock.apps2[1].uid}`) |
| 77 | + .reply(200, { |
| 78 | + data: mock.apps2[1], |
| 79 | + }) |
| 80 | + ) |
| 81 | + .nock(`https://${developerHubBaseUrl}`, (api) => |
| 82 | + api.put(`/manifests/${mock.apps2[1].uid}`).reply(200, mock.deploy_custom_host) |
| 83 | + ) |
| 84 | + .command([ |
| 85 | + "app:deploy", |
| 86 | + "--org", |
| 87 | + mock.organizations[0].uid, |
| 88 | + "--app-uid", |
| 89 | + mock.apps[1].uid, |
| 90 | + "--hosting-type", |
| 91 | + "Custom Hosting", |
| 92 | + "--app-url", |
| 93 | + "https://example.com", |
| 94 | + ]) |
| 95 | + .do(({ stdout }) => { |
| 96 | + expect(stdout).to.contain( |
| 97 | + $t(messages.APP_DEPLOYED, { app: mock.apps[1].name }) |
| 98 | + ); |
| 99 | + }) |
| 100 | + .it("should deploy the app with custom hosting using flags in command"); |
| 101 | + }); |
| 102 | + |
| 103 | + describe("Deploy an app with Hosting with Launch with existing project", () => { |
| 104 | + test |
| 105 | + .stdout({ print: process.env.PRINT === "true" || false }) |
| 106 | + .stub(ux.action, "stop", () => {}) |
| 107 | + .stub(ux.action, "start", () => {}) |
| 108 | + .stub(cliux, "inquire", async (...args: any) => { |
| 109 | + const [prompt]: any = args; |
| 110 | + const cases = { |
| 111 | + App: mock.apps2[1].name, |
| 112 | + Organization: mock.organizations[0].name, |
| 113 | + "hosting types": "Hosting with Launch", |
| 114 | + "provider": "launch", |
| 115 | + "selected_launch_project":"existing", |
| 116 | + "deployment_url": "https://example.com", |
| 117 | + "environment_uid": "environment_uid", |
| 118 | + "project_uid": "project_uid", |
| 119 | + }; |
| 120 | + return (cases as Record<string, any>)[prompt.name]; |
| 121 | + }) |
| 122 | + .nock(region.cma, (api) => |
| 123 | + api |
| 124 | + .get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0") |
| 125 | + .reply(200, { organizations: mock.organizations }) |
| 126 | + ) |
| 127 | + .nock(`https://${developerHubBaseUrl}`, (api) => |
| 128 | + api |
| 129 | + .get("/manifests?limit=50&asc=name&include_count=true&skip=0") |
| 130 | + .reply(200, { |
| 131 | + data: mock.apps2, |
| 132 | + }) |
| 133 | + ) |
| 134 | + .nock(`https://${developerHubBaseUrl}`, (api) => |
| 135 | + api.put(`/manifests/${mock.apps2[1].uid}`).reply(200, mock.deploy_launch_host) |
| 136 | + ) |
| 137 | + .command(["app:deploy"]) |
| 138 | + .do(({ stdout }) => { |
| 139 | + expect(stdout).to.contain( |
| 140 | + $t(messages.APP_DEPLOYED, { app: mock.apps2[1].name }) |
| 141 | + ); |
| 142 | + }) |
| 143 | + .it("should deploy the app with Hosting with Launch with existing project"); |
| 144 | + }); |
| 145 | +}); |
0 commit comments