@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,164 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import sinon from "sinon";
|
|
3
|
+
import { PackagesApi } from "../../client/api";
|
|
4
|
+
import { ClientConfiguration } from "../../clientconfiguration";
|
|
5
|
+
import { logger } from "../../logger";
|
|
6
|
+
import { getConfirmation } from "../../utils";
|
|
7
|
+
import { deletePackage } from "./deletepackage";
|
|
8
|
+
|
|
9
|
+
describe("delete-package", () => {
|
|
10
|
+
let sandbox: sinon.SinonSandbox;
|
|
11
|
+
let deletePackageStub: sinon.SinonStub;
|
|
12
|
+
let loggerStub: sinon.SinonStubbedInstance<typeof logger>;
|
|
13
|
+
let getConfirmationStub: sinon.SinonStub;
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
sandbox = sinon.createSandbox();
|
|
17
|
+
deletePackageStub = 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, "getProject")
|
|
26
|
+
.returns("test-project");
|
|
27
|
+
sandbox
|
|
28
|
+
.stub(ClientConfiguration.prototype, "doesConfigExists")
|
|
29
|
+
.returns(true);
|
|
30
|
+
sandbox
|
|
31
|
+
.stub(ClientConfiguration.prototype, "getHeaders")
|
|
32
|
+
.returns({ Authorization: "Bearer test-token" });
|
|
33
|
+
|
|
34
|
+
sandbox
|
|
35
|
+
.stub(PackagesApi.prototype, "deletePackage")
|
|
36
|
+
.callsFake(deletePackageStub);
|
|
37
|
+
sandbox
|
|
38
|
+
.stub(require("../../utils"), "getConfirmation")
|
|
39
|
+
.callsFake(getConfirmationStub);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
afterEach(() => {
|
|
43
|
+
sandbox.restore();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("should delete package successfully", async () => {
|
|
47
|
+
deletePackageStub.resolves({ status: 200 });
|
|
48
|
+
getConfirmationStub.resolves(true);
|
|
49
|
+
|
|
50
|
+
await deletePackage("http://test-server", "/test-package", false, true);
|
|
51
|
+
|
|
52
|
+
expect(deletePackageStub.calledOnce).to.be.true;
|
|
53
|
+
expect(deletePackageStub.firstCall.args[0]).to.equal("test-org");
|
|
54
|
+
expect(deletePackageStub.firstCall.args[1]).to.equal("test-project");
|
|
55
|
+
expect(deletePackageStub.firstCall.args[2]).to.equal("test-package");
|
|
56
|
+
expect(deletePackageStub.firstCall.args[3]).to.deep.include({
|
|
57
|
+
baseURL: "http://test-server",
|
|
58
|
+
headers: { Authorization: "Bearer test-token" },
|
|
59
|
+
});
|
|
60
|
+
expect(
|
|
61
|
+
loggerStub.info.calledWith(
|
|
62
|
+
sinon.match("Package deleted successfully"),
|
|
63
|
+
),
|
|
64
|
+
).to.be.true;
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("should handle package path without leading slash", async () => {
|
|
68
|
+
deletePackageStub.resolves({ status: 200 });
|
|
69
|
+
getConfirmationStub.resolves(true);
|
|
70
|
+
|
|
71
|
+
await deletePackage("http://test-server", "test-package", false, true);
|
|
72
|
+
|
|
73
|
+
expect(deletePackageStub.firstCall.args[2]).to.equal("test-package");
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("should handle missing config", async () => {
|
|
77
|
+
sandbox.restore();
|
|
78
|
+
sandbox = sinon.createSandbox();
|
|
79
|
+
deletePackageStub = sandbox.stub();
|
|
80
|
+
loggerStub = sandbox.stub(logger);
|
|
81
|
+
getConfirmationStub = sandbox.stub();
|
|
82
|
+
|
|
83
|
+
sandbox
|
|
84
|
+
.stub(ClientConfiguration.prototype, "doesConfigExists")
|
|
85
|
+
.returns(false);
|
|
86
|
+
sandbox
|
|
87
|
+
.stub(PackagesApi.prototype, "deletePackage")
|
|
88
|
+
.callsFake(deletePackageStub);
|
|
89
|
+
sandbox
|
|
90
|
+
.stub(require("../../utils"), "getConfirmation")
|
|
91
|
+
.callsFake(getConfirmationStub);
|
|
92
|
+
|
|
93
|
+
await deletePackage("http://test-server", "/test-package", false, true);
|
|
94
|
+
|
|
95
|
+
expect(deletePackageStub.called).to.be.false;
|
|
96
|
+
expect(
|
|
97
|
+
loggerStub.error.calledWith(
|
|
98
|
+
sinon.match("Please, make sure that you are logged in"),
|
|
99
|
+
),
|
|
100
|
+
).to.be.true;
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("should handle missing project", async () => {
|
|
104
|
+
sandbox.restore();
|
|
105
|
+
sandbox = sinon.createSandbox();
|
|
106
|
+
deletePackageStub = sandbox.stub();
|
|
107
|
+
loggerStub = sandbox.stub(logger);
|
|
108
|
+
getConfirmationStub = sandbox.stub();
|
|
109
|
+
|
|
110
|
+
sandbox
|
|
111
|
+
.stub(ClientConfiguration.prototype, "doesConfigExists")
|
|
112
|
+
.returns(true);
|
|
113
|
+
sandbox.stub(ClientConfiguration.prototype, "getProject").returns("");
|
|
114
|
+
sandbox
|
|
115
|
+
.stub(PackagesApi.prototype, "deletePackage")
|
|
116
|
+
.callsFake(deletePackageStub);
|
|
117
|
+
sandbox
|
|
118
|
+
.stub(require("../../utils"), "getConfirmation")
|
|
119
|
+
.callsFake(getConfirmationStub);
|
|
120
|
+
|
|
121
|
+
await deletePackage("http://test-server", "/test-package", false, true);
|
|
122
|
+
|
|
123
|
+
expect(deletePackageStub.called).to.be.false;
|
|
124
|
+
expect(
|
|
125
|
+
loggerStub.error.calledWith(
|
|
126
|
+
sinon.match("Please, make sure to set a project"),
|
|
127
|
+
),
|
|
128
|
+
).to.be.true;
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("should request confirmation when autoConfirm is false", async () => {
|
|
132
|
+
deletePackageStub.resolves({ status: 200 });
|
|
133
|
+
getConfirmationStub.resolves(true);
|
|
134
|
+
|
|
135
|
+
await deletePackage("http://test-server", "/test-package", false, false);
|
|
136
|
+
|
|
137
|
+
expect(getConfirmationStub.calledOnce).to.be.true;
|
|
138
|
+
expect(deletePackageStub.calledOnce).to.be.true;
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("should cancel when confirmation is denied", async () => {
|
|
142
|
+
getConfirmationStub.resolves(false);
|
|
143
|
+
|
|
144
|
+
await deletePackage("http://test-server", "/test-package", false, false);
|
|
145
|
+
|
|
146
|
+
expect(getConfirmationStub.calledOnce).to.be.true;
|
|
147
|
+
expect(deletePackageStub.called).to.be.false;
|
|
148
|
+
expect(loggerStub.info.calledWith(sinon.match("Operation cancelled."))).to
|
|
149
|
+
.be.true;
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it("should handle API errors", async () => {
|
|
153
|
+
const mockError = new Error("API Error");
|
|
154
|
+
deletePackageStub.rejects(mockError);
|
|
155
|
+
getConfirmationStub.resolves(true);
|
|
156
|
+
|
|
157
|
+
await deletePackage("http://test-server", "/test-package", true, true);
|
|
158
|
+
|
|
159
|
+
expect(deletePackageStub.calledOnce).to.be.true;
|
|
160
|
+
expect(
|
|
161
|
+
loggerStub.error.calledWith(sinon.match("Failed to delete package")),
|
|
162
|
+
).to.be.true;
|
|
163
|
+
});
|
|
164
|
+
});
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import sinon from "sinon";
|
|
3
|
+
import { PackagesApi } from "../../client/api";
|
|
4
|
+
import { ClientConfiguration } from "../../clientconfiguration";
|
|
5
|
+
import { logger } from "../../logger";
|
|
6
|
+
import { prettifyJson } from "../../utils";
|
|
7
|
+
import { listPackages, printOutPackages } from "./listpackages";
|
|
8
|
+
|
|
9
|
+
describe("list-packages", () => {
|
|
10
|
+
let sandbox: sinon.SinonSandbox;
|
|
11
|
+
let listPackagesStub: sinon.SinonStub;
|
|
12
|
+
let loggerStub: sinon.SinonStubbedInstance<typeof logger>;
|
|
13
|
+
let consoleLogStub: sinon.SinonStub;
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
sandbox = sinon.createSandbox();
|
|
17
|
+
listPackagesStub = 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, "getProject")
|
|
26
|
+
.returns("test-project");
|
|
27
|
+
sandbox
|
|
28
|
+
.stub(ClientConfiguration.prototype, "doesConfigExists")
|
|
29
|
+
.returns(true);
|
|
30
|
+
sandbox
|
|
31
|
+
.stub(ClientConfiguration.prototype, "getHeaders")
|
|
32
|
+
.returns({ Authorization: "Bearer test-token" });
|
|
33
|
+
|
|
34
|
+
sandbox
|
|
35
|
+
.stub(PackagesApi.prototype, "listPackages")
|
|
36
|
+
.callsFake(listPackagesStub);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
afterEach(() => {
|
|
40
|
+
sandbox.restore();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("should list packages successfully", async () => {
|
|
44
|
+
const mockPackages = [
|
|
45
|
+
{ name: "package1", latestVersion: "1.0.0" },
|
|
46
|
+
{ name: "package2", latestVersion: "2.0.0" },
|
|
47
|
+
];
|
|
48
|
+
const mockResponse = {
|
|
49
|
+
data: mockPackages,
|
|
50
|
+
headers: {},
|
|
51
|
+
};
|
|
52
|
+
listPackagesStub.resolves(mockResponse);
|
|
53
|
+
|
|
54
|
+
const result = await listPackages("http://test-server", false);
|
|
55
|
+
|
|
56
|
+
expect(listPackagesStub.calledOnce).to.be.true;
|
|
57
|
+
expect(listPackagesStub.firstCall.args[0]).to.equal("test-org");
|
|
58
|
+
expect(listPackagesStub.firstCall.args[1]).to.equal("test-project");
|
|
59
|
+
expect(listPackagesStub.firstCall.args[2]).to.equal(-1); // limit
|
|
60
|
+
expect(listPackagesStub.firstCall.args[3]).to.equal(0); // offset
|
|
61
|
+
expect(listPackagesStub.firstCall.args[4]).to.deep.include({
|
|
62
|
+
baseURL: "http://test-server",
|
|
63
|
+
headers: { Authorization: "Bearer test-token" },
|
|
64
|
+
});
|
|
65
|
+
expect(result).to.deep.equal({
|
|
66
|
+
packages: mockPackages,
|
|
67
|
+
totalCount: undefined,
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("should handle missing config", async () => {
|
|
72
|
+
sandbox.restore();
|
|
73
|
+
sandbox = sinon.createSandbox();
|
|
74
|
+
listPackagesStub = sandbox.stub();
|
|
75
|
+
loggerStub = sandbox.stub(logger);
|
|
76
|
+
consoleLogStub = sandbox.stub(console, "log");
|
|
77
|
+
|
|
78
|
+
sandbox
|
|
79
|
+
.stub(ClientConfiguration.prototype, "doesConfigExists")
|
|
80
|
+
.returns(false);
|
|
81
|
+
sandbox
|
|
82
|
+
.stub(PackagesApi.prototype, "listPackages")
|
|
83
|
+
.callsFake(listPackagesStub);
|
|
84
|
+
|
|
85
|
+
const result = await listPackages("http://test-server", false);
|
|
86
|
+
|
|
87
|
+
expect(listPackagesStub.called).to.be.false;
|
|
88
|
+
expect(result).to.be.undefined;
|
|
89
|
+
expect(
|
|
90
|
+
loggerStub.error.calledWith(
|
|
91
|
+
sinon.match("Please, make sure that you are logged in"),
|
|
92
|
+
),
|
|
93
|
+
).to.be.true;
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("should handle missing project", async () => {
|
|
97
|
+
sandbox.restore();
|
|
98
|
+
sandbox = sinon.createSandbox();
|
|
99
|
+
listPackagesStub = sandbox.stub();
|
|
100
|
+
loggerStub = sandbox.stub(logger);
|
|
101
|
+
consoleLogStub = sandbox.stub(console, "log");
|
|
102
|
+
|
|
103
|
+
sandbox
|
|
104
|
+
.stub(ClientConfiguration.prototype, "doesConfigExists")
|
|
105
|
+
.returns(true);
|
|
106
|
+
sandbox.stub(ClientConfiguration.prototype, "getProject").returns("");
|
|
107
|
+
sandbox
|
|
108
|
+
.stub(PackagesApi.prototype, "listPackages")
|
|
109
|
+
.callsFake(listPackagesStub);
|
|
110
|
+
|
|
111
|
+
const result = await listPackages("http://test-server", false);
|
|
112
|
+
|
|
113
|
+
expect(listPackagesStub.called).to.be.false;
|
|
114
|
+
expect(result).to.be.undefined;
|
|
115
|
+
expect(
|
|
116
|
+
loggerStub.error.calledWith(
|
|
117
|
+
sinon.match("Please, make sure to set a project"),
|
|
118
|
+
),
|
|
119
|
+
).to.be.true;
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("should handle API errors", async () => {
|
|
123
|
+
const mockError = new Error("API Error");
|
|
124
|
+
listPackagesStub.rejects(mockError);
|
|
125
|
+
|
|
126
|
+
const result = await listPackages("http://test-server", true);
|
|
127
|
+
|
|
128
|
+
expect(listPackagesStub.calledOnce).to.be.true;
|
|
129
|
+
expect(result).to.be.undefined;
|
|
130
|
+
expect(
|
|
131
|
+
loggerStub.error.calledWith(sinon.match("Failed to list packages")),
|
|
132
|
+
).to.be.true;
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it("should print packages when using printOutPackages", async () => {
|
|
136
|
+
const mockPackages = [{ name: "package1" }];
|
|
137
|
+
const mockResponse = {
|
|
138
|
+
data: mockPackages,
|
|
139
|
+
headers: {},
|
|
140
|
+
};
|
|
141
|
+
listPackagesStub.resolves(mockResponse);
|
|
142
|
+
|
|
143
|
+
await printOutPackages("http://test-server", false);
|
|
144
|
+
|
|
145
|
+
expect(consoleLogStub.called).to.be.true;
|
|
146
|
+
});
|
|
147
|
+
});
|
|
@@ -2,11 +2,21 @@ import { PackagesApi } from "../../client/api";
|
|
|
2
2
|
import { Configuration } from "../../client/configuration";
|
|
3
3
|
import { ClientConfiguration } from "../../clientconfiguration";
|
|
4
4
|
import { logger } from "../../logger";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
prettifyJson,
|
|
7
|
+
printOutError,
|
|
8
|
+
parsePaginationParams,
|
|
9
|
+
extractTotalCount,
|
|
10
|
+
} from "../../utils";
|
|
6
11
|
|
|
7
12
|
const packagesApi = new PackagesApi(new Configuration());
|
|
8
13
|
|
|
9
|
-
export async function listPackages(
|
|
14
|
+
export async function listPackages(
|
|
15
|
+
controlPlane: string,
|
|
16
|
+
debug: boolean,
|
|
17
|
+
page?: string | number,
|
|
18
|
+
pageSize?: string | number,
|
|
19
|
+
) {
|
|
10
20
|
const clientConfig = new ClientConfiguration();
|
|
11
21
|
const organizationName = clientConfig.getOrganization();
|
|
12
22
|
const projectName = clientConfig.getProject();
|
|
@@ -22,23 +32,36 @@ export async function listPackages(controlPlane: string, debug: boolean) {
|
|
|
22
32
|
}
|
|
23
33
|
|
|
24
34
|
try {
|
|
35
|
+
const { limit, offset } = parsePaginationParams(page, pageSize);
|
|
25
36
|
const response = await packagesApi.listPackages(
|
|
26
37
|
organizationName,
|
|
27
38
|
projectName,
|
|
39
|
+
limit,
|
|
40
|
+
offset,
|
|
28
41
|
{
|
|
29
42
|
baseURL: controlPlane,
|
|
30
43
|
headers: clientConfig.getHeaders(),
|
|
31
44
|
},
|
|
32
45
|
);
|
|
33
46
|
|
|
34
|
-
|
|
47
|
+
const totalCount = extractTotalCount(response.headers);
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
packages: response.data,
|
|
51
|
+
totalCount,
|
|
52
|
+
};
|
|
35
53
|
} catch (e) {
|
|
36
54
|
logger.error("Failed to list packages");
|
|
37
55
|
printOutError(e, debug);
|
|
38
56
|
}
|
|
39
57
|
}
|
|
40
58
|
|
|
41
|
-
export async function printOutPackages(
|
|
42
|
-
|
|
59
|
+
export async function printOutPackages(
|
|
60
|
+
controlPlane: string,
|
|
61
|
+
debug: boolean,
|
|
62
|
+
page?: string | number,
|
|
63
|
+
pageSize?: string | number,
|
|
64
|
+
) {
|
|
65
|
+
const packages = await listPackages(controlPlane, debug, page, pageSize);
|
|
43
66
|
console.log(prettifyJson(packages));
|
|
44
67
|
}
|