@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
|
@@ -218,4 +218,102 @@ describe("set-replication-count", () => {
|
|
|
218
218
|
});
|
|
219
219
|
});
|
|
220
220
|
});
|
|
221
|
+
|
|
222
|
+
describe("updatePackage params", () => {
|
|
223
|
+
it("should pass latestVersion when provided", async () => {
|
|
224
|
+
const mockResponse = { status: 200 };
|
|
225
|
+
updatePackageStub.resolves(mockResponse);
|
|
226
|
+
|
|
227
|
+
await updatePackage(
|
|
228
|
+
"http://test-server",
|
|
229
|
+
"test-package",
|
|
230
|
+
{ latestVersion: "2.0.0" },
|
|
231
|
+
false,
|
|
232
|
+
true,
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
expect(updatePackageStub.calledOnce).to.be.true;
|
|
236
|
+
expect(updatePackageStub.firstCall.args[3]).to.deep.include({
|
|
237
|
+
latestVersion: "2.0.0",
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it("should pass description when provided", async () => {
|
|
242
|
+
const mockResponse = { status: 200 };
|
|
243
|
+
updatePackageStub.resolves(mockResponse);
|
|
244
|
+
|
|
245
|
+
await updatePackage(
|
|
246
|
+
"http://test-server",
|
|
247
|
+
"test-package",
|
|
248
|
+
{ description: "Updated description" },
|
|
249
|
+
false,
|
|
250
|
+
true,
|
|
251
|
+
);
|
|
252
|
+
|
|
253
|
+
expect(updatePackageStub.calledOnce).to.be.true;
|
|
254
|
+
expect(updatePackageStub.firstCall.args[3]).to.deep.include({
|
|
255
|
+
description: "Updated description",
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it("should reject invalid package path with multiple segments", async () => {
|
|
260
|
+
await updatePackage(
|
|
261
|
+
"http://test-server",
|
|
262
|
+
"foo/bar",
|
|
263
|
+
{ replicationCount: 3 },
|
|
264
|
+
false,
|
|
265
|
+
true,
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
expect(updatePackageStub.called).to.be.false;
|
|
269
|
+
expect(
|
|
270
|
+
loggerStub.error.calledWith(sinon.match("Invalid package path")),
|
|
271
|
+
).to.be.true;
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
describe("confirmation flow", () => {
|
|
276
|
+
let getConfirmationStub: sinon.SinonStub;
|
|
277
|
+
|
|
278
|
+
beforeEach(() => {
|
|
279
|
+
getConfirmationStub = sandbox.stub();
|
|
280
|
+
sandbox
|
|
281
|
+
.stub(require("../../utils"), "getConfirmation")
|
|
282
|
+
.callsFake(getConfirmationStub);
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it("should request confirmation when autoConfirm is false", async () => {
|
|
286
|
+
const mockResponse = { status: 200 };
|
|
287
|
+
updatePackageStub.resolves(mockResponse);
|
|
288
|
+
getConfirmationStub.resolves(true);
|
|
289
|
+
|
|
290
|
+
await updatePackage(
|
|
291
|
+
"http://test-server",
|
|
292
|
+
"test-package",
|
|
293
|
+
{ replicationCount: 3 },
|
|
294
|
+
false,
|
|
295
|
+
false,
|
|
296
|
+
);
|
|
297
|
+
|
|
298
|
+
expect(getConfirmationStub.calledOnce).to.be.true;
|
|
299
|
+
expect(updatePackageStub.calledOnce).to.be.true;
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
it("should cancel when confirmation is denied", async () => {
|
|
303
|
+
getConfirmationStub.resolves(false);
|
|
304
|
+
|
|
305
|
+
await updatePackage(
|
|
306
|
+
"http://test-server",
|
|
307
|
+
"test-package",
|
|
308
|
+
{ replicationCount: 3 },
|
|
309
|
+
false,
|
|
310
|
+
false,
|
|
311
|
+
);
|
|
312
|
+
|
|
313
|
+
expect(getConfirmationStub.calledOnce).to.be.true;
|
|
314
|
+
expect(updatePackageStub.called).to.be.false;
|
|
315
|
+
expect(loggerStub.info.calledWith(sinon.match("Operation cancelled.")))
|
|
316
|
+
.to.be.true;
|
|
317
|
+
});
|
|
318
|
+
});
|
|
221
319
|
});
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import sinon from "sinon";
|
|
4
|
+
import { ProjectsApi } from "../../client/api";
|
|
5
|
+
import { ClientConfiguration } from "../../clientconfiguration";
|
|
6
|
+
import { logger } from "../../logger";
|
|
7
|
+
import { getConfirmation } from "../../utils";
|
|
8
|
+
import { createProject } from "./createproject";
|
|
9
|
+
|
|
10
|
+
describe("create-project", () => {
|
|
11
|
+
let sandbox: sinon.SinonSandbox;
|
|
12
|
+
let createProjectStub: sinon.SinonStub;
|
|
13
|
+
let loggerStub: sinon.SinonStubbedInstance<typeof logger>;
|
|
14
|
+
let consoleLogStub: sinon.SinonStub;
|
|
15
|
+
let getConfirmationStub: sinon.SinonStub;
|
|
16
|
+
let readFileSyncStub: sinon.SinonStub;
|
|
17
|
+
let setProjectStub: sinon.SinonStub;
|
|
18
|
+
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
sandbox = sinon.createSandbox();
|
|
21
|
+
createProjectStub = sandbox.stub();
|
|
22
|
+
loggerStub = sandbox.stub(logger);
|
|
23
|
+
consoleLogStub = sandbox.stub(console, "log");
|
|
24
|
+
getConfirmationStub = sandbox.stub();
|
|
25
|
+
readFileSyncStub = sandbox.stub(fs, "readFileSync");
|
|
26
|
+
setProjectStub = sandbox.stub(
|
|
27
|
+
ClientConfiguration.prototype,
|
|
28
|
+
"setProject",
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
sandbox
|
|
32
|
+
.stub(ClientConfiguration.prototype, "getOrganization")
|
|
33
|
+
.returns("test-org");
|
|
34
|
+
sandbox
|
|
35
|
+
.stub(ClientConfiguration.prototype, "doesConfigExists")
|
|
36
|
+
.returns(true);
|
|
37
|
+
sandbox
|
|
38
|
+
.stub(ClientConfiguration.prototype, "getAuthenticationHeader")
|
|
39
|
+
.returns("Bearer test-token");
|
|
40
|
+
|
|
41
|
+
sandbox
|
|
42
|
+
.stub(ProjectsApi.prototype, "createProject")
|
|
43
|
+
.callsFake(createProjectStub);
|
|
44
|
+
sandbox
|
|
45
|
+
.stub(require("../../utils"), "getConfirmation")
|
|
46
|
+
.callsFake(getConfirmationStub);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
afterEach(() => {
|
|
50
|
+
sandbox.restore();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("should create project successfully", async () => {
|
|
54
|
+
const mockResponse = {
|
|
55
|
+
data: { name: "test-project", replicationCount: 2 },
|
|
56
|
+
};
|
|
57
|
+
createProjectStub.resolves(mockResponse);
|
|
58
|
+
getConfirmationStub.resolves(true);
|
|
59
|
+
|
|
60
|
+
await createProject(
|
|
61
|
+
"http://test-server",
|
|
62
|
+
"test-project",
|
|
63
|
+
"",
|
|
64
|
+
undefined,
|
|
65
|
+
false,
|
|
66
|
+
true,
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
expect(createProjectStub.calledOnce).to.be.true;
|
|
70
|
+
expect(createProjectStub.firstCall.args[0]).to.equal("test-org");
|
|
71
|
+
expect(createProjectStub.firstCall.args[1]).to.deep.include({
|
|
72
|
+
name: "test-project",
|
|
73
|
+
readme: "",
|
|
74
|
+
});
|
|
75
|
+
expect(setProjectStub.calledWith("test-project")).to.be.true;
|
|
76
|
+
expect(
|
|
77
|
+
loggerStub.info.calledWith(
|
|
78
|
+
sinon.match("Project created successfully"),
|
|
79
|
+
),
|
|
80
|
+
).to.be.true;
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("should create project with readme file", async () => {
|
|
84
|
+
const mockResponse = {
|
|
85
|
+
data: { name: "test-project" },
|
|
86
|
+
};
|
|
87
|
+
createProjectStub.resolves(mockResponse);
|
|
88
|
+
getConfirmationStub.resolves(true);
|
|
89
|
+
readFileSyncStub.returns("README content");
|
|
90
|
+
|
|
91
|
+
await createProject(
|
|
92
|
+
"http://test-server",
|
|
93
|
+
"test-project",
|
|
94
|
+
"/path/to/readme.md",
|
|
95
|
+
undefined,
|
|
96
|
+
false,
|
|
97
|
+
true,
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
expect(readFileSyncStub.calledWith("/path/to/readme.md")).to.be.true;
|
|
101
|
+
expect(createProjectStub.firstCall.args[1]).to.deep.include({
|
|
102
|
+
name: "test-project",
|
|
103
|
+
readme: "README content",
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("should create project with replication count", async () => {
|
|
108
|
+
const mockResponse = {
|
|
109
|
+
data: { name: "test-project", replicationCount: 5 },
|
|
110
|
+
};
|
|
111
|
+
createProjectStub.resolves(mockResponse);
|
|
112
|
+
getConfirmationStub.resolves(true);
|
|
113
|
+
|
|
114
|
+
await createProject(
|
|
115
|
+
"http://test-server",
|
|
116
|
+
"test-project",
|
|
117
|
+
"",
|
|
118
|
+
5,
|
|
119
|
+
false,
|
|
120
|
+
true,
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
expect(createProjectStub.firstCall.args[1]).to.deep.include({
|
|
124
|
+
name: "test-project",
|
|
125
|
+
replicationCount: 5,
|
|
126
|
+
});
|
|
127
|
+
expect(
|
|
128
|
+
loggerStub.info.calledWith(sinon.match("Replication count set to 5")),
|
|
129
|
+
).to.be.true;
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it("should handle missing config", async () => {
|
|
133
|
+
sandbox.restore();
|
|
134
|
+
sandbox = sinon.createSandbox();
|
|
135
|
+
createProjectStub = sandbox.stub();
|
|
136
|
+
loggerStub = sandbox.stub(logger);
|
|
137
|
+
consoleLogStub = sandbox.stub(console, "log");
|
|
138
|
+
getConfirmationStub = sandbox.stub();
|
|
139
|
+
readFileSyncStub = sandbox.stub(fs, "readFileSync");
|
|
140
|
+
setProjectStub = sandbox.stub(
|
|
141
|
+
ClientConfiguration.prototype,
|
|
142
|
+
"setProject",
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
sandbox
|
|
146
|
+
.stub(ClientConfiguration.prototype, "doesConfigExists")
|
|
147
|
+
.returns(false);
|
|
148
|
+
sandbox
|
|
149
|
+
.stub(ProjectsApi.prototype, "createProject")
|
|
150
|
+
.callsFake(createProjectStub);
|
|
151
|
+
sandbox
|
|
152
|
+
.stub(require("../../utils"), "getConfirmation")
|
|
153
|
+
.callsFake(getConfirmationStub);
|
|
154
|
+
|
|
155
|
+
await createProject(
|
|
156
|
+
"http://test-server",
|
|
157
|
+
"test-project",
|
|
158
|
+
"",
|
|
159
|
+
undefined,
|
|
160
|
+
false,
|
|
161
|
+
true,
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
expect(createProjectStub.called).to.be.false;
|
|
165
|
+
expect(
|
|
166
|
+
loggerStub.error.calledWith(
|
|
167
|
+
sinon.match("Please, make sure that you are logged in"),
|
|
168
|
+
),
|
|
169
|
+
).to.be.true;
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("should reject replication count less than 1", async () => {
|
|
173
|
+
await createProject(
|
|
174
|
+
"http://test-server",
|
|
175
|
+
"test-project",
|
|
176
|
+
"",
|
|
177
|
+
0,
|
|
178
|
+
false,
|
|
179
|
+
true,
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
expect(createProjectStub.called).to.be.false;
|
|
183
|
+
expect(
|
|
184
|
+
loggerStub.error.calledWith(
|
|
185
|
+
sinon.match("Replication count must be at least 1"),
|
|
186
|
+
),
|
|
187
|
+
).to.be.true;
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it("should request confirmation when autoConfirm is false", async () => {
|
|
191
|
+
const mockResponse = {
|
|
192
|
+
data: { name: "test-project" },
|
|
193
|
+
};
|
|
194
|
+
createProjectStub.resolves(mockResponse);
|
|
195
|
+
getConfirmationStub.resolves(true);
|
|
196
|
+
|
|
197
|
+
await createProject(
|
|
198
|
+
"http://test-server",
|
|
199
|
+
"test-project",
|
|
200
|
+
"",
|
|
201
|
+
undefined,
|
|
202
|
+
false,
|
|
203
|
+
false,
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
expect(getConfirmationStub.calledOnce).to.be.true;
|
|
207
|
+
expect(createProjectStub.calledOnce).to.be.true;
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it("should cancel when confirmation is denied", async () => {
|
|
211
|
+
getConfirmationStub.resolves(false);
|
|
212
|
+
|
|
213
|
+
await createProject(
|
|
214
|
+
"http://test-server",
|
|
215
|
+
"test-project",
|
|
216
|
+
"",
|
|
217
|
+
undefined,
|
|
218
|
+
false,
|
|
219
|
+
false,
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
expect(getConfirmationStub.calledOnce).to.be.true;
|
|
223
|
+
expect(createProjectStub.called).to.be.false;
|
|
224
|
+
expect(loggerStub.info.calledWith(sinon.match("Operation cancelled."))).to
|
|
225
|
+
.be.true;
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it("should handle API errors", async () => {
|
|
229
|
+
const mockError = new Error("API Error");
|
|
230
|
+
createProjectStub.rejects(mockError);
|
|
231
|
+
getConfirmationStub.resolves(true);
|
|
232
|
+
|
|
233
|
+
await createProject(
|
|
234
|
+
"http://test-server",
|
|
235
|
+
"test-project",
|
|
236
|
+
"",
|
|
237
|
+
undefined,
|
|
238
|
+
true,
|
|
239
|
+
true,
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
expect(createProjectStub.calledOnce).to.be.true;
|
|
243
|
+
expect(
|
|
244
|
+
loggerStub.error.calledWith(sinon.match("Failed to create project")),
|
|
245
|
+
).to.be.true;
|
|
246
|
+
});
|
|
247
|
+
});
|
|
@@ -11,6 +11,7 @@ export async function createProject(
|
|
|
11
11
|
controlPlane: string,
|
|
12
12
|
projectName: string,
|
|
13
13
|
readmeFile: string,
|
|
14
|
+
replicationCount: number | undefined,
|
|
14
15
|
debug: boolean,
|
|
15
16
|
autoConfirm: boolean,
|
|
16
17
|
) {
|
|
@@ -20,6 +21,10 @@ export async function createProject(
|
|
|
20
21
|
logger.error("Please, make sure that you are logged in");
|
|
21
22
|
return;
|
|
22
23
|
}
|
|
24
|
+
if (replicationCount !== undefined && replicationCount < 1) {
|
|
25
|
+
logger.error("Replication count must be at least 1");
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
23
28
|
if (!autoConfirm) {
|
|
24
29
|
const confirmation = await getConfirmation(
|
|
25
30
|
`Are you sure you that want to create a project named ${projectName}?`,
|
|
@@ -38,6 +43,9 @@ export async function createProject(
|
|
|
38
43
|
|
|
39
44
|
try {
|
|
40
45
|
const project: Project = { name: projectName, readme: readmeContents };
|
|
46
|
+
if (replicationCount !== undefined) {
|
|
47
|
+
project.replicationCount = replicationCount;
|
|
48
|
+
}
|
|
41
49
|
await projectsApi
|
|
42
50
|
.createProject(clientConfig.getOrganization(), project, {
|
|
43
51
|
baseURL: controlPlane,
|
|
@@ -50,10 +58,13 @@ export async function createProject(
|
|
|
50
58
|
console.log(jsonString);
|
|
51
59
|
// Make the new project the default project.
|
|
52
60
|
clientConfig.setProject(projectName);
|
|
61
|
+
if (replicationCount !== undefined) {
|
|
62
|
+
logger.info(`Replication count set to ${replicationCount}`);
|
|
63
|
+
}
|
|
53
64
|
});
|
|
54
65
|
logger.info("Project created successfully");
|
|
55
66
|
} catch (e) {
|
|
56
67
|
logger.error("Failed to create project");
|
|
57
68
|
printOutError(e, debug);
|
|
58
69
|
}
|
|
59
|
-
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import sinon from "sinon";
|
|
3
|
+
import { ProjectsApi } from "../../client/api";
|
|
4
|
+
import { ClientConfiguration } from "../../clientconfiguration";
|
|
5
|
+
import { logger } from "../../logger";
|
|
6
|
+
import { getConfirmation } from "../../utils";
|
|
7
|
+
import { deleteProject } from "./deleteproject";
|
|
8
|
+
|
|
9
|
+
describe("delete-project", () => {
|
|
10
|
+
let sandbox: sinon.SinonSandbox;
|
|
11
|
+
let deleteProjectStub: sinon.SinonStub;
|
|
12
|
+
let loggerStub: sinon.SinonStubbedInstance<typeof logger>;
|
|
13
|
+
let getConfirmationStub: sinon.SinonStub;
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
sandbox = sinon.createSandbox();
|
|
17
|
+
deleteProjectStub = sandbox.stub();
|
|
18
|
+
loggerStub = sandbox.stub(logger);
|
|
19
|
+
getConfirmationStub = sandbox.stub();
|
|
20
|
+
|
|
21
|
+
sandbox
|
|
22
|
+
.stub(ClientConfiguration.prototype, "getOrganization")
|
|
23
|
+
.returns("test-org");
|
|
24
|
+
sandbox
|
|
25
|
+
.stub(ClientConfiguration.prototype, "doesConfigExists")
|
|
26
|
+
.returns(true);
|
|
27
|
+
sandbox
|
|
28
|
+
.stub(ClientConfiguration.prototype, "getAuthenticationHeader")
|
|
29
|
+
.returns("Bearer test-token");
|
|
30
|
+
|
|
31
|
+
sandbox
|
|
32
|
+
.stub(ProjectsApi.prototype, "deleteProject")
|
|
33
|
+
.callsFake(deleteProjectStub);
|
|
34
|
+
sandbox
|
|
35
|
+
.stub(require("../../utils"), "getConfirmation")
|
|
36
|
+
.callsFake(getConfirmationStub);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
afterEach(() => {
|
|
40
|
+
sandbox.restore();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("should delete project successfully", async () => {
|
|
44
|
+
deleteProjectStub.resolves({ status: 200 });
|
|
45
|
+
getConfirmationStub.resolves(true);
|
|
46
|
+
|
|
47
|
+
await deleteProject("http://test-server", "test-project", false, true);
|
|
48
|
+
|
|
49
|
+
expect(deleteProjectStub.calledOnce).to.be.true;
|
|
50
|
+
expect(deleteProjectStub.firstCall.args[0]).to.equal("test-org");
|
|
51
|
+
expect(deleteProjectStub.firstCall.args[1]).to.equal("test-project");
|
|
52
|
+
expect(deleteProjectStub.firstCall.args[2]).to.deep.include({
|
|
53
|
+
baseURL: "http://test-server",
|
|
54
|
+
headers: { Authorization: "Bearer test-token" },
|
|
55
|
+
});
|
|
56
|
+
expect(
|
|
57
|
+
loggerStub.info.calledWith(
|
|
58
|
+
sinon.match("Project deleted successfully"),
|
|
59
|
+
),
|
|
60
|
+
).to.be.true;
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("should handle missing config", async () => {
|
|
64
|
+
sandbox.restore();
|
|
65
|
+
sandbox = sinon.createSandbox();
|
|
66
|
+
deleteProjectStub = sandbox.stub();
|
|
67
|
+
loggerStub = sandbox.stub(logger);
|
|
68
|
+
getConfirmationStub = sandbox.stub();
|
|
69
|
+
|
|
70
|
+
sandbox
|
|
71
|
+
.stub(ClientConfiguration.prototype, "doesConfigExists")
|
|
72
|
+
.returns(false);
|
|
73
|
+
sandbox
|
|
74
|
+
.stub(ProjectsApi.prototype, "deleteProject")
|
|
75
|
+
.callsFake(deleteProjectStub);
|
|
76
|
+
sandbox
|
|
77
|
+
.stub(require("../../utils"), "getConfirmation")
|
|
78
|
+
.callsFake(getConfirmationStub);
|
|
79
|
+
|
|
80
|
+
await deleteProject("http://test-server", "test-project", false, true);
|
|
81
|
+
|
|
82
|
+
expect(deleteProjectStub.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 request confirmation when autoConfirm is false", async () => {
|
|
91
|
+
deleteProjectStub.resolves({ status: 200 });
|
|
92
|
+
getConfirmationStub.resolves(true);
|
|
93
|
+
|
|
94
|
+
await deleteProject("http://test-server", "test-project", false, false);
|
|
95
|
+
|
|
96
|
+
expect(getConfirmationStub.calledOnce).to.be.true;
|
|
97
|
+
expect(deleteProjectStub.calledOnce).to.be.true;
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("should cancel when confirmation is denied", async () => {
|
|
101
|
+
getConfirmationStub.resolves(false);
|
|
102
|
+
|
|
103
|
+
await deleteProject("http://test-server", "test-project", false, false);
|
|
104
|
+
|
|
105
|
+
expect(getConfirmationStub.calledOnce).to.be.true;
|
|
106
|
+
expect(deleteProjectStub.called).to.be.false;
|
|
107
|
+
expect(loggerStub.info.calledWith(sinon.match("Operation cancelled."))).to
|
|
108
|
+
.be.true;
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("should handle API errors", async () => {
|
|
112
|
+
const mockError = new Error("API Error");
|
|
113
|
+
deleteProjectStub.rejects(mockError);
|
|
114
|
+
getConfirmationStub.resolves(true);
|
|
115
|
+
|
|
116
|
+
await deleteProject("http://test-server", "test-project", true, true);
|
|
117
|
+
|
|
118
|
+
expect(deleteProjectStub.calledOnce).to.be.true;
|
|
119
|
+
expect(
|
|
120
|
+
loggerStub.error.calledWith(sinon.match("Failed to delete project")),
|
|
121
|
+
).to.be.true;
|
|
122
|
+
});
|
|
123
|
+
});
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import sinon from "sinon";
|
|
3
|
+
import { ProjectsApi } from "../../client/api";
|
|
4
|
+
import { ClientConfiguration } from "../../clientconfiguration";
|
|
5
|
+
import { logger } from "../../logger";
|
|
6
|
+
import { prettifyJson } from "../../utils";
|
|
7
|
+
import { getProject } from "./getproject";
|
|
8
|
+
|
|
9
|
+
describe("get-project", () => {
|
|
10
|
+
let sandbox: sinon.SinonSandbox;
|
|
11
|
+
let getProjectStub: sinon.SinonStub;
|
|
12
|
+
let loggerStub: sinon.SinonStubbedInstance<typeof logger>;
|
|
13
|
+
let consoleLogStub: sinon.SinonStub;
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
sandbox = sinon.createSandbox();
|
|
17
|
+
getProjectStub = sandbox.stub();
|
|
18
|
+
loggerStub = sandbox.stub(logger);
|
|
19
|
+
consoleLogStub = sandbox.stub(console, "log");
|
|
20
|
+
|
|
21
|
+
sandbox
|
|
22
|
+
.stub(ClientConfiguration.prototype, "getOrganization")
|
|
23
|
+
.returns("test-org");
|
|
24
|
+
sandbox
|
|
25
|
+
.stub(ClientConfiguration.prototype, "doesConfigExists")
|
|
26
|
+
.returns(true);
|
|
27
|
+
sandbox
|
|
28
|
+
.stub(ClientConfiguration.prototype, "getHeaders")
|
|
29
|
+
.returns({ Authorization: "Bearer test-token" });
|
|
30
|
+
|
|
31
|
+
sandbox
|
|
32
|
+
.stub(ProjectsApi.prototype, "getProject")
|
|
33
|
+
.callsFake(getProjectStub);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
afterEach(() => {
|
|
37
|
+
sandbox.restore();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("should get project successfully", async () => {
|
|
41
|
+
const mockProjectData = {
|
|
42
|
+
name: "test-project",
|
|
43
|
+
replicationCount: 3,
|
|
44
|
+
};
|
|
45
|
+
const mockResponse = {
|
|
46
|
+
data: mockProjectData,
|
|
47
|
+
};
|
|
48
|
+
getProjectStub.resolves(mockResponse);
|
|
49
|
+
|
|
50
|
+
await getProject("http://test-server", "test-project", false);
|
|
51
|
+
|
|
52
|
+
expect(getProjectStub.calledOnce).to.be.true;
|
|
53
|
+
expect(getProjectStub.firstCall.args[0]).to.equal("test-org");
|
|
54
|
+
expect(getProjectStub.firstCall.args[1]).to.equal("test-project");
|
|
55
|
+
expect(getProjectStub.firstCall.args[2]).to.equal(false);
|
|
56
|
+
expect(getProjectStub.firstCall.args[3]).to.deep.include({
|
|
57
|
+
baseURL: "http://test-server",
|
|
58
|
+
headers: { Authorization: "Bearer test-token" },
|
|
59
|
+
});
|
|
60
|
+
expect(consoleLogStub.calledWith(prettifyJson(mockProjectData))).to.be
|
|
61
|
+
.true;
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("should handle missing config", async () => {
|
|
65
|
+
sandbox.restore();
|
|
66
|
+
sandbox = sinon.createSandbox();
|
|
67
|
+
getProjectStub = sandbox.stub();
|
|
68
|
+
loggerStub = sandbox.stub(logger);
|
|
69
|
+
consoleLogStub = sandbox.stub(console, "log");
|
|
70
|
+
|
|
71
|
+
sandbox
|
|
72
|
+
.stub(ClientConfiguration.prototype, "doesConfigExists")
|
|
73
|
+
.returns(false);
|
|
74
|
+
sandbox
|
|
75
|
+
.stub(ProjectsApi.prototype, "getProject")
|
|
76
|
+
.callsFake(getProjectStub);
|
|
77
|
+
|
|
78
|
+
await getProject("http://test-server", "test-project", false);
|
|
79
|
+
|
|
80
|
+
expect(getProjectStub.called).to.be.false;
|
|
81
|
+
expect(
|
|
82
|
+
loggerStub.error.calledWith(
|
|
83
|
+
sinon.match("Please, make sure that you are logged in"),
|
|
84
|
+
),
|
|
85
|
+
).to.be.true;
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("should handle missing project name", async () => {
|
|
89
|
+
await getProject("http://test-server", "", false);
|
|
90
|
+
|
|
91
|
+
expect(getProjectStub.called).to.be.false;
|
|
92
|
+
expect(
|
|
93
|
+
loggerStub.error.calledWith(
|
|
94
|
+
sinon.match("Please, make sure to provide a project name"),
|
|
95
|
+
),
|
|
96
|
+
).to.be.true;
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("should handle API errors", async () => {
|
|
100
|
+
const mockError = new Error("API Error");
|
|
101
|
+
getProjectStub.rejects(mockError);
|
|
102
|
+
|
|
103
|
+
await getProject("http://test-server", "test-project", true);
|
|
104
|
+
|
|
105
|
+
expect(getProjectStub.calledOnce).to.be.true;
|
|
106
|
+
expect(loggerStub.error.calledWith(sinon.match("Failed to get project")))
|
|
107
|
+
.to.be.true;
|
|
108
|
+
});
|
|
109
|
+
});
|