@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.
Files changed (172) hide show
  1. package/.prettierignore +2 -1
  2. package/README.md +0 -2
  3. package/bun.lock +182 -283
  4. package/dist/client/api.js +796 -111
  5. package/dist/client/api.js.map +1 -1
  6. package/dist/clientconfiguration.js +55 -13
  7. package/dist/clientconfiguration.js.map +1 -1
  8. package/dist/clientconfiguration.spec.js +305 -16
  9. package/dist/clientconfiguration.spec.js.map +1 -1
  10. package/dist/commands/add.js +6 -3
  11. package/dist/commands/add.js.map +1 -1
  12. package/dist/commands/connection/createconnections.js +18 -3
  13. package/dist/commands/connection/createconnections.js.map +1 -1
  14. package/dist/commands/connection/createconnections.spec.js +219 -0
  15. package/dist/commands/connection/createconnections.spec.js.map +1 -0
  16. package/dist/commands/connection/deleteconnection.spec.js +130 -0
  17. package/dist/commands/connection/deleteconnection.spec.js.map +1 -0
  18. package/dist/commands/connection/listconnections.js +9 -3
  19. package/dist/commands/connection/listconnections.js.map +1 -1
  20. package/dist/commands/connection/listconnections.spec.js +117 -0
  21. package/dist/commands/connection/listconnections.spec.js.map +1 -0
  22. package/dist/commands/group/addmember.js +2 -0
  23. package/dist/commands/group/addmember.js.map +1 -1
  24. package/dist/commands/group/addmember.spec.js +148 -0
  25. package/dist/commands/group/addmember.spec.js.map +1 -0
  26. package/dist/commands/group/creategroup.spec.js +122 -0
  27. package/dist/commands/group/creategroup.spec.js.map +1 -0
  28. package/dist/commands/group/deletegroup.spec.js +104 -0
  29. package/dist/commands/group/deletegroup.spec.js.map +1 -0
  30. package/dist/commands/group/getgroup.spec.js +111 -0
  31. package/dist/commands/group/getgroup.spec.js.map +1 -0
  32. package/dist/commands/group/listgroups.spec.js +118 -0
  33. package/dist/commands/group/listgroups.spec.js.map +1 -0
  34. package/dist/commands/group/removemember.js +1 -0
  35. package/dist/commands/group/removemember.js.map +1 -1
  36. package/dist/commands/group/removemember.spec.js +138 -0
  37. package/dist/commands/group/removemember.spec.js.map +1 -0
  38. package/dist/commands/groupaccesstoken/createToken.js +6 -2
  39. package/dist/commands/groupaccesstoken/createToken.js.map +1 -1
  40. package/dist/commands/groupaccesstoken/createToken.spec.js +127 -0
  41. package/dist/commands/groupaccesstoken/createToken.spec.js.map +1 -0
  42. package/dist/commands/groupaccesstoken/deleteToken.js.map +1 -1
  43. package/dist/commands/groupaccesstoken/deleteToken.spec.js +103 -0
  44. package/dist/commands/groupaccesstoken/deleteToken.spec.js.map +1 -0
  45. package/dist/commands/groupaccesstoken/groupContainer.js.map +1 -1
  46. package/dist/commands/groupaccesstoken/listTokens.js.map +1 -1
  47. package/dist/commands/groupaccesstoken/listTokens.spec.js +115 -0
  48. package/dist/commands/groupaccesstoken/listTokens.spec.js.map +1 -0
  49. package/dist/commands/list.js +10 -3
  50. package/dist/commands/list.js.map +1 -1
  51. package/dist/commands/misc/login.js +146 -22
  52. package/dist/commands/misc/login.js.map +1 -1
  53. package/dist/commands/misc/login.spec.js +111 -6
  54. package/dist/commands/misc/login.spec.js.map +1 -1
  55. package/dist/commands/misc/logout.spec.js +30 -0
  56. package/dist/commands/misc/logout.spec.js.map +1 -0
  57. package/dist/commands/misc/loopbackOAuth.js +110 -0
  58. package/dist/commands/misc/loopbackOAuth.js.map +1 -0
  59. package/dist/commands/misc/set-access-token.js.map +1 -1
  60. package/dist/commands/misc/set-access-token.spec.js +65 -0
  61. package/dist/commands/misc/set-access-token.spec.js.map +1 -0
  62. package/dist/commands/package/deletepackage.spec.js +136 -0
  63. package/dist/commands/package/deletepackage.spec.js.map +1 -0
  64. package/dist/commands/package/listpackages.js +10 -5
  65. package/dist/commands/package/listpackages.js.map +1 -1
  66. package/dist/commands/package/listpackages.spec.js +129 -0
  67. package/dist/commands/package/listpackages.spec.js.map +1 -0
  68. package/dist/commands/package/publish.js +23 -0
  69. package/dist/commands/package/publish.js.map +1 -1
  70. package/dist/commands/package/publish.spec.js +511 -0
  71. package/dist/commands/package/publish.spec.js.map +1 -0
  72. package/dist/commands/package/updatepackage.spec.js +50 -0
  73. package/dist/commands/package/updatepackage.spec.js.map +1 -1
  74. package/dist/commands/project/createproject.js +11 -1
  75. package/dist/commands/project/createproject.js.map +1 -1
  76. package/dist/commands/project/createproject.spec.js +154 -0
  77. package/dist/commands/project/createproject.spec.js.map +1 -0
  78. package/dist/commands/project/deleteproject.spec.js +106 -0
  79. package/dist/commands/project/deleteproject.spec.js.map +1 -0
  80. package/dist/commands/project/getproject.spec.js +99 -0
  81. package/dist/commands/project/getproject.spec.js.map +1 -0
  82. package/dist/commands/project/listprojects.js +13 -7
  83. package/dist/commands/project/listprojects.js.map +1 -1
  84. package/dist/commands/project/listprojects.spec.js +111 -0
  85. package/dist/commands/project/listprojects.spec.js.map +1 -0
  86. package/dist/commands/project/setproject.spec.js +58 -0
  87. package/dist/commands/project/setproject.spec.js.map +1 -0
  88. package/dist/commands/project/updateproject.js +68 -0
  89. package/dist/commands/project/updateproject.js.map +1 -0
  90. package/dist/commands/project/updateproject.spec.js +129 -0
  91. package/dist/commands/project/updateproject.spec.js.map +1 -0
  92. package/dist/commands/rm.js.map +1 -1
  93. package/dist/commands/update.js +13 -0
  94. package/dist/commands/update.js.map +1 -1
  95. package/dist/commands/version/listversions.spec.js +121 -0
  96. package/dist/commands/version/listversions.spec.js.map +1 -0
  97. package/dist/common/UserGroupId.spec.js +92 -0
  98. package/dist/common/UserGroupId.spec.js.map +1 -0
  99. package/dist/constants.js +49 -13
  100. package/dist/constants.js.map +1 -1
  101. package/dist/index.js +40 -18
  102. package/dist/index.js.map +1 -1
  103. package/dist/logger.spec.js +125 -0
  104. package/dist/logger.spec.js.map +1 -0
  105. package/dist/polyfills/file.polyfill.js.map +1 -1
  106. package/dist/utils.js +59 -0
  107. package/dist/utils.js.map +1 -1
  108. package/dist/utils.spec.js +158 -0
  109. package/dist/utils.spec.js.map +1 -0
  110. package/docker/Dockerfile.ci +11 -3
  111. package/eslint.config.mjs +45 -0
  112. package/generate-client.sh +3 -0
  113. package/package.json +24 -16
  114. package/src/client/.openapi-generator/FILES +1 -0
  115. package/src/client/api.ts +1347 -161
  116. package/src/clientconfiguration.spec.ts +394 -20
  117. package/src/clientconfiguration.ts +74 -15
  118. package/src/commands/add.ts +15 -6
  119. package/src/commands/connection/createconnections.spec.ts +403 -0
  120. package/src/commands/connection/createconnections.ts +30 -5
  121. package/src/commands/connection/deleteconnection.spec.ts +189 -0
  122. package/src/commands/connection/listconnections.spec.ts +132 -0
  123. package/src/commands/connection/listconnections.ts +22 -3
  124. package/src/commands/group/addmember.spec.ts +257 -0
  125. package/src/commands/group/addmember.ts +2 -0
  126. package/src/commands/group/creategroup.spec.ts +146 -0
  127. package/src/commands/group/deletegroup.spec.ts +120 -0
  128. package/src/commands/group/getgroup.spec.ts +129 -0
  129. package/src/commands/group/listgroups.spec.ts +137 -0
  130. package/src/commands/group/removemember.spec.ts +224 -0
  131. package/src/commands/group/removemember.ts +1 -0
  132. package/src/commands/groupaccesstoken/createToken.spec.ts +211 -0
  133. package/src/commands/groupaccesstoken/createToken.ts +55 -51
  134. package/src/commands/groupaccesstoken/deleteToken.spec.ts +147 -0
  135. package/src/commands/groupaccesstoken/deleteToken.ts +16 -11
  136. package/src/commands/groupaccesstoken/groupContainer.ts +51 -51
  137. package/src/commands/groupaccesstoken/listTokens.spec.ts +147 -0
  138. package/src/commands/groupaccesstoken/listTokens.ts +16 -11
  139. package/src/commands/list.ts +50 -9
  140. package/src/commands/misc/login.spec.ts +91 -6
  141. package/src/commands/misc/login.ts +208 -25
  142. package/src/commands/misc/logout.spec.ts +32 -0
  143. package/src/commands/misc/loopbackOAuth.ts +127 -0
  144. package/src/commands/misc/set-access-token.spec.ts +95 -0
  145. package/src/commands/misc/set-access-token.ts +16 -16
  146. package/src/commands/package/deletepackage.spec.ts +164 -0
  147. package/src/commands/package/listpackages.spec.ts +147 -0
  148. package/src/commands/package/listpackages.ts +28 -5
  149. package/src/commands/package/publish.spec.ts +597 -0
  150. package/src/commands/package/publish.ts +32 -0
  151. package/src/commands/package/updatepackage.spec.ts +98 -0
  152. package/src/commands/project/createproject.spec.ts +247 -0
  153. package/src/commands/project/createproject.ts +12 -1
  154. package/src/commands/project/deleteproject.spec.ts +123 -0
  155. package/src/commands/project/getproject.spec.ts +109 -0
  156. package/src/commands/project/listprojects.spec.ts +121 -0
  157. package/src/commands/project/listprojects.ts +33 -7
  158. package/src/commands/project/setproject.spec.ts +63 -0
  159. package/src/commands/project/updateproject.spec.ts +217 -0
  160. package/src/commands/project/updateproject.ts +82 -0
  161. package/src/commands/rm.ts +1 -6
  162. package/src/commands/update.ts +24 -1
  163. package/src/commands/version/listversions.spec.ts +138 -0
  164. package/src/common/UserGroupId.spec.ts +117 -0
  165. package/src/constants.ts +59 -13
  166. package/src/index.ts +46 -20
  167. package/src/logger.spec.ts +158 -0
  168. package/src/polyfills/file.polyfill.ts +1 -0
  169. package/src/utils.spec.ts +135 -0
  170. package/src/utils.ts +81 -0
  171. package/tsconfig.json +15 -18
  172. 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
+ });
@@ -44,6 +44,7 @@ export async function removeMember(
44
44
  } else {
45
45
  logger.error("Error: memberType must be either 'user' or 'group'");
46
46
  process.exit(1);
47
+ return;
47
48
  }
48
49
 
49
50
  const groupMember: GroupMember = {