@credibledata/cred-cli 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/build.yml +23 -0
- package/.mocharc.json +10 -0
- package/.prettierignore +2 -0
- package/.prettierrc +4 -0
- package/README-DEV.md +40 -0
- package/README.md +11 -0
- package/bun.lock +1158 -0
- package/dist/client/api.js +7715 -0
- package/dist/client/api.js.map +1 -0
- package/dist/client/base.js +69 -0
- package/dist/client/base.js.map +1 -0
- package/dist/client/common.js +162 -0
- package/dist/client/common.js.map +1 -0
- package/dist/client/configuration.js +44 -0
- package/dist/client/configuration.js.map +1 -0
- package/dist/client/index.js +32 -0
- package/dist/client/index.js.map +1 -0
- package/dist/clientconfiguration.js +205 -0
- package/dist/clientconfiguration.js.map +1 -0
- package/dist/clientconfiguration.spec.js +381 -0
- package/dist/clientconfiguration.spec.js.map +1 -0
- package/dist/commands/add.js +66 -0
- package/dist/commands/add.js.map +1 -0
- package/dist/commands/connection/createconnections.js +89 -0
- package/dist/commands/connection/createconnections.js.map +1 -0
- package/dist/commands/connection/createconnections.spec.js +219 -0
- package/dist/commands/connection/createconnections.spec.js.map +1 -0
- package/dist/commands/connection/deleteconnection.js +52 -0
- package/dist/commands/connection/deleteconnection.js.map +1 -0
- package/dist/commands/connection/deleteconnection.spec.js +130 -0
- package/dist/commands/connection/deleteconnection.spec.js.map +1 -0
- package/dist/commands/connection/listconnections.js +50 -0
- package/dist/commands/connection/listconnections.js.map +1 -0
- package/dist/commands/connection/listconnections.spec.js +117 -0
- package/dist/commands/connection/listconnections.spec.js.map +1 -0
- package/dist/commands/get.js +28 -0
- package/dist/commands/get.js.map +1 -0
- package/dist/commands/group/addmember.js +75 -0
- package/dist/commands/group/addmember.js.map +1 -0
- package/dist/commands/group/addmember.spec.js +148 -0
- package/dist/commands/group/addmember.spec.js.map +1 -0
- package/dist/commands/group/creategroup.js +55 -0
- package/dist/commands/group/creategroup.js.map +1 -0
- package/dist/commands/group/creategroup.spec.js +122 -0
- package/dist/commands/group/creategroup.spec.js.map +1 -0
- package/dist/commands/group/deletegroup.js +48 -0
- package/dist/commands/group/deletegroup.js.map +1 -0
- package/dist/commands/group/deletegroup.spec.js +104 -0
- package/dist/commands/group/deletegroup.spec.js.map +1 -0
- package/dist/commands/group/getgroup.js +50 -0
- package/dist/commands/group/getgroup.js.map +1 -0
- package/dist/commands/group/getgroup.spec.js +111 -0
- package/dist/commands/group/getgroup.spec.js.map +1 -0
- package/dist/commands/group/listgroups.js +56 -0
- package/dist/commands/group/listgroups.js.map +1 -0
- package/dist/commands/group/listgroups.spec.js +118 -0
- package/dist/commands/group/listgroups.spec.js.map +1 -0
- package/dist/commands/group/removemember.js +69 -0
- package/dist/commands/group/removemember.js.map +1 -0
- package/dist/commands/group/removemember.spec.js +138 -0
- package/dist/commands/group/removemember.spec.js.map +1 -0
- package/dist/commands/groupaccesstoken/createToken.js +53 -0
- package/dist/commands/groupaccesstoken/createToken.js.map +1 -0
- package/dist/commands/groupaccesstoken/createToken.spec.js +127 -0
- package/dist/commands/groupaccesstoken/createToken.spec.js.map +1 -0
- package/dist/commands/groupaccesstoken/deleteToken.js +24 -0
- package/dist/commands/groupaccesstoken/deleteToken.js.map +1 -0
- package/dist/commands/groupaccesstoken/deleteToken.spec.js +103 -0
- package/dist/commands/groupaccesstoken/deleteToken.spec.js.map +1 -0
- package/dist/commands/groupaccesstoken/groupContainer.js +71 -0
- package/dist/commands/groupaccesstoken/groupContainer.js.map +1 -0
- package/dist/commands/groupaccesstoken/listTokens.js +25 -0
- package/dist/commands/groupaccesstoken/listTokens.js.map +1 -0
- package/dist/commands/groupaccesstoken/listTokens.spec.js +115 -0
- package/dist/commands/groupaccesstoken/listTokens.spec.js.map +1 -0
- package/dist/commands/list.js +75 -0
- package/dist/commands/list.js.map +1 -0
- package/dist/commands/misc/login.js +290 -0
- package/dist/commands/misc/login.js.map +1 -0
- package/dist/commands/misc/login.spec.js +243 -0
- package/dist/commands/misc/login.spec.js.map +1 -0
- package/dist/commands/misc/logout.js +11 -0
- package/dist/commands/misc/logout.js.map +1 -0
- package/dist/commands/misc/logout.spec.js +30 -0
- package/dist/commands/misc/logout.spec.js.map +1 -0
- package/dist/commands/misc/loopbackOAuth.js +110 -0
- package/dist/commands/misc/loopbackOAuth.js.map +1 -0
- package/dist/commands/misc/set-access-token.js +27 -0
- package/dist/commands/misc/set-access-token.js.map +1 -0
- package/dist/commands/misc/set-access-token.spec.js +65 -0
- package/dist/commands/misc/set-access-token.spec.js.map +1 -0
- package/dist/commands/package/deletepackage.js +54 -0
- package/dist/commands/package/deletepackage.js.map +1 -0
- package/dist/commands/package/deletepackage.spec.js +136 -0
- package/dist/commands/package/deletepackage.spec.js.map +1 -0
- package/dist/commands/package/listpackages.js +57 -0
- package/dist/commands/package/listpackages.js.map +1 -0
- package/dist/commands/package/listpackages.spec.js +129 -0
- package/dist/commands/package/listpackages.spec.js.map +1 -0
- package/dist/commands/package/publish.js +157 -0
- package/dist/commands/package/publish.js.map +1 -0
- package/dist/commands/package/publish.spec.js +511 -0
- package/dist/commands/package/publish.spec.js.map +1 -0
- package/dist/commands/package/updatepackage.js +75 -0
- package/dist/commands/package/updatepackage.js.map +1 -0
- package/dist/commands/package/updatepackage.spec.js +189 -0
- package/dist/commands/package/updatepackage.spec.js.map +1 -0
- package/dist/commands/project/createproject.js +75 -0
- package/dist/commands/project/createproject.js.map +1 -0
- package/dist/commands/project/createproject.spec.js +154 -0
- package/dist/commands/project/createproject.spec.js.map +1 -0
- package/dist/commands/project/deleteproject.js +49 -0
- package/dist/commands/project/deleteproject.js.map +1 -0
- package/dist/commands/project/deleteproject.spec.js +106 -0
- package/dist/commands/project/deleteproject.spec.js.map +1 -0
- package/dist/commands/project/getproject.js +44 -0
- package/dist/commands/project/getproject.js.map +1 -0
- package/dist/commands/project/getproject.spec.js +99 -0
- package/dist/commands/project/getproject.spec.js.map +1 -0
- package/dist/commands/project/listprojects.js +52 -0
- package/dist/commands/project/listprojects.js.map +1 -0
- package/dist/commands/project/listprojects.spec.js +111 -0
- package/dist/commands/project/listprojects.spec.js.map +1 -0
- package/dist/commands/project/setproject.js +26 -0
- package/dist/commands/project/setproject.js.map +1 -0
- package/dist/commands/project/setproject.spec.js +58 -0
- package/dist/commands/project/setproject.spec.js.map +1 -0
- package/dist/commands/project/updateproject.js +68 -0
- package/dist/commands/project/updateproject.js.map +1 -0
- package/dist/commands/project/updateproject.spec.js +129 -0
- package/dist/commands/project/updateproject.spec.js.map +1 -0
- package/dist/commands/rm.js +68 -0
- package/dist/commands/rm.js.map +1 -0
- package/dist/commands/set.js +17 -0
- package/dist/commands/set.js.map +1 -0
- package/dist/commands/update.js +42 -0
- package/dist/commands/update.js.map +1 -0
- package/dist/commands/version/archive-unarchive-version.js +79 -0
- package/dist/commands/version/archive-unarchive-version.js.map +1 -0
- package/dist/commands/version/archive-unarchive-version.spec.js +244 -0
- package/dist/commands/version/archive-unarchive-version.spec.js.map +1 -0
- package/dist/commands/version/listversions.js +46 -0
- package/dist/commands/version/listversions.js.map +1 -0
- package/dist/commands/version/listversions.spec.js +121 -0
- package/dist/commands/version/listversions.spec.js.map +1 -0
- package/dist/common/UserGroupId.js +112 -0
- package/dist/common/UserGroupId.js.map +1 -0
- package/dist/common/UserGroupId.spec.js +92 -0
- package/dist/common/UserGroupId.spec.js.map +1 -0
- package/dist/constants.js +90 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.js +159 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.js +77 -0
- package/dist/logger.js.map +1 -0
- package/dist/logger.spec.js +125 -0
- package/dist/logger.spec.js.map +1 -0
- package/dist/polyfills/file.polyfill.js +6 -0
- package/dist/polyfills/file.polyfill.js.map +1 -0
- package/dist/utils.js +110 -0
- package/dist/utils.js.map +1 -0
- package/dist/utils.spec.js +158 -0
- package/dist/utils.spec.js.map +1 -0
- package/dist/validator.js +53 -0
- package/dist/validator.js.map +1 -0
- package/dist/validator.spec.js +41 -0
- package/dist/validator.spec.js.map +1 -0
- package/docker/Dockerfile.ci +18 -0
- package/docker-compose.yml +18 -0
- package/eslint.config.mjs +45 -0
- package/generate-client.sh +27 -0
- package/mocha.setup.ts +4 -0
- package/openapitools.json +7 -0
- package/package.json +75 -0
- package/src/client/.openapi-generator/FILES +9 -0
- package/src/client/.openapi-generator/VERSION +1 -0
- package/src/client/.openapi-generator-ignore +23 -0
- package/src/client/api.ts +9729 -0
- package/src/client/base.ts +86 -0
- package/src/client/common.ts +150 -0
- package/src/client/configuration.ts +110 -0
- package/src/client/git_push.sh +57 -0
- package/src/client/index.ts +18 -0
- package/src/clientconfiguration.spec.ts +490 -0
- package/src/clientconfiguration.ts +263 -0
- package/src/commands/add.ts +125 -0
- package/src/commands/connection/createconnections.spec.ts +403 -0
- package/src/commands/connection/createconnections.ts +109 -0
- package/src/commands/connection/deleteconnection.spec.ts +189 -0
- package/src/commands/connection/deleteconnection.ts +57 -0
- package/src/commands/connection/listconnections.spec.ts +132 -0
- package/src/commands/connection/listconnections.ts +58 -0
- package/src/commands/get.ts +31 -0
- package/src/commands/group/addmember.spec.ts +257 -0
- package/src/commands/group/addmember.ts +85 -0
- package/src/commands/group/creategroup.spec.ts +146 -0
- package/src/commands/group/creategroup.ts +54 -0
- package/src/commands/group/deletegroup.spec.ts +120 -0
- package/src/commands/group/deletegroup.ts +45 -0
- package/src/commands/group/getgroup.spec.ts +129 -0
- package/src/commands/group/getgroup.ts +47 -0
- package/src/commands/group/listgroups.spec.ts +137 -0
- package/src/commands/group/listgroups.ts +45 -0
- package/src/commands/group/removemember.spec.ts +224 -0
- package/src/commands/group/removemember.ts +75 -0
- package/src/commands/groupaccesstoken/createToken.spec.ts +211 -0
- package/src/commands/groupaccesstoken/createToken.ts +72 -0
- package/src/commands/groupaccesstoken/deleteToken.spec.ts +147 -0
- package/src/commands/groupaccesstoken/deleteToken.ts +29 -0
- package/src/commands/groupaccesstoken/groupContainer.ts +83 -0
- package/src/commands/groupaccesstoken/listTokens.spec.ts +147 -0
- package/src/commands/groupaccesstoken/listTokens.ts +29 -0
- package/src/commands/list.ts +131 -0
- package/src/commands/misc/login.spec.ts +213 -0
- package/src/commands/misc/login.ts +325 -0
- package/src/commands/misc/logout.spec.ts +32 -0
- package/src/commands/misc/logout.ts +9 -0
- package/src/commands/misc/loopbackOAuth.ts +127 -0
- package/src/commands/misc/set-access-token.spec.ts +95 -0
- package/src/commands/misc/set-access-token.ts +32 -0
- package/src/commands/package/deletepackage.spec.ts +164 -0
- package/src/commands/package/deletepackage.ts +58 -0
- package/src/commands/package/listpackages.spec.ts +147 -0
- package/src/commands/package/listpackages.ts +67 -0
- package/src/commands/package/publish.spec.ts +597 -0
- package/src/commands/package/publish.ts +211 -0
- package/src/commands/package/updatepackage.spec.ts +319 -0
- package/src/commands/package/updatepackage.ts +95 -0
- package/src/commands/project/createproject.spec.ts +247 -0
- package/src/commands/project/createproject.ts +70 -0
- package/src/commands/project/deleteproject.spec.ts +123 -0
- package/src/commands/project/deleteproject.ts +48 -0
- package/src/commands/project/getproject.spec.ts +109 -0
- package/src/commands/project/getproject.ts +43 -0
- package/src/commands/project/listprojects.spec.ts +121 -0
- package/src/commands/project/listprojects.ts +62 -0
- package/src/commands/project/setproject.spec.ts +63 -0
- package/src/commands/project/setproject.ts +14 -0
- package/src/commands/project/updateproject.spec.ts +217 -0
- package/src/commands/project/updateproject.ts +82 -0
- package/src/commands/rm.ts +101 -0
- package/src/commands/set.ts +16 -0
- package/src/commands/update.ts +64 -0
- package/src/commands/version/archive-unarchive-version.spec.ts +456 -0
- package/src/commands/version/archive-unarchive-version.ts +111 -0
- package/src/commands/version/listversions.spec.ts +138 -0
- package/src/commands/version/listversions.ts +45 -0
- package/src/common/UserGroupId.spec.ts +117 -0
- package/src/common/UserGroupId.ts +137 -0
- package/src/constants.ts +116 -0
- package/src/index.ts +209 -0
- package/src/logger.spec.ts +158 -0
- package/src/logger.ts +86 -0
- package/src/polyfills/file.polyfill.ts +6 -0
- package/src/utils.spec.ts +135 -0
- package/src/utils.ts +115 -0
- package/src/validator.spec.ts +51 -0
- package/src/validator.ts +44 -0
- package/tsconfig.json +17 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import sinon from "sinon";
|
|
3
|
+
import { GroupsApi } from "../../client/api";
|
|
4
|
+
import { ClientConfiguration } from "../../clientconfiguration";
|
|
5
|
+
import { logger } from "../../logger";
|
|
6
|
+
import { createGroup } from "./creategroup";
|
|
7
|
+
|
|
8
|
+
describe("create-group", () => {
|
|
9
|
+
let sandbox: sinon.SinonSandbox;
|
|
10
|
+
let createGroupStub: sinon.SinonStub;
|
|
11
|
+
let loggerStub: sinon.SinonStubbedInstance<typeof logger>;
|
|
12
|
+
let consoleLogStub: sinon.SinonStub;
|
|
13
|
+
let processExitStub: sinon.SinonStub;
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
sandbox = sinon.createSandbox();
|
|
17
|
+
createGroupStub = sandbox.stub();
|
|
18
|
+
loggerStub = sandbox.stub(logger);
|
|
19
|
+
consoleLogStub = sandbox.stub(console, "log");
|
|
20
|
+
processExitStub = sandbox.stub(process, "exit");
|
|
21
|
+
|
|
22
|
+
sandbox
|
|
23
|
+
.stub(ClientConfiguration.prototype, "getOrganization")
|
|
24
|
+
.returns("test-org");
|
|
25
|
+
sandbox
|
|
26
|
+
.stub(ClientConfiguration.prototype, "doesConfigExists")
|
|
27
|
+
.returns(true);
|
|
28
|
+
sandbox
|
|
29
|
+
.stub(ClientConfiguration.prototype, "getAuthenticationHeader")
|
|
30
|
+
.returns("Bearer test-token");
|
|
31
|
+
|
|
32
|
+
sandbox
|
|
33
|
+
.stub(GroupsApi.prototype, "createGroup")
|
|
34
|
+
.callsFake(createGroupStub);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
afterEach(() => {
|
|
38
|
+
sandbox.restore();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("should create group successfully", async () => {
|
|
42
|
+
const mockResponse = {
|
|
43
|
+
data: { groupName: "test-group", organizationName: "test-org" },
|
|
44
|
+
};
|
|
45
|
+
createGroupStub.resolves(mockResponse);
|
|
46
|
+
|
|
47
|
+
await createGroup("http://test-server", "test-group", false);
|
|
48
|
+
|
|
49
|
+
expect(createGroupStub.calledOnce).to.be.true;
|
|
50
|
+
expect(createGroupStub.firstCall.args[0]).to.equal("test-org");
|
|
51
|
+
expect(createGroupStub.firstCall.args[1]).to.deep.include({
|
|
52
|
+
organizationName: "test-org",
|
|
53
|
+
groupName: "test-group",
|
|
54
|
+
description: "Group test-group",
|
|
55
|
+
});
|
|
56
|
+
expect(consoleLogStub.called).to.be.true;
|
|
57
|
+
expect(
|
|
58
|
+
loggerStub.info.calledWith(sinon.match("Group created successfully")),
|
|
59
|
+
).to.be.true;
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("should create group with custom description", async () => {
|
|
63
|
+
const mockResponse = {
|
|
64
|
+
data: { groupName: "test-group" },
|
|
65
|
+
};
|
|
66
|
+
createGroupStub.resolves(mockResponse);
|
|
67
|
+
|
|
68
|
+
await createGroup(
|
|
69
|
+
"http://test-server",
|
|
70
|
+
"test-group",
|
|
71
|
+
false,
|
|
72
|
+
"Custom description",
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
expect(createGroupStub.firstCall.args[1]).to.deep.include({
|
|
76
|
+
description: "Custom description",
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("should handle missing config", async () => {
|
|
81
|
+
sandbox.restore();
|
|
82
|
+
sandbox = sinon.createSandbox();
|
|
83
|
+
createGroupStub = sandbox.stub();
|
|
84
|
+
loggerStub = sandbox.stub(logger);
|
|
85
|
+
consoleLogStub = sandbox.stub(console, "log");
|
|
86
|
+
processExitStub = sandbox.stub(process, "exit");
|
|
87
|
+
|
|
88
|
+
sandbox
|
|
89
|
+
.stub(ClientConfiguration.prototype, "doesConfigExists")
|
|
90
|
+
.returns(false);
|
|
91
|
+
sandbox
|
|
92
|
+
.stub(GroupsApi.prototype, "createGroup")
|
|
93
|
+
.callsFake(createGroupStub);
|
|
94
|
+
|
|
95
|
+
await createGroup("http://test-server", "test-group", false);
|
|
96
|
+
|
|
97
|
+
expect(createGroupStub.called).to.be.false;
|
|
98
|
+
expect(
|
|
99
|
+
loggerStub.error.calledWith(
|
|
100
|
+
sinon.match("Please, make sure that you are logged in"),
|
|
101
|
+
),
|
|
102
|
+
).to.be.true;
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("should handle missing organization", async () => {
|
|
106
|
+
sandbox.restore();
|
|
107
|
+
sandbox = sinon.createSandbox();
|
|
108
|
+
createGroupStub = sandbox.stub();
|
|
109
|
+
loggerStub = sandbox.stub(logger);
|
|
110
|
+
consoleLogStub = sandbox.stub(console, "log");
|
|
111
|
+
processExitStub = sandbox.stub(process, "exit");
|
|
112
|
+
|
|
113
|
+
sandbox
|
|
114
|
+
.stub(ClientConfiguration.prototype, "doesConfigExists")
|
|
115
|
+
.returns(true);
|
|
116
|
+
sandbox
|
|
117
|
+
.stub(ClientConfiguration.prototype, "getOrganization")
|
|
118
|
+
.returns(undefined);
|
|
119
|
+
sandbox
|
|
120
|
+
.stub(GroupsApi.prototype, "createGroup")
|
|
121
|
+
.callsFake(createGroupStub);
|
|
122
|
+
|
|
123
|
+
await createGroup("http://test-server", "test-group", false);
|
|
124
|
+
|
|
125
|
+
expect(createGroupStub.called).to.be.false;
|
|
126
|
+
expect(
|
|
127
|
+
loggerStub.error.calledWith(
|
|
128
|
+
sinon.match(
|
|
129
|
+
"No organization set. Please login or set an organization.",
|
|
130
|
+
),
|
|
131
|
+
),
|
|
132
|
+
).to.be.true;
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it("should handle API errors", async () => {
|
|
136
|
+
const mockError = new Error("API Error");
|
|
137
|
+
createGroupStub.rejects(mockError);
|
|
138
|
+
|
|
139
|
+
await createGroup("http://test-server", "test-group", true);
|
|
140
|
+
|
|
141
|
+
expect(createGroupStub.calledOnce).to.be.true;
|
|
142
|
+
expect(loggerStub.error.calledWith(sinon.match("Failed to create group")))
|
|
143
|
+
.to.be.true;
|
|
144
|
+
expect(processExitStub.calledWith(1)).to.be.true;
|
|
145
|
+
});
|
|
146
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Group, GroupsApi } from "../../client/api";
|
|
2
|
+
import { Configuration } from "../../client/configuration";
|
|
3
|
+
import { ClientConfiguration } from "../../clientconfiguration";
|
|
4
|
+
import { logger } from "../../logger";
|
|
5
|
+
import { printOutError } from "../../utils";
|
|
6
|
+
|
|
7
|
+
const groupsApi = new GroupsApi(new Configuration());
|
|
8
|
+
|
|
9
|
+
export async function createGroup(
|
|
10
|
+
controlPlane: string,
|
|
11
|
+
groupName: string,
|
|
12
|
+
debug: boolean,
|
|
13
|
+
description?: string,
|
|
14
|
+
) {
|
|
15
|
+
const clientConfig = new ClientConfiguration();
|
|
16
|
+
|
|
17
|
+
if (!clientConfig.doesConfigExists()) {
|
|
18
|
+
logger.error("Please, make sure that you are logged in");
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const organizationName = clientConfig.getOrganization();
|
|
23
|
+
if (!organizationName) {
|
|
24
|
+
logger.error("No organization set. Please login or set an organization.");
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
logger.info(
|
|
29
|
+
`Creating group ${groupName} in organization ${organizationName}`,
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const group: Group = {
|
|
33
|
+
organizationName,
|
|
34
|
+
groupName,
|
|
35
|
+
description: description || `Group ${groupName}`,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
const response = await groupsApi.createGroup(organizationName, group, {
|
|
40
|
+
baseURL: controlPlane,
|
|
41
|
+
headers: {
|
|
42
|
+
Authorization: clientConfig.getAuthenticationHeader(),
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const jsonString = JSON.stringify(response.data, null, 2);
|
|
47
|
+
console.log(jsonString);
|
|
48
|
+
logger.info("Group created successfully");
|
|
49
|
+
} catch (error) {
|
|
50
|
+
logger.error("Failed to create group");
|
|
51
|
+
printOutError(error, debug);
|
|
52
|
+
process.exit(1);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import sinon from "sinon";
|
|
3
|
+
import { GroupsApi } from "../../client/api";
|
|
4
|
+
import { ClientConfiguration } from "../../clientconfiguration";
|
|
5
|
+
import { logger } from "../../logger";
|
|
6
|
+
import { deleteGroup } from "./deletegroup";
|
|
7
|
+
|
|
8
|
+
describe("delete-group", () => {
|
|
9
|
+
let sandbox: sinon.SinonSandbox;
|
|
10
|
+
let deleteGroupStub: sinon.SinonStub;
|
|
11
|
+
let loggerStub: sinon.SinonStubbedInstance<typeof logger>;
|
|
12
|
+
let processExitStub: sinon.SinonStub;
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
sandbox = sinon.createSandbox();
|
|
16
|
+
deleteGroupStub = sandbox.stub();
|
|
17
|
+
loggerStub = sandbox.stub(logger);
|
|
18
|
+
processExitStub = sandbox.stub(process, "exit");
|
|
19
|
+
|
|
20
|
+
sandbox
|
|
21
|
+
.stub(ClientConfiguration.prototype, "getOrganization")
|
|
22
|
+
.returns("test-org");
|
|
23
|
+
sandbox
|
|
24
|
+
.stub(ClientConfiguration.prototype, "doesConfigExists")
|
|
25
|
+
.returns(true);
|
|
26
|
+
sandbox
|
|
27
|
+
.stub(ClientConfiguration.prototype, "getAuthenticationHeader")
|
|
28
|
+
.returns("Bearer test-token");
|
|
29
|
+
|
|
30
|
+
sandbox
|
|
31
|
+
.stub(GroupsApi.prototype, "deleteGroup")
|
|
32
|
+
.callsFake(deleteGroupStub);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
afterEach(() => {
|
|
36
|
+
sandbox.restore();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("should delete group successfully", async () => {
|
|
40
|
+
deleteGroupStub.resolves({ status: 200 });
|
|
41
|
+
|
|
42
|
+
await deleteGroup("http://test-server", "test-group", false);
|
|
43
|
+
|
|
44
|
+
expect(deleteGroupStub.calledOnce).to.be.true;
|
|
45
|
+
expect(deleteGroupStub.firstCall.args[0]).to.equal("test-org");
|
|
46
|
+
expect(deleteGroupStub.firstCall.args[1]).to.equal("test-group");
|
|
47
|
+
expect(deleteGroupStub.firstCall.args[2]).to.deep.include({
|
|
48
|
+
baseURL: "http://test-server",
|
|
49
|
+
headers: { Authorization: "Bearer test-token" },
|
|
50
|
+
});
|
|
51
|
+
expect(
|
|
52
|
+
loggerStub.info.calledWith(sinon.match("Group deleted successfully")),
|
|
53
|
+
).to.be.true;
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("should handle missing config", async () => {
|
|
57
|
+
sandbox.restore();
|
|
58
|
+
sandbox = sinon.createSandbox();
|
|
59
|
+
deleteGroupStub = sandbox.stub();
|
|
60
|
+
loggerStub = sandbox.stub(logger);
|
|
61
|
+
processExitStub = sandbox.stub(process, "exit");
|
|
62
|
+
|
|
63
|
+
sandbox
|
|
64
|
+
.stub(ClientConfiguration.prototype, "doesConfigExists")
|
|
65
|
+
.returns(false);
|
|
66
|
+
sandbox
|
|
67
|
+
.stub(GroupsApi.prototype, "deleteGroup")
|
|
68
|
+
.callsFake(deleteGroupStub);
|
|
69
|
+
|
|
70
|
+
await deleteGroup("http://test-server", "test-group", false);
|
|
71
|
+
|
|
72
|
+
expect(deleteGroupStub.called).to.be.false;
|
|
73
|
+
expect(
|
|
74
|
+
loggerStub.error.calledWith(
|
|
75
|
+
sinon.match("Please, make sure that you are logged in"),
|
|
76
|
+
),
|
|
77
|
+
).to.be.true;
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("should handle missing organization", async () => {
|
|
81
|
+
sandbox.restore();
|
|
82
|
+
sandbox = sinon.createSandbox();
|
|
83
|
+
deleteGroupStub = sandbox.stub();
|
|
84
|
+
loggerStub = sandbox.stub(logger);
|
|
85
|
+
processExitStub = sandbox.stub(process, "exit");
|
|
86
|
+
|
|
87
|
+
sandbox
|
|
88
|
+
.stub(ClientConfiguration.prototype, "doesConfigExists")
|
|
89
|
+
.returns(true);
|
|
90
|
+
sandbox
|
|
91
|
+
.stub(ClientConfiguration.prototype, "getOrganization")
|
|
92
|
+
.returns(undefined);
|
|
93
|
+
sandbox
|
|
94
|
+
.stub(GroupsApi.prototype, "deleteGroup")
|
|
95
|
+
.callsFake(deleteGroupStub);
|
|
96
|
+
|
|
97
|
+
await deleteGroup("http://test-server", "test-group", false);
|
|
98
|
+
|
|
99
|
+
expect(deleteGroupStub.called).to.be.false;
|
|
100
|
+
expect(
|
|
101
|
+
loggerStub.error.calledWith(
|
|
102
|
+
sinon.match(
|
|
103
|
+
"No organization set. Please login or set an organization.",
|
|
104
|
+
),
|
|
105
|
+
),
|
|
106
|
+
).to.be.true;
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("should handle API errors", async () => {
|
|
110
|
+
const mockError = new Error("API Error");
|
|
111
|
+
deleteGroupStub.rejects(mockError);
|
|
112
|
+
|
|
113
|
+
await deleteGroup("http://test-server", "test-group", true);
|
|
114
|
+
|
|
115
|
+
expect(deleteGroupStub.calledOnce).to.be.true;
|
|
116
|
+
expect(loggerStub.error.calledWith(sinon.match("Failed to delete group")))
|
|
117
|
+
.to.be.true;
|
|
118
|
+
expect(processExitStub.calledWith(1)).to.be.true;
|
|
119
|
+
});
|
|
120
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { GroupsApi } from "../../client/api";
|
|
2
|
+
import { Configuration } from "../../client/configuration";
|
|
3
|
+
import { ClientConfiguration } from "../../clientconfiguration";
|
|
4
|
+
import { logger } from "../../logger";
|
|
5
|
+
import { printOutError } from "../../utils";
|
|
6
|
+
|
|
7
|
+
const groupsApi = new GroupsApi(new Configuration());
|
|
8
|
+
|
|
9
|
+
export async function deleteGroup(
|
|
10
|
+
controlPlane: string,
|
|
11
|
+
groupName: string,
|
|
12
|
+
debug: boolean,
|
|
13
|
+
) {
|
|
14
|
+
const clientConfig = new ClientConfiguration();
|
|
15
|
+
|
|
16
|
+
if (!clientConfig.doesConfigExists()) {
|
|
17
|
+
logger.error("Please, make sure that you are logged in");
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const organizationName = clientConfig.getOrganization();
|
|
22
|
+
if (!organizationName) {
|
|
23
|
+
logger.error("No organization set. Please login or set an organization.");
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
logger.info(
|
|
28
|
+
`Deleting group ${groupName} from organization ${organizationName}`,
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
await groupsApi.deleteGroup(organizationName, groupName, {
|
|
33
|
+
baseURL: controlPlane,
|
|
34
|
+
headers: {
|
|
35
|
+
Authorization: clientConfig.getAuthenticationHeader(),
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
logger.info("Group deleted successfully");
|
|
40
|
+
} catch (error) {
|
|
41
|
+
logger.error("Failed to delete group");
|
|
42
|
+
printOutError(error, debug);
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import sinon from "sinon";
|
|
3
|
+
import { GroupsApi } from "../../client/api";
|
|
4
|
+
import { ClientConfiguration } from "../../clientconfiguration";
|
|
5
|
+
import { logger } from "../../logger";
|
|
6
|
+
import { getGroup } from "./getgroup";
|
|
7
|
+
|
|
8
|
+
describe("get-group", () => {
|
|
9
|
+
let sandbox: sinon.SinonSandbox;
|
|
10
|
+
let getGroupStub: sinon.SinonStub;
|
|
11
|
+
let loggerStub: sinon.SinonStubbedInstance<typeof logger>;
|
|
12
|
+
let consoleLogStub: sinon.SinonStub;
|
|
13
|
+
let processExitStub: sinon.SinonStub;
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
sandbox = sinon.createSandbox();
|
|
17
|
+
getGroupStub = sandbox.stub();
|
|
18
|
+
loggerStub = sandbox.stub(logger);
|
|
19
|
+
consoleLogStub = sandbox.stub(console, "log");
|
|
20
|
+
processExitStub = sandbox.stub(process, "exit");
|
|
21
|
+
|
|
22
|
+
sandbox
|
|
23
|
+
.stub(ClientConfiguration.prototype, "getOrganization")
|
|
24
|
+
.returns("test-org");
|
|
25
|
+
sandbox
|
|
26
|
+
.stub(ClientConfiguration.prototype, "doesConfigExists")
|
|
27
|
+
.returns(true);
|
|
28
|
+
sandbox
|
|
29
|
+
.stub(ClientConfiguration.prototype, "getAuthenticationHeader")
|
|
30
|
+
.returns("Bearer test-token");
|
|
31
|
+
|
|
32
|
+
sandbox.stub(GroupsApi.prototype, "getGroup").callsFake(getGroupStub);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
afterEach(() => {
|
|
36
|
+
sandbox.restore();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("should get group successfully", async () => {
|
|
40
|
+
const mockGroupData = {
|
|
41
|
+
groupName: "test-group",
|
|
42
|
+
organizationName: "test-org",
|
|
43
|
+
description: "Test group",
|
|
44
|
+
};
|
|
45
|
+
const mockResponse = {
|
|
46
|
+
data: mockGroupData,
|
|
47
|
+
};
|
|
48
|
+
getGroupStub.resolves(mockResponse);
|
|
49
|
+
|
|
50
|
+
await getGroup("http://test-server", "test-group", false);
|
|
51
|
+
|
|
52
|
+
expect(getGroupStub.calledOnce).to.be.true;
|
|
53
|
+
expect(getGroupStub.firstCall.args[0]).to.equal("test-org");
|
|
54
|
+
expect(getGroupStub.firstCall.args[1]).to.equal("test-group");
|
|
55
|
+
expect(getGroupStub.firstCall.args[2]).to.deep.include({
|
|
56
|
+
baseURL: "http://test-server",
|
|
57
|
+
headers: { Authorization: "Bearer test-token" },
|
|
58
|
+
});
|
|
59
|
+
expect(consoleLogStub.called).to.be.true;
|
|
60
|
+
expect(
|
|
61
|
+
loggerStub.info.calledWith(
|
|
62
|
+
sinon.match("Group retrieved successfully"),
|
|
63
|
+
),
|
|
64
|
+
).to.be.true;
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("should handle missing config", async () => {
|
|
68
|
+
sandbox.restore();
|
|
69
|
+
sandbox = sinon.createSandbox();
|
|
70
|
+
getGroupStub = sandbox.stub();
|
|
71
|
+
loggerStub = sandbox.stub(logger);
|
|
72
|
+
consoleLogStub = sandbox.stub(console, "log");
|
|
73
|
+
processExitStub = sandbox.stub(process, "exit");
|
|
74
|
+
|
|
75
|
+
sandbox
|
|
76
|
+
.stub(ClientConfiguration.prototype, "doesConfigExists")
|
|
77
|
+
.returns(false);
|
|
78
|
+
sandbox.stub(GroupsApi.prototype, "getGroup").callsFake(getGroupStub);
|
|
79
|
+
|
|
80
|
+
await getGroup("http://test-server", "test-group", false);
|
|
81
|
+
|
|
82
|
+
expect(getGroupStub.called).to.be.false;
|
|
83
|
+
expect(
|
|
84
|
+
loggerStub.error.calledWith(
|
|
85
|
+
sinon.match("Please, make sure that you are logged in"),
|
|
86
|
+
),
|
|
87
|
+
).to.be.true;
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("should handle missing organization", async () => {
|
|
91
|
+
sandbox.restore();
|
|
92
|
+
sandbox = sinon.createSandbox();
|
|
93
|
+
getGroupStub = sandbox.stub();
|
|
94
|
+
loggerStub = sandbox.stub(logger);
|
|
95
|
+
consoleLogStub = sandbox.stub(console, "log");
|
|
96
|
+
processExitStub = sandbox.stub(process, "exit");
|
|
97
|
+
|
|
98
|
+
sandbox
|
|
99
|
+
.stub(ClientConfiguration.prototype, "doesConfigExists")
|
|
100
|
+
.returns(true);
|
|
101
|
+
sandbox
|
|
102
|
+
.stub(ClientConfiguration.prototype, "getOrganization")
|
|
103
|
+
.returns(undefined);
|
|
104
|
+
sandbox.stub(GroupsApi.prototype, "getGroup").callsFake(getGroupStub);
|
|
105
|
+
|
|
106
|
+
await getGroup("http://test-server", "test-group", false);
|
|
107
|
+
|
|
108
|
+
expect(getGroupStub.called).to.be.false;
|
|
109
|
+
expect(
|
|
110
|
+
loggerStub.error.calledWith(
|
|
111
|
+
sinon.match(
|
|
112
|
+
"No organization set. Please login or set an organization.",
|
|
113
|
+
),
|
|
114
|
+
),
|
|
115
|
+
).to.be.true;
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it("should handle API errors", async () => {
|
|
119
|
+
const mockError = new Error("API Error");
|
|
120
|
+
getGroupStub.rejects(mockError);
|
|
121
|
+
|
|
122
|
+
await getGroup("http://test-server", "test-group", true);
|
|
123
|
+
|
|
124
|
+
expect(getGroupStub.calledOnce).to.be.true;
|
|
125
|
+
expect(loggerStub.error.calledWith(sinon.match("Failed to get group"))).to
|
|
126
|
+
.be.true;
|
|
127
|
+
expect(processExitStub.calledWith(1)).to.be.true;
|
|
128
|
+
});
|
|
129
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { GroupsApi } from "../../client/api";
|
|
2
|
+
import { Configuration } from "../../client/configuration";
|
|
3
|
+
import { ClientConfiguration } from "../../clientconfiguration";
|
|
4
|
+
import { logger } from "../../logger";
|
|
5
|
+
import { printOutError } from "../../utils";
|
|
6
|
+
|
|
7
|
+
const groupsApi = new GroupsApi(new Configuration());
|
|
8
|
+
|
|
9
|
+
export async function getGroup(
|
|
10
|
+
controlPlane: string,
|
|
11
|
+
groupName: string,
|
|
12
|
+
debug: boolean,
|
|
13
|
+
) {
|
|
14
|
+
const clientConfig = new ClientConfiguration();
|
|
15
|
+
|
|
16
|
+
if (!clientConfig.doesConfigExists()) {
|
|
17
|
+
logger.error("Please, make sure that you are logged in");
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const organizationName = clientConfig.getOrganization();
|
|
22
|
+
if (!organizationName) {
|
|
23
|
+
logger.error("No organization set. Please login or set an organization.");
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
logger.info(
|
|
28
|
+
`Getting group ${groupName} from organization ${organizationName}`,
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
const response = await groupsApi.getGroup(organizationName, groupName, {
|
|
33
|
+
baseURL: controlPlane,
|
|
34
|
+
headers: {
|
|
35
|
+
Authorization: clientConfig.getAuthenticationHeader(),
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const jsonString = JSON.stringify(response.data, null, 2);
|
|
40
|
+
console.log(jsonString);
|
|
41
|
+
logger.info("Group retrieved successfully");
|
|
42
|
+
} catch (error) {
|
|
43
|
+
logger.error("Failed to get group");
|
|
44
|
+
printOutError(error, debug);
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import sinon from "sinon";
|
|
3
|
+
import { GroupsApi } from "../../client/api";
|
|
4
|
+
import { ClientConfiguration } from "../../clientconfiguration";
|
|
5
|
+
import { logger } from "../../logger";
|
|
6
|
+
import { listGroups, printOutGroups } from "./listgroups";
|
|
7
|
+
|
|
8
|
+
describe("list-groups", () => {
|
|
9
|
+
let sandbox: sinon.SinonSandbox;
|
|
10
|
+
let listGroupsStub: sinon.SinonStub;
|
|
11
|
+
let loggerStub: sinon.SinonStubbedInstance<typeof logger>;
|
|
12
|
+
let consoleLogStub: sinon.SinonStub;
|
|
13
|
+
let processExitStub: sinon.SinonStub;
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
sandbox = sinon.createSandbox();
|
|
17
|
+
listGroupsStub = sandbox.stub();
|
|
18
|
+
loggerStub = sandbox.stub(logger);
|
|
19
|
+
consoleLogStub = sandbox.stub(console, "log");
|
|
20
|
+
processExitStub = sandbox.stub(process, "exit");
|
|
21
|
+
|
|
22
|
+
sandbox
|
|
23
|
+
.stub(ClientConfiguration.prototype, "getOrganization")
|
|
24
|
+
.returns("test-org");
|
|
25
|
+
sandbox
|
|
26
|
+
.stub(ClientConfiguration.prototype, "doesConfigExists")
|
|
27
|
+
.returns(true);
|
|
28
|
+
sandbox
|
|
29
|
+
.stub(ClientConfiguration.prototype, "getAuthenticationHeader")
|
|
30
|
+
.returns("Bearer test-token");
|
|
31
|
+
|
|
32
|
+
sandbox.stub(GroupsApi.prototype, "listGroups").callsFake(listGroupsStub);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
afterEach(() => {
|
|
36
|
+
sandbox.restore();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("should list groups successfully", async () => {
|
|
40
|
+
const mockGroups = [
|
|
41
|
+
{ groupName: "group1", organizationName: "test-org" },
|
|
42
|
+
{ groupName: "group2", organizationName: "test-org" },
|
|
43
|
+
];
|
|
44
|
+
const mockResponse = {
|
|
45
|
+
data: mockGroups,
|
|
46
|
+
};
|
|
47
|
+
listGroupsStub.resolves(mockResponse);
|
|
48
|
+
|
|
49
|
+
await listGroups("http://test-server", false);
|
|
50
|
+
|
|
51
|
+
expect(listGroupsStub.calledOnce).to.be.true;
|
|
52
|
+
expect(listGroupsStub.firstCall.args[0]).to.equal("test-org");
|
|
53
|
+
expect(listGroupsStub.firstCall.args[1]).to.deep.include({
|
|
54
|
+
baseURL: "http://test-server",
|
|
55
|
+
headers: { Authorization: "Bearer test-token" },
|
|
56
|
+
});
|
|
57
|
+
expect(consoleLogStub.called).to.be.true;
|
|
58
|
+
expect(
|
|
59
|
+
loggerStub.info.calledWith(sinon.match("Groups listed successfully")),
|
|
60
|
+
).to.be.true;
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("should handle missing config", async () => {
|
|
64
|
+
sandbox.restore();
|
|
65
|
+
sandbox = sinon.createSandbox();
|
|
66
|
+
listGroupsStub = sandbox.stub();
|
|
67
|
+
loggerStub = sandbox.stub(logger);
|
|
68
|
+
consoleLogStub = sandbox.stub(console, "log");
|
|
69
|
+
processExitStub = sandbox.stub(process, "exit");
|
|
70
|
+
|
|
71
|
+
sandbox
|
|
72
|
+
.stub(ClientConfiguration.prototype, "doesConfigExists")
|
|
73
|
+
.returns(false);
|
|
74
|
+
sandbox.stub(GroupsApi.prototype, "listGroups").callsFake(listGroupsStub);
|
|
75
|
+
|
|
76
|
+
await listGroups("http://test-server", false);
|
|
77
|
+
|
|
78
|
+
expect(listGroupsStub.called).to.be.false;
|
|
79
|
+
expect(
|
|
80
|
+
loggerStub.error.calledWith(
|
|
81
|
+
sinon.match("Please, make sure that you are logged in"),
|
|
82
|
+
),
|
|
83
|
+
).to.be.true;
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("should handle missing organization", async () => {
|
|
87
|
+
sandbox.restore();
|
|
88
|
+
sandbox = sinon.createSandbox();
|
|
89
|
+
listGroupsStub = sandbox.stub();
|
|
90
|
+
loggerStub = sandbox.stub(logger);
|
|
91
|
+
consoleLogStub = sandbox.stub(console, "log");
|
|
92
|
+
processExitStub = sandbox.stub(process, "exit");
|
|
93
|
+
|
|
94
|
+
sandbox
|
|
95
|
+
.stub(ClientConfiguration.prototype, "doesConfigExists")
|
|
96
|
+
.returns(true);
|
|
97
|
+
sandbox
|
|
98
|
+
.stub(ClientConfiguration.prototype, "getOrganization")
|
|
99
|
+
.returns(undefined);
|
|
100
|
+
sandbox.stub(GroupsApi.prototype, "listGroups").callsFake(listGroupsStub);
|
|
101
|
+
|
|
102
|
+
await listGroups("http://test-server", false);
|
|
103
|
+
|
|
104
|
+
expect(listGroupsStub.called).to.be.false;
|
|
105
|
+
expect(
|
|
106
|
+
loggerStub.error.calledWith(
|
|
107
|
+
sinon.match(
|
|
108
|
+
"No organization set. Please login or set an organization.",
|
|
109
|
+
),
|
|
110
|
+
),
|
|
111
|
+
).to.be.true;
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("should handle API errors", async () => {
|
|
115
|
+
const mockError = new Error("API Error");
|
|
116
|
+
listGroupsStub.rejects(mockError);
|
|
117
|
+
|
|
118
|
+
await listGroups("http://test-server", true);
|
|
119
|
+
|
|
120
|
+
expect(listGroupsStub.calledOnce).to.be.true;
|
|
121
|
+
expect(loggerStub.error.calledWith(sinon.match("Failed to list groups")))
|
|
122
|
+
.to.be.true;
|
|
123
|
+
expect(processExitStub.calledWith(1)).to.be.true;
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("should work with printOutGroups", async () => {
|
|
127
|
+
const mockGroups = [{ groupName: "group1" }];
|
|
128
|
+
const mockResponse = {
|
|
129
|
+
data: mockGroups,
|
|
130
|
+
};
|
|
131
|
+
listGroupsStub.resolves(mockResponse);
|
|
132
|
+
|
|
133
|
+
await printOutGroups("http://test-server", false);
|
|
134
|
+
|
|
135
|
+
expect(listGroupsStub.calledOnce).to.be.true;
|
|
136
|
+
});
|
|
137
|
+
});
|