@credibledata/cred-cli 0.1.4 → 0.1.5
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/.prettierignore +2 -1
- package/README.md +0 -2
- package/bun.lock +182 -283
- package/dist/client/api.js +796 -111
- package/dist/client/api.js.map +1 -1
- package/dist/clientconfiguration.js +55 -13
- package/dist/clientconfiguration.js.map +1 -1
- package/dist/clientconfiguration.spec.js +305 -16
- package/dist/clientconfiguration.spec.js.map +1 -1
- package/dist/commands/add.js +6 -3
- package/dist/commands/add.js.map +1 -1
- package/dist/commands/connection/createconnections.js +18 -3
- package/dist/commands/connection/createconnections.js.map +1 -1
- package/dist/commands/connection/createconnections.spec.js +219 -0
- package/dist/commands/connection/createconnections.spec.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 +9 -3
- package/dist/commands/connection/listconnections.js.map +1 -1
- package/dist/commands/connection/listconnections.spec.js +117 -0
- package/dist/commands/connection/listconnections.spec.js.map +1 -0
- package/dist/commands/group/addmember.js +2 -0
- package/dist/commands/group/addmember.js.map +1 -1
- package/dist/commands/group/addmember.spec.js +148 -0
- package/dist/commands/group/addmember.spec.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.spec.js +104 -0
- package/dist/commands/group/deletegroup.spec.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.spec.js +118 -0
- package/dist/commands/group/listgroups.spec.js.map +1 -0
- package/dist/commands/group/removemember.js +1 -0
- package/dist/commands/group/removemember.js.map +1 -1
- 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 +6 -2
- package/dist/commands/groupaccesstoken/createToken.js.map +1 -1
- 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.map +1 -1
- 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.map +1 -1
- package/dist/commands/groupaccesstoken/listTokens.js.map +1 -1
- package/dist/commands/groupaccesstoken/listTokens.spec.js +115 -0
- package/dist/commands/groupaccesstoken/listTokens.spec.js.map +1 -0
- package/dist/commands/list.js +10 -3
- package/dist/commands/list.js.map +1 -1
- package/dist/commands/misc/login.js +146 -22
- package/dist/commands/misc/login.js.map +1 -1
- package/dist/commands/misc/login.spec.js +111 -6
- package/dist/commands/misc/login.spec.js.map +1 -1
- 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.map +1 -1
- 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.spec.js +136 -0
- package/dist/commands/package/deletepackage.spec.js.map +1 -0
- package/dist/commands/package/listpackages.js +10 -5
- package/dist/commands/package/listpackages.js.map +1 -1
- 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 +23 -0
- package/dist/commands/package/publish.js.map +1 -1
- package/dist/commands/package/publish.spec.js +511 -0
- package/dist/commands/package/publish.spec.js.map +1 -0
- package/dist/commands/package/updatepackage.spec.js +50 -0
- package/dist/commands/package/updatepackage.spec.js.map +1 -1
- package/dist/commands/project/createproject.js +11 -1
- package/dist/commands/project/createproject.js.map +1 -1
- package/dist/commands/project/createproject.spec.js +154 -0
- package/dist/commands/project/createproject.spec.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.spec.js +99 -0
- package/dist/commands/project/getproject.spec.js.map +1 -0
- package/dist/commands/project/listprojects.js +13 -7
- package/dist/commands/project/listprojects.js.map +1 -1
- package/dist/commands/project/listprojects.spec.js +111 -0
- package/dist/commands/project/listprojects.spec.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.map +1 -1
- package/dist/commands/update.js +13 -0
- package/dist/commands/update.js.map +1 -1
- package/dist/commands/version/listversions.spec.js +121 -0
- package/dist/commands/version/listversions.spec.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 +49 -13
- package/dist/constants.js.map +1 -1
- package/dist/index.js +40 -18
- package/dist/index.js.map +1 -1
- package/dist/logger.spec.js +125 -0
- package/dist/logger.spec.js.map +1 -0
- package/dist/polyfills/file.polyfill.js.map +1 -1
- package/dist/utils.js +59 -0
- package/dist/utils.js.map +1 -1
- package/dist/utils.spec.js +158 -0
- package/dist/utils.spec.js.map +1 -0
- package/docker/Dockerfile.ci +11 -3
- package/eslint.config.mjs +45 -0
- package/generate-client.sh +3 -0
- package/package.json +24 -16
- package/src/client/.openapi-generator/FILES +1 -0
- package/src/client/api.ts +1347 -161
- package/src/clientconfiguration.spec.ts +394 -20
- package/src/clientconfiguration.ts +74 -15
- package/src/commands/add.ts +15 -6
- package/src/commands/connection/createconnections.spec.ts +403 -0
- package/src/commands/connection/createconnections.ts +30 -5
- package/src/commands/connection/deleteconnection.spec.ts +189 -0
- package/src/commands/connection/listconnections.spec.ts +132 -0
- package/src/commands/connection/listconnections.ts +22 -3
- package/src/commands/group/addmember.spec.ts +257 -0
- package/src/commands/group/addmember.ts +2 -0
- package/src/commands/group/creategroup.spec.ts +146 -0
- package/src/commands/group/deletegroup.spec.ts +120 -0
- package/src/commands/group/getgroup.spec.ts +129 -0
- package/src/commands/group/listgroups.spec.ts +137 -0
- package/src/commands/group/removemember.spec.ts +224 -0
- package/src/commands/group/removemember.ts +1 -0
- package/src/commands/groupaccesstoken/createToken.spec.ts +211 -0
- package/src/commands/groupaccesstoken/createToken.ts +55 -51
- package/src/commands/groupaccesstoken/deleteToken.spec.ts +147 -0
- package/src/commands/groupaccesstoken/deleteToken.ts +16 -11
- package/src/commands/groupaccesstoken/groupContainer.ts +51 -51
- package/src/commands/groupaccesstoken/listTokens.spec.ts +147 -0
- package/src/commands/groupaccesstoken/listTokens.ts +16 -11
- package/src/commands/list.ts +50 -9
- package/src/commands/misc/login.spec.ts +91 -6
- package/src/commands/misc/login.ts +208 -25
- package/src/commands/misc/logout.spec.ts +32 -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 +16 -16
- package/src/commands/package/deletepackage.spec.ts +164 -0
- package/src/commands/package/listpackages.spec.ts +147 -0
- package/src/commands/package/listpackages.ts +28 -5
- package/src/commands/package/publish.spec.ts +597 -0
- package/src/commands/package/publish.ts +32 -0
- package/src/commands/package/updatepackage.spec.ts +98 -0
- package/src/commands/project/createproject.spec.ts +247 -0
- package/src/commands/project/createproject.ts +12 -1
- package/src/commands/project/deleteproject.spec.ts +123 -0
- package/src/commands/project/getproject.spec.ts +109 -0
- package/src/commands/project/listprojects.spec.ts +121 -0
- package/src/commands/project/listprojects.ts +33 -7
- package/src/commands/project/setproject.spec.ts +63 -0
- package/src/commands/project/updateproject.spec.ts +217 -0
- package/src/commands/project/updateproject.ts +82 -0
- package/src/commands/rm.ts +1 -6
- package/src/commands/update.ts +24 -1
- package/src/commands/version/listversions.spec.ts +138 -0
- package/src/common/UserGroupId.spec.ts +117 -0
- package/src/constants.ts +59 -13
- package/src/index.ts +46 -20
- package/src/logger.spec.ts +158 -0
- package/src/polyfills/file.polyfill.ts +1 -0
- package/src/utils.spec.ts +135 -0
- package/src/utils.ts +81 -0
- package/tsconfig.json +15 -18
- package/.eslintrc +0 -33
|
@@ -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,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,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
|
+
});
|
|
@@ -0,0 +1,224 @@
|
|
|
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 { removeMember } from "./removemember";
|
|
7
|
+
|
|
8
|
+
describe("remove-member", () => {
|
|
9
|
+
let sandbox: sinon.SinonSandbox;
|
|
10
|
+
let removeGroupMembersStub: sinon.SinonStub;
|
|
11
|
+
let loggerStub: sinon.SinonStubbedInstance<typeof logger>;
|
|
12
|
+
let processExitStub: sinon.SinonStub;
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
sandbox = sinon.createSandbox();
|
|
16
|
+
removeGroupMembersStub = 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, "removeGroupMembers")
|
|
32
|
+
.callsFake(removeGroupMembersStub);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
afterEach(() => {
|
|
36
|
+
sandbox.restore();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("should remove user member successfully", async () => {
|
|
40
|
+
const mockResponse = {
|
|
41
|
+
data: {},
|
|
42
|
+
};
|
|
43
|
+
removeGroupMembersStub.resolves(mockResponse);
|
|
44
|
+
|
|
45
|
+
await removeMember(
|
|
46
|
+
"http://test-server",
|
|
47
|
+
"test-group",
|
|
48
|
+
"user",
|
|
49
|
+
"test-user",
|
|
50
|
+
false,
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
expect(removeGroupMembersStub.calledOnce).to.be.true;
|
|
54
|
+
expect(removeGroupMembersStub.firstCall.args[0]).to.equal("test-org");
|
|
55
|
+
expect(removeGroupMembersStub.firstCall.args[1]).to.equal("test-group");
|
|
56
|
+
expect(removeGroupMembersStub.firstCall.args[2]).to.deep.include({
|
|
57
|
+
members: [
|
|
58
|
+
{
|
|
59
|
+
userGroupId: "user:test-user",
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
});
|
|
63
|
+
expect(
|
|
64
|
+
loggerStub.info.calledWith(
|
|
65
|
+
sinon.match(
|
|
66
|
+
"Successfully removed user test-user from group test-group",
|
|
67
|
+
),
|
|
68
|
+
),
|
|
69
|
+
).to.be.true;
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("should remove group member successfully", async () => {
|
|
73
|
+
const mockResponse = {
|
|
74
|
+
data: {},
|
|
75
|
+
};
|
|
76
|
+
removeGroupMembersStub.resolves(mockResponse);
|
|
77
|
+
|
|
78
|
+
await removeMember(
|
|
79
|
+
"http://test-server",
|
|
80
|
+
"test-group",
|
|
81
|
+
"group",
|
|
82
|
+
"test-subgroup",
|
|
83
|
+
false,
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
expect(removeGroupMembersStub.firstCall.args[2]).to.deep.include({
|
|
87
|
+
members: [
|
|
88
|
+
{
|
|
89
|
+
userGroupId: "group:test-subgroup",
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
});
|
|
93
|
+
expect(
|
|
94
|
+
loggerStub.info.calledWith(
|
|
95
|
+
sinon.match(
|
|
96
|
+
"Successfully removed group test-subgroup from group test-group",
|
|
97
|
+
),
|
|
98
|
+
),
|
|
99
|
+
).to.be.true;
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("should handle case-insensitive member type", async () => {
|
|
103
|
+
const mockResponse = {
|
|
104
|
+
data: {},
|
|
105
|
+
};
|
|
106
|
+
removeGroupMembersStub.resolves(mockResponse);
|
|
107
|
+
|
|
108
|
+
await removeMember(
|
|
109
|
+
"http://test-server",
|
|
110
|
+
"test-group",
|
|
111
|
+
"USER",
|
|
112
|
+
"test-user",
|
|
113
|
+
false,
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
expect(
|
|
117
|
+
removeGroupMembersStub.firstCall.args[2].members[0].userGroupId,
|
|
118
|
+
).to.equal("user:test-user");
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("should handle missing config", async () => {
|
|
122
|
+
sandbox.restore();
|
|
123
|
+
sandbox = sinon.createSandbox();
|
|
124
|
+
removeGroupMembersStub = sandbox.stub();
|
|
125
|
+
loggerStub = sandbox.stub(logger);
|
|
126
|
+
processExitStub = sandbox.stub(process, "exit");
|
|
127
|
+
|
|
128
|
+
sandbox
|
|
129
|
+
.stub(ClientConfiguration.prototype, "doesConfigExists")
|
|
130
|
+
.returns(false);
|
|
131
|
+
sandbox
|
|
132
|
+
.stub(GroupsApi.prototype, "removeGroupMembers")
|
|
133
|
+
.callsFake(removeGroupMembersStub);
|
|
134
|
+
|
|
135
|
+
await removeMember(
|
|
136
|
+
"http://test-server",
|
|
137
|
+
"test-group",
|
|
138
|
+
"user",
|
|
139
|
+
"test-user",
|
|
140
|
+
false,
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
expect(removeGroupMembersStub.called).to.be.false;
|
|
144
|
+
expect(
|
|
145
|
+
loggerStub.error.calledWith(
|
|
146
|
+
sinon.match("Please, make sure that you are logged in"),
|
|
147
|
+
),
|
|
148
|
+
).to.be.true;
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("should handle missing organization", async () => {
|
|
152
|
+
sandbox.restore();
|
|
153
|
+
sandbox = sinon.createSandbox();
|
|
154
|
+
removeGroupMembersStub = sandbox.stub();
|
|
155
|
+
loggerStub = sandbox.stub(logger);
|
|
156
|
+
processExitStub = sandbox.stub(process, "exit");
|
|
157
|
+
|
|
158
|
+
sandbox
|
|
159
|
+
.stub(ClientConfiguration.prototype, "doesConfigExists")
|
|
160
|
+
.returns(true);
|
|
161
|
+
sandbox
|
|
162
|
+
.stub(ClientConfiguration.prototype, "getOrganization")
|
|
163
|
+
.returns(undefined);
|
|
164
|
+
sandbox
|
|
165
|
+
.stub(GroupsApi.prototype, "removeGroupMembers")
|
|
166
|
+
.callsFake(removeGroupMembersStub);
|
|
167
|
+
|
|
168
|
+
await removeMember(
|
|
169
|
+
"http://test-server",
|
|
170
|
+
"test-group",
|
|
171
|
+
"user",
|
|
172
|
+
"test-user",
|
|
173
|
+
false,
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
expect(removeGroupMembersStub.called).to.be.false;
|
|
177
|
+
expect(
|
|
178
|
+
loggerStub.error.calledWith(
|
|
179
|
+
sinon.match(
|
|
180
|
+
"No organization set. Please login or set an organization.",
|
|
181
|
+
),
|
|
182
|
+
),
|
|
183
|
+
).to.be.true;
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it("should reject invalid member type", async () => {
|
|
187
|
+
await removeMember(
|
|
188
|
+
"http://test-server",
|
|
189
|
+
"test-group",
|
|
190
|
+
"invalid",
|
|
191
|
+
"test-user",
|
|
192
|
+
false,
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
expect(removeGroupMembersStub.called).to.be.false;
|
|
196
|
+
expect(
|
|
197
|
+
loggerStub.error.calledWith(
|
|
198
|
+
sinon.match("Error: memberType must be either 'user' or 'group'"),
|
|
199
|
+
),
|
|
200
|
+
).to.be.true;
|
|
201
|
+
expect(processExitStub.calledWith(1)).to.be.true;
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("should handle API errors", async () => {
|
|
205
|
+
const mockError = new Error("API Error");
|
|
206
|
+
removeGroupMembersStub.rejects(mockError);
|
|
207
|
+
|
|
208
|
+
await removeMember(
|
|
209
|
+
"http://test-server",
|
|
210
|
+
"test-group",
|
|
211
|
+
"user",
|
|
212
|
+
"test-user",
|
|
213
|
+
true,
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
expect(removeGroupMembersStub.calledOnce).to.be.true;
|
|
217
|
+
expect(
|
|
218
|
+
loggerStub.error.calledWith(
|
|
219
|
+
sinon.match("Failed to remove member from group"),
|
|
220
|
+
),
|
|
221
|
+
).to.be.true;
|
|
222
|
+
expect(processExitStub.calledWith(1)).to.be.true;
|
|
223
|
+
});
|
|
224
|
+
});
|