@credibledata/cred-cli 0.1.3 → 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 +804 -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 +5 -0
- package/package.json +24 -16
- package/src/client/.openapi-generator/FILES +1 -0
- package/src/client/api.ts +1999 -696
- 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,403 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import sinon from "sinon";
|
|
4
|
+
import { ConnectionsApi } from "../../client/api";
|
|
5
|
+
import { ClientConfiguration } from "../../clientconfiguration";
|
|
6
|
+
import { logger } from "../../logger";
|
|
7
|
+
import { getConfirmation } from "../../utils";
|
|
8
|
+
import { createConnections } from "./createconnections";
|
|
9
|
+
|
|
10
|
+
describe("create-connections", () => {
|
|
11
|
+
let sandbox: sinon.SinonSandbox;
|
|
12
|
+
let createConnectionStub: sinon.SinonStub;
|
|
13
|
+
let loggerStub: sinon.SinonStubbedInstance<typeof logger>;
|
|
14
|
+
let getConfirmationStub: sinon.SinonStub;
|
|
15
|
+
let readFileSyncStub: sinon.SinonStub;
|
|
16
|
+
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
sandbox = sinon.createSandbox();
|
|
19
|
+
createConnectionStub = sandbox.stub();
|
|
20
|
+
loggerStub = sandbox.stub(logger);
|
|
21
|
+
getConfirmationStub = sandbox.stub();
|
|
22
|
+
readFileSyncStub = sandbox.stub(fs, "readFileSync");
|
|
23
|
+
|
|
24
|
+
sandbox
|
|
25
|
+
.stub(ClientConfiguration.prototype, "getOrganization")
|
|
26
|
+
.returns("test-org");
|
|
27
|
+
sandbox
|
|
28
|
+
.stub(ClientConfiguration.prototype, "getProject")
|
|
29
|
+
.returns("test-project");
|
|
30
|
+
sandbox
|
|
31
|
+
.stub(ClientConfiguration.prototype, "doesConfigExists")
|
|
32
|
+
.returns(true);
|
|
33
|
+
sandbox
|
|
34
|
+
.stub(ClientConfiguration.prototype, "getHeaders")
|
|
35
|
+
.returns({ Authorization: "Bearer test-token" });
|
|
36
|
+
|
|
37
|
+
sandbox
|
|
38
|
+
.stub(ConnectionsApi.prototype, "createConnection")
|
|
39
|
+
.callsFake(createConnectionStub);
|
|
40
|
+
sandbox
|
|
41
|
+
.stub(require("../../utils"), "getConfirmation")
|
|
42
|
+
.callsFake(getConfirmationStub);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
afterEach(() => {
|
|
46
|
+
sandbox.restore();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("should create connection successfully", async () => {
|
|
50
|
+
const mockConnections = [
|
|
51
|
+
{
|
|
52
|
+
name: "test_connection",
|
|
53
|
+
type: "postgres",
|
|
54
|
+
host: "localhost",
|
|
55
|
+
port: 5432,
|
|
56
|
+
},
|
|
57
|
+
];
|
|
58
|
+
readFileSyncStub.returns(JSON.stringify(mockConnections));
|
|
59
|
+
getConfirmationStub.resolves(true);
|
|
60
|
+
createConnectionStub.resolves({ data: {} });
|
|
61
|
+
|
|
62
|
+
await createConnections(
|
|
63
|
+
"http://test-server",
|
|
64
|
+
"/path/to/connections.json",
|
|
65
|
+
null,
|
|
66
|
+
null,
|
|
67
|
+
false,
|
|
68
|
+
false,
|
|
69
|
+
true,
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
expect(readFileSyncStub.calledWith("/path/to/connections.json", "utf8"))
|
|
73
|
+
.to.be.true;
|
|
74
|
+
expect(createConnectionStub.calledOnce).to.be.true;
|
|
75
|
+
expect(createConnectionStub.firstCall.args[0]).to.equal("test-org");
|
|
76
|
+
expect(createConnectionStub.firstCall.args[1]).to.equal("test-project");
|
|
77
|
+
expect(createConnectionStub.firstCall.args[2]).to.deep.include({
|
|
78
|
+
name: "test_connection",
|
|
79
|
+
});
|
|
80
|
+
expect(
|
|
81
|
+
loggerStub.info.calledWith(
|
|
82
|
+
sinon.match("Connection test_connection created successfully"),
|
|
83
|
+
),
|
|
84
|
+
).to.be.true;
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("should create multiple connections", async () => {
|
|
88
|
+
const mockConnections = [
|
|
89
|
+
{ name: "conn1", type: "postgres" },
|
|
90
|
+
{ name: "conn2", type: "mysql" },
|
|
91
|
+
];
|
|
92
|
+
readFileSyncStub.returns(JSON.stringify(mockConnections));
|
|
93
|
+
getConfirmationStub.resolves(true);
|
|
94
|
+
createConnectionStub.resolves({ data: {} });
|
|
95
|
+
|
|
96
|
+
await createConnections(
|
|
97
|
+
"http://test-server",
|
|
98
|
+
"/path/to/connections.json",
|
|
99
|
+
null,
|
|
100
|
+
null,
|
|
101
|
+
false,
|
|
102
|
+
false,
|
|
103
|
+
true,
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
expect(createConnectionStub.calledTwice).to.be.true;
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("should handle includeTables", async () => {
|
|
110
|
+
const mockConnections = [{ name: "test_conn", type: "postgres" }];
|
|
111
|
+
readFileSyncStub.returns(JSON.stringify(mockConnections));
|
|
112
|
+
getConfirmationStub.resolves(true);
|
|
113
|
+
createConnectionStub.resolves({ data: {} });
|
|
114
|
+
|
|
115
|
+
await createConnections(
|
|
116
|
+
"http://test-server",
|
|
117
|
+
"/path/to/connections.json",
|
|
118
|
+
"table1, table2",
|
|
119
|
+
null,
|
|
120
|
+
false,
|
|
121
|
+
false,
|
|
122
|
+
true,
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
expect(createConnectionStub.firstCall.args[2]).to.deep.include({
|
|
126
|
+
includeTables: ["table1", "table2"],
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("should handle excludeTables", async () => {
|
|
131
|
+
const mockConnections = [{ name: "test_conn", type: "postgres" }];
|
|
132
|
+
readFileSyncStub.returns(JSON.stringify(mockConnections));
|
|
133
|
+
getConfirmationStub.resolves(true);
|
|
134
|
+
createConnectionStub.resolves({ data: {} });
|
|
135
|
+
|
|
136
|
+
await createConnections(
|
|
137
|
+
"http://test-server",
|
|
138
|
+
"/path/to/connections.json",
|
|
139
|
+
null,
|
|
140
|
+
"table1, table2",
|
|
141
|
+
false,
|
|
142
|
+
false,
|
|
143
|
+
true,
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
expect(createConnectionStub.firstCall.args[2]).to.deep.include({
|
|
147
|
+
excludeTables: ["table1", "table2"],
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("should handle skipIndexing", async () => {
|
|
152
|
+
const mockConnections = [{ name: "test_conn", type: "postgres" }];
|
|
153
|
+
readFileSyncStub.returns(JSON.stringify(mockConnections));
|
|
154
|
+
getConfirmationStub.resolves(true);
|
|
155
|
+
createConnectionStub.resolves({ data: {} });
|
|
156
|
+
|
|
157
|
+
await createConnections(
|
|
158
|
+
"http://test-server",
|
|
159
|
+
"/path/to/connections.json",
|
|
160
|
+
null,
|
|
161
|
+
null,
|
|
162
|
+
true,
|
|
163
|
+
false,
|
|
164
|
+
true,
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
expect(createConnectionStub.firstCall.args[2]).to.deep.include({
|
|
168
|
+
excludeAllTables: true,
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("should reject includeTables and excludeTables together", async () => {
|
|
173
|
+
await createConnections(
|
|
174
|
+
"http://test-server",
|
|
175
|
+
"/path/to/connections.json",
|
|
176
|
+
"table1",
|
|
177
|
+
"table2",
|
|
178
|
+
false,
|
|
179
|
+
false,
|
|
180
|
+
true,
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
expect(createConnectionStub.called).to.be.false;
|
|
184
|
+
expect(
|
|
185
|
+
loggerStub.error.calledWith(
|
|
186
|
+
sinon.match(
|
|
187
|
+
"includeTables and excludeTables cannot be set at the same time",
|
|
188
|
+
),
|
|
189
|
+
),
|
|
190
|
+
).to.be.true;
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it("should reject skipIndexing with includeTables", async () => {
|
|
194
|
+
await createConnections(
|
|
195
|
+
"http://test-server",
|
|
196
|
+
"/path/to/connections.json",
|
|
197
|
+
"table1",
|
|
198
|
+
null,
|
|
199
|
+
true,
|
|
200
|
+
false,
|
|
201
|
+
true,
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
expect(createConnectionStub.called).to.be.false;
|
|
205
|
+
expect(
|
|
206
|
+
loggerStub.error.calledWith(
|
|
207
|
+
sinon.match(
|
|
208
|
+
"skipIndexing and includeTables cannot be set at the same time",
|
|
209
|
+
),
|
|
210
|
+
),
|
|
211
|
+
).to.be.true;
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it("should reject skipIndexing with excludeTables", async () => {
|
|
215
|
+
await createConnections(
|
|
216
|
+
"http://test-server",
|
|
217
|
+
"/path/to/connections.json",
|
|
218
|
+
null,
|
|
219
|
+
"table1",
|
|
220
|
+
true,
|
|
221
|
+
false,
|
|
222
|
+
true,
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
expect(createConnectionStub.called).to.be.false;
|
|
226
|
+
expect(
|
|
227
|
+
loggerStub.error.calledWith(
|
|
228
|
+
sinon.match(
|
|
229
|
+
"skipIndexing and excludeTables cannot be set at the same time",
|
|
230
|
+
),
|
|
231
|
+
),
|
|
232
|
+
).to.be.true;
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it("should reject invalid connection name", async () => {
|
|
236
|
+
const mockConnections = [
|
|
237
|
+
{ name: "123invalid", type: "postgres" },
|
|
238
|
+
{ name: "valid_connection", type: "postgres" },
|
|
239
|
+
];
|
|
240
|
+
readFileSyncStub.returns(JSON.stringify(mockConnections));
|
|
241
|
+
getConfirmationStub.resolves(true);
|
|
242
|
+
createConnectionStub.resolves({ data: {} });
|
|
243
|
+
|
|
244
|
+
await createConnections(
|
|
245
|
+
"http://test-server",
|
|
246
|
+
"/path/to/connections.json",
|
|
247
|
+
null,
|
|
248
|
+
null,
|
|
249
|
+
false,
|
|
250
|
+
false,
|
|
251
|
+
true,
|
|
252
|
+
);
|
|
253
|
+
|
|
254
|
+
expect(
|
|
255
|
+
loggerStub.error.calledWith(
|
|
256
|
+
sinon.match(/Connection name can only contain letters/),
|
|
257
|
+
),
|
|
258
|
+
).to.be.true;
|
|
259
|
+
expect(createConnectionStub.calledOnce).to.be.true;
|
|
260
|
+
expect(createConnectionStub.firstCall.args[2].name).to.equal(
|
|
261
|
+
"valid_connection",
|
|
262
|
+
);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it("should handle missing config", async () => {
|
|
266
|
+
sandbox.restore();
|
|
267
|
+
sandbox = sinon.createSandbox();
|
|
268
|
+
createConnectionStub = sandbox.stub();
|
|
269
|
+
loggerStub = sandbox.stub(logger);
|
|
270
|
+
getConfirmationStub = sandbox.stub();
|
|
271
|
+
readFileSyncStub = sandbox.stub(fs, "readFileSync");
|
|
272
|
+
|
|
273
|
+
sandbox
|
|
274
|
+
.stub(ClientConfiguration.prototype, "doesConfigExists")
|
|
275
|
+
.returns(false);
|
|
276
|
+
sandbox
|
|
277
|
+
.stub(ConnectionsApi.prototype, "createConnection")
|
|
278
|
+
.callsFake(createConnectionStub);
|
|
279
|
+
sandbox
|
|
280
|
+
.stub(require("../../utils"), "getConfirmation")
|
|
281
|
+
.callsFake(getConfirmationStub);
|
|
282
|
+
|
|
283
|
+
await createConnections(
|
|
284
|
+
"http://test-server",
|
|
285
|
+
"/path/to/connections.json",
|
|
286
|
+
null,
|
|
287
|
+
null,
|
|
288
|
+
false,
|
|
289
|
+
false,
|
|
290
|
+
true,
|
|
291
|
+
);
|
|
292
|
+
|
|
293
|
+
expect(createConnectionStub.called).to.be.false;
|
|
294
|
+
expect(
|
|
295
|
+
loggerStub.error.calledWith(
|
|
296
|
+
sinon.match("Please, make sure that you are logged in"),
|
|
297
|
+
),
|
|
298
|
+
).to.be.true;
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
it("should handle missing project", async () => {
|
|
302
|
+
sandbox.restore();
|
|
303
|
+
sandbox = sinon.createSandbox();
|
|
304
|
+
createConnectionStub = sandbox.stub();
|
|
305
|
+
loggerStub = sandbox.stub(logger);
|
|
306
|
+
getConfirmationStub = sandbox.stub();
|
|
307
|
+
readFileSyncStub = sandbox.stub(fs, "readFileSync");
|
|
308
|
+
|
|
309
|
+
sandbox
|
|
310
|
+
.stub(ClientConfiguration.prototype, "doesConfigExists")
|
|
311
|
+
.returns(true);
|
|
312
|
+
sandbox.stub(ClientConfiguration.prototype, "getProject").returns("");
|
|
313
|
+
sandbox
|
|
314
|
+
.stub(ConnectionsApi.prototype, "createConnection")
|
|
315
|
+
.callsFake(createConnectionStub);
|
|
316
|
+
sandbox
|
|
317
|
+
.stub(require("../../utils"), "getConfirmation")
|
|
318
|
+
.callsFake(getConfirmationStub);
|
|
319
|
+
|
|
320
|
+
await createConnections(
|
|
321
|
+
"http://test-server",
|
|
322
|
+
"/path/to/connections.json",
|
|
323
|
+
null,
|
|
324
|
+
null,
|
|
325
|
+
false,
|
|
326
|
+
false,
|
|
327
|
+
true,
|
|
328
|
+
);
|
|
329
|
+
|
|
330
|
+
expect(createConnectionStub.called).to.be.false;
|
|
331
|
+
expect(
|
|
332
|
+
loggerStub.error.calledWith(
|
|
333
|
+
sinon.match("Please, make sure to set a project"),
|
|
334
|
+
),
|
|
335
|
+
).to.be.true;
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
it("should request confirmation when autoConfirm is false", async () => {
|
|
339
|
+
const mockConnections = [{ name: "test_conn", type: "postgres" }];
|
|
340
|
+
readFileSyncStub.returns(JSON.stringify(mockConnections));
|
|
341
|
+
getConfirmationStub.resolves(true);
|
|
342
|
+
createConnectionStub.resolves({ data: {} });
|
|
343
|
+
|
|
344
|
+
await createConnections(
|
|
345
|
+
"http://test-server",
|
|
346
|
+
"/path/to/connections.json",
|
|
347
|
+
null,
|
|
348
|
+
null,
|
|
349
|
+
false,
|
|
350
|
+
false,
|
|
351
|
+
false,
|
|
352
|
+
);
|
|
353
|
+
|
|
354
|
+
expect(getConfirmationStub.calledOnce).to.be.true;
|
|
355
|
+
expect(createConnectionStub.calledOnce).to.be.true;
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
it("should cancel when confirmation is denied", async () => {
|
|
359
|
+
const mockConnections = [{ name: "test_conn", type: "postgres" }];
|
|
360
|
+
readFileSyncStub.returns(JSON.stringify(mockConnections));
|
|
361
|
+
getConfirmationStub.resolves(false);
|
|
362
|
+
|
|
363
|
+
await createConnections(
|
|
364
|
+
"http://test-server",
|
|
365
|
+
"/path/to/connections.json",
|
|
366
|
+
null,
|
|
367
|
+
null,
|
|
368
|
+
false,
|
|
369
|
+
false,
|
|
370
|
+
false,
|
|
371
|
+
);
|
|
372
|
+
|
|
373
|
+
expect(getConfirmationStub.calledOnce).to.be.true;
|
|
374
|
+
expect(createConnectionStub.called).to.be.false;
|
|
375
|
+
expect(loggerStub.info.calledWith(sinon.match("Operation cancelled."))).to
|
|
376
|
+
.be.true;
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
it("should handle API errors", async () => {
|
|
380
|
+
const mockConnections = [{ name: "test_conn", type: "postgres" }];
|
|
381
|
+
readFileSyncStub.returns(JSON.stringify(mockConnections));
|
|
382
|
+
getConfirmationStub.resolves(true);
|
|
383
|
+
const mockError = new Error("API Error");
|
|
384
|
+
createConnectionStub.rejects(mockError);
|
|
385
|
+
|
|
386
|
+
await createConnections(
|
|
387
|
+
"http://test-server",
|
|
388
|
+
"/path/to/connections.json",
|
|
389
|
+
null,
|
|
390
|
+
null,
|
|
391
|
+
false,
|
|
392
|
+
true,
|
|
393
|
+
true,
|
|
394
|
+
);
|
|
395
|
+
|
|
396
|
+
expect(createConnectionStub.calledOnce).to.be.true;
|
|
397
|
+
expect(
|
|
398
|
+
loggerStub.error.calledWith(
|
|
399
|
+
sinon.match("Failed to create connection test_conn"),
|
|
400
|
+
),
|
|
401
|
+
).to.be.true;
|
|
402
|
+
});
|
|
403
|
+
});
|
|
@@ -12,6 +12,7 @@ export const createConnections = async (
|
|
|
12
12
|
connectionFileName: string,
|
|
13
13
|
includeTables: string | null,
|
|
14
14
|
excludeTables: string | null,
|
|
15
|
+
skipIndexing: boolean,
|
|
15
16
|
debug: boolean,
|
|
16
17
|
autoConfirm: boolean,
|
|
17
18
|
) => {
|
|
@@ -30,7 +31,23 @@ export const createConnections = async (
|
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
if (includeTables && excludeTables) {
|
|
33
|
-
logger.error(
|
|
34
|
+
logger.error(
|
|
35
|
+
"includeTables and excludeTables cannot be set at the same time",
|
|
36
|
+
);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (skipIndexing && includeTables) {
|
|
41
|
+
logger.error(
|
|
42
|
+
"skipIndexing and includeTables cannot be set at the same time",
|
|
43
|
+
);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (skipIndexing && excludeTables) {
|
|
48
|
+
logger.error(
|
|
49
|
+
"skipIndexing and excludeTables cannot be set at the same time",
|
|
50
|
+
);
|
|
34
51
|
return;
|
|
35
52
|
}
|
|
36
53
|
|
|
@@ -39,9 +56,10 @@ export const createConnections = async (
|
|
|
39
56
|
) as Connection[];
|
|
40
57
|
|
|
41
58
|
for (const connection of connections) {
|
|
42
|
-
|
|
43
59
|
if (!/^[a-zA-Z_][a-zA-Z0-9_]+$/.test(connection.name)) {
|
|
44
|
-
logger.error(
|
|
60
|
+
logger.error(
|
|
61
|
+
`Connection name can only contain letters, numbers, and underscores for connection and should start with a letter or underscore: ${connection.name}`,
|
|
62
|
+
);
|
|
45
63
|
continue;
|
|
46
64
|
}
|
|
47
65
|
|
|
@@ -55,8 +73,12 @@ export const createConnections = async (
|
|
|
55
73
|
}
|
|
56
74
|
}
|
|
57
75
|
try {
|
|
58
|
-
const parsedIncludeTables = includeTables
|
|
59
|
-
|
|
76
|
+
const parsedIncludeTables = includeTables
|
|
77
|
+
? includeTables.split(",").map((s) => s.trim())
|
|
78
|
+
: undefined;
|
|
79
|
+
const parsedExcludeTables = excludeTables
|
|
80
|
+
? excludeTables.split(",").map((s) => s.trim())
|
|
81
|
+
: undefined;
|
|
60
82
|
|
|
61
83
|
if (parsedIncludeTables) {
|
|
62
84
|
connection.includeTables = parsedIncludeTables;
|
|
@@ -64,6 +86,9 @@ export const createConnections = async (
|
|
|
64
86
|
if (parsedExcludeTables) {
|
|
65
87
|
connection.excludeTables = parsedExcludeTables;
|
|
66
88
|
}
|
|
89
|
+
if (skipIndexing) {
|
|
90
|
+
connection.excludeAllTables = true;
|
|
91
|
+
}
|
|
67
92
|
|
|
68
93
|
await connectionsApi.createConnection(
|
|
69
94
|
organizationName,
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import sinon from "sinon";
|
|
3
|
+
import { ConnectionsApi } from "../../client/api";
|
|
4
|
+
import { ClientConfiguration } from "../../clientconfiguration";
|
|
5
|
+
import { logger } from "../../logger";
|
|
6
|
+
import { getConfirmation } from "../../utils";
|
|
7
|
+
import { deleteConnection } from "./deleteconnection";
|
|
8
|
+
|
|
9
|
+
describe("delete-connection", () => {
|
|
10
|
+
let sandbox: sinon.SinonSandbox;
|
|
11
|
+
let deleteConnectionStub: sinon.SinonStub;
|
|
12
|
+
let loggerStub: sinon.SinonStubbedInstance<typeof logger>;
|
|
13
|
+
let getConfirmationStub: sinon.SinonStub;
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
sandbox = sinon.createSandbox();
|
|
17
|
+
deleteConnectionStub = 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(ConnectionsApi.prototype, "deleteConnection")
|
|
36
|
+
.callsFake(deleteConnectionStub);
|
|
37
|
+
sandbox
|
|
38
|
+
.stub(require("../../utils"), "getConfirmation")
|
|
39
|
+
.callsFake(getConfirmationStub);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
afterEach(() => {
|
|
43
|
+
sandbox.restore();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("should delete connection successfully", async () => {
|
|
47
|
+
deleteConnectionStub.resolves({ status: 200 });
|
|
48
|
+
getConfirmationStub.resolves(true);
|
|
49
|
+
|
|
50
|
+
await deleteConnection(
|
|
51
|
+
"http://test-server",
|
|
52
|
+
"test-connection",
|
|
53
|
+
false,
|
|
54
|
+
true,
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
expect(deleteConnectionStub.calledOnce).to.be.true;
|
|
58
|
+
expect(deleteConnectionStub.firstCall.args[0]).to.equal("test-org");
|
|
59
|
+
expect(deleteConnectionStub.firstCall.args[1]).to.equal("test-project");
|
|
60
|
+
expect(deleteConnectionStub.firstCall.args[2]).to.equal(
|
|
61
|
+
"test-connection",
|
|
62
|
+
);
|
|
63
|
+
expect(deleteConnectionStub.firstCall.args[3]).to.deep.include({
|
|
64
|
+
baseURL: "http://test-server",
|
|
65
|
+
headers: { Authorization: "Bearer test-token" },
|
|
66
|
+
});
|
|
67
|
+
expect(
|
|
68
|
+
loggerStub.info.calledWith(
|
|
69
|
+
sinon.match("Connection deleted successfully"),
|
|
70
|
+
),
|
|
71
|
+
).to.be.true;
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("should handle missing config", async () => {
|
|
75
|
+
sandbox.restore();
|
|
76
|
+
sandbox = sinon.createSandbox();
|
|
77
|
+
deleteConnectionStub = sandbox.stub();
|
|
78
|
+
loggerStub = sandbox.stub(logger);
|
|
79
|
+
getConfirmationStub = sandbox.stub();
|
|
80
|
+
|
|
81
|
+
sandbox
|
|
82
|
+
.stub(ClientConfiguration.prototype, "doesConfigExists")
|
|
83
|
+
.returns(false);
|
|
84
|
+
sandbox
|
|
85
|
+
.stub(ConnectionsApi.prototype, "deleteConnection")
|
|
86
|
+
.callsFake(deleteConnectionStub);
|
|
87
|
+
sandbox
|
|
88
|
+
.stub(require("../../utils"), "getConfirmation")
|
|
89
|
+
.callsFake(getConfirmationStub);
|
|
90
|
+
|
|
91
|
+
await deleteConnection(
|
|
92
|
+
"http://test-server",
|
|
93
|
+
"test-connection",
|
|
94
|
+
false,
|
|
95
|
+
true,
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
expect(deleteConnectionStub.called).to.be.false;
|
|
99
|
+
expect(
|
|
100
|
+
loggerStub.error.calledWith(
|
|
101
|
+
sinon.match("Please, make sure that you are logged in"),
|
|
102
|
+
),
|
|
103
|
+
).to.be.true;
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("should handle missing project", async () => {
|
|
107
|
+
sandbox.restore();
|
|
108
|
+
sandbox = sinon.createSandbox();
|
|
109
|
+
deleteConnectionStub = sandbox.stub();
|
|
110
|
+
loggerStub = sandbox.stub(logger);
|
|
111
|
+
getConfirmationStub = sandbox.stub();
|
|
112
|
+
|
|
113
|
+
sandbox
|
|
114
|
+
.stub(ClientConfiguration.prototype, "doesConfigExists")
|
|
115
|
+
.returns(true);
|
|
116
|
+
sandbox.stub(ClientConfiguration.prototype, "getProject").returns("");
|
|
117
|
+
sandbox
|
|
118
|
+
.stub(ConnectionsApi.prototype, "deleteConnection")
|
|
119
|
+
.callsFake(deleteConnectionStub);
|
|
120
|
+
sandbox
|
|
121
|
+
.stub(require("../../utils"), "getConfirmation")
|
|
122
|
+
.callsFake(getConfirmationStub);
|
|
123
|
+
|
|
124
|
+
await deleteConnection(
|
|
125
|
+
"http://test-server",
|
|
126
|
+
"test-connection",
|
|
127
|
+
false,
|
|
128
|
+
true,
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
expect(deleteConnectionStub.called).to.be.false;
|
|
132
|
+
expect(
|
|
133
|
+
loggerStub.error.calledWith(
|
|
134
|
+
sinon.match("Please, make sure to set a project"),
|
|
135
|
+
),
|
|
136
|
+
).to.be.true;
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("should request confirmation when autoConfirm is false", async () => {
|
|
140
|
+
deleteConnectionStub.resolves({ status: 200 });
|
|
141
|
+
getConfirmationStub.resolves(true);
|
|
142
|
+
|
|
143
|
+
await deleteConnection(
|
|
144
|
+
"http://test-server",
|
|
145
|
+
"test-connection",
|
|
146
|
+
false,
|
|
147
|
+
false,
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
expect(getConfirmationStub.calledOnce).to.be.true;
|
|
151
|
+
expect(deleteConnectionStub.calledOnce).to.be.true;
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it("should cancel when confirmation is denied", async () => {
|
|
155
|
+
getConfirmationStub.resolves(false);
|
|
156
|
+
|
|
157
|
+
await deleteConnection(
|
|
158
|
+
"http://test-server",
|
|
159
|
+
"test-connection",
|
|
160
|
+
false,
|
|
161
|
+
false,
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
expect(getConfirmationStub.calledOnce).to.be.true;
|
|
165
|
+
expect(deleteConnectionStub.called).to.be.false;
|
|
166
|
+
expect(loggerStub.info.calledWith(sinon.match("Operation cancelled."))).to
|
|
167
|
+
.be.true;
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("should handle API errors", async () => {
|
|
171
|
+
const mockError = new Error("API Error");
|
|
172
|
+
deleteConnectionStub.rejects(mockError);
|
|
173
|
+
getConfirmationStub.resolves(true);
|
|
174
|
+
|
|
175
|
+
await deleteConnection(
|
|
176
|
+
"http://test-server",
|
|
177
|
+
"test-connection",
|
|
178
|
+
true,
|
|
179
|
+
true,
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
expect(deleteConnectionStub.calledOnce).to.be.true;
|
|
183
|
+
expect(
|
|
184
|
+
loggerStub.error.calledWith(
|
|
185
|
+
sinon.match("Failed to delete connection"),
|
|
186
|
+
),
|
|
187
|
+
).to.be.true;
|
|
188
|
+
});
|
|
189
|
+
});
|