-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete.test.ts
More file actions
114 lines (103 loc) · 3.78 KB
/
delete.test.ts
File metadata and controls
114 lines (103 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import { expect } from "chai";
import { runCommand } from "@oclif/test";
import { cliux, configHandler } from "@contentstack/cli-utilities";
import sinon from "sinon";
const mock = (global as any).commonMock;
import messages, { $t } from "../../../../src/messages";
import { getDeveloperHubUrl } from "../../../../src/util/inquirer";
import nock from "nock";
import { stubAuthentication } from "../../helpers/auth-stub-helper";
const region: { cma: string; name: string; cda: string } =
configHandler.get("region");
const developerHubBaseUrl = getDeveloperHubUrl();
describe("app:delete", () => {
let sandbox: sinon.SinonSandbox;
beforeEach(() => {
sandbox = sinon.createSandbox();
// Stub authentication using shared helper
stubAuthentication(sandbox);
nock(region.cma)
.get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0")
.reply(200, { organizations: mock.organizations });
});
afterEach(() => {
sandbox.restore();
nock.cleanAll();
});
describe("app:delete with --org and --app-uid flags", () => {
beforeEach(() => {
nock(`https://${developerHubBaseUrl}`)
.get("/manifests/app-uid-1/installations")
.reply(200, {
data: mock.installations,
});
});
it("should print an error saying that app is already installed", async () => {
const { stdout } = await runCommand([
"app:delete",
"--org",
mock.organizations[0].uid,
"--app-uid",
mock.apps[0].uid,
]);
expect(stdout).to.contain(messages.APP_IS_INSTALLED);
});
});
describe("app:delete using inquirer prompts", () => {
beforeEach(() => {
sandbox.stub(cliux, "inquire").callsFake(async (prompt: any) => {
const cases: Record<string, any> = {
Organization: "test org 1",
App: "App 1",
confirmation: true,
};
return Promise.resolve(cases[prompt.name]);
});
nock(`https://${developerHubBaseUrl}`)
.get("/manifests?limit=50&asc=name&include_count=true&skip=0")
.reply(200, { data: mock.apps });
nock(`https://${developerHubBaseUrl}`)
.get("/manifests/app-uid-1/installations")
.reply(200, { data: [] });
nock(`https://${developerHubBaseUrl}`)
.delete("/manifests/app-uid-1")
.reply(200, { data: {} });
});
it("should delete the app", async () => {
const { stdout } = await runCommand(["app:delete"]);
expect(stdout).to.contain(
$t(messages.APP_DELETED_SUCCESSFULLY, { app: mock.apps[0].name })
);
});
});
describe("app:delete error handling", () => {
beforeEach(() => {
sandbox.stub(cliux, "loader").callsFake(() => {});
sandbox.stub(cliux, "inquire").callsFake(async (prompt: any) => {
const cases: Record<string, any> = {
Organization: "test org 1",
App: "App 1",
confirmation: true,
};
return Promise.resolve(cases[prompt.name]);
});
nock(`https://${developerHubBaseUrl}`)
.get("/manifests?limit=50&asc=name&include_count=true&skip=0")
.reply(200, { data: mock.apps });
nock(`https://${developerHubBaseUrl}`)
.get("/manifests/app-uid-1/installations")
.replyWithError({
status: 409,
message: "(1) installations found for this app",
error: "Bad Request",
statusText: "Conflict",
});
});
it("should throw an error while deleting the app", async () => {
const { stdout, stderr } = await runCommand(["app:delete"]);
const output = stdout + stderr;
// Error is logged by fetchAppInstallations catch and/or delete command
expect(output).to.match(/Some error occurred while fetching app installations|Contact the support team for help/);
});
});
});