mongodb-atlas-api-client 2.31.0 → 3.1.0
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/.github/workflows/codeql-analysis.yml +72 -0
- package/.github/workflows/testcoverage.yml +46 -0
- package/README.md +80 -80
- package/package.json +6 -11
- package/src/alert.js +19 -16
- package/src/atlasSearch.js +43 -37
- package/src/atlasUser.js +31 -28
- package/src/cloudProviderAccess.js +26 -21
- package/src/cluster.js +49 -42
- package/src/customDbRole.js +31 -26
- package/src/dataLake.js +39 -37
- package/src/event.js +22 -20
- package/src/helper.js +11 -0
- package/src/httpClient.js +28 -0
- package/src/index.js +5 -6
- package/src/organization.js +41 -36
- package/src/project.js +46 -40
- package/src/projectAccesslist.js +31 -26
- package/src/projectWhitelist.js +31 -26
- package/src/user.js +31 -26
- package/test/alert.test.js +43 -0
- package/test/atlasSearch.test.js +91 -0
- package/test/atlasUser.test.js +66 -0
- package/test/dataLake.test.js +1 -2
- package/test/helper.test.js +38 -0
- package/.travis.yml +0 -6
package/src/projectWhitelist.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const {getQueryStringFromOptions} = require("./helper");
|
|
2
|
+
|
|
1
3
|
class ProjectWhitelist {
|
|
2
4
|
|
|
3
5
|
constructor(client, baseUrl, projectId) {
|
|
@@ -6,56 +8,59 @@ class ProjectWhitelist {
|
|
|
6
8
|
this.projectId_ = projectId;
|
|
7
9
|
}
|
|
8
10
|
|
|
9
|
-
async get(whitelistentry, options) {
|
|
10
|
-
const
|
|
11
|
-
const
|
|
11
|
+
async get(whitelistentry, options = {}) {
|
|
12
|
+
const queryString = getQueryStringFromOptions(options);
|
|
13
|
+
const httpOptions = options.httpOptions;
|
|
12
14
|
const response = (
|
|
13
|
-
await this.client_.fetch(`${this.baseUrl_}/groups/${this.projectId_}/whitelist/${whitelistentry}?${queryString}
|
|
14
|
-
)
|
|
15
|
+
await this.client_.fetch(`${this.baseUrl_}/groups/${this.projectId_}/whitelist/${whitelistentry}?${queryString}`, httpOptions)
|
|
16
|
+
);
|
|
15
17
|
return response;
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
async getAll(options) {
|
|
19
|
-
const
|
|
20
|
-
const
|
|
20
|
+
async getAll(options = {}) {
|
|
21
|
+
const queryString = getQueryStringFromOptions(options);
|
|
22
|
+
const httpOptions = options.httpOptions;
|
|
21
23
|
const response = (
|
|
22
|
-
await this.client_.fetch(`${this.baseUrl_}/groups/${this.projectId_}/whitelist?${queryString}
|
|
23
|
-
)
|
|
24
|
+
await this.client_.fetch(`${this.baseUrl_}/groups/${this.projectId_}/whitelist?${queryString}`, httpOptions)
|
|
25
|
+
);
|
|
24
26
|
return response;
|
|
25
27
|
}
|
|
26
28
|
|
|
27
|
-
async delete(whitelistentry, options) {
|
|
28
|
-
const
|
|
29
|
-
const
|
|
29
|
+
async delete(whitelistentry, options = {}) {
|
|
30
|
+
const queryString = getQueryStringFromOptions(options);
|
|
31
|
+
const httpOptions = options.httpOptions;
|
|
30
32
|
await this.client_.fetch(`${this.baseUrl_}/groups/${this.projectId_}/whitelist/${whitelistentry}?${queryString}`, {
|
|
31
|
-
"method": "DELETE"
|
|
33
|
+
"method": "DELETE",
|
|
34
|
+
...httpOptions
|
|
32
35
|
});
|
|
33
36
|
return true;
|
|
34
37
|
}
|
|
35
38
|
|
|
36
|
-
async update(body, options) {
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
+
async update(body, options = {}) {
|
|
40
|
+
const queryString = getQueryStringFromOptions(options);
|
|
41
|
+
const httpOptions = options.httpOptions;
|
|
39
42
|
const response = (
|
|
40
43
|
await this.client_.fetch(`${this.baseUrl_}/groups/${this.projectId_}/whitelist?${queryString}`, {
|
|
41
44
|
"method": "POST",
|
|
42
|
-
"
|
|
43
|
-
"headers": {"Content-Type": "application/json"}
|
|
45
|
+
"data": body,
|
|
46
|
+
"headers": {"Content-Type": "application/json"},
|
|
47
|
+
...httpOptions
|
|
44
48
|
})
|
|
45
|
-
)
|
|
49
|
+
);
|
|
46
50
|
return response;
|
|
47
51
|
}
|
|
48
52
|
|
|
49
|
-
async create(body, options) {
|
|
50
|
-
const
|
|
51
|
-
const
|
|
53
|
+
async create(body, options = {}) {
|
|
54
|
+
const queryString = getQueryStringFromOptions(options);
|
|
55
|
+
const httpOptions = options.httpOptions;
|
|
52
56
|
const response = (
|
|
53
57
|
await this.client_.fetch(`${this.baseUrl_}/groups/${this.projectId_}/whitelist?${queryString}`, {
|
|
54
58
|
"method": "POST",
|
|
55
|
-
"
|
|
56
|
-
"headers": {"Content-Type": "application/json"}
|
|
59
|
+
"data": body,
|
|
60
|
+
"headers": {"Content-Type": "application/json"},
|
|
61
|
+
...httpOptions
|
|
57
62
|
})
|
|
58
|
-
)
|
|
63
|
+
);
|
|
59
64
|
return response;
|
|
60
65
|
}
|
|
61
66
|
}
|
package/src/user.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const {getQueryStringFromOptions} = require("./helper");
|
|
2
|
+
|
|
1
3
|
class User {
|
|
2
4
|
|
|
3
5
|
constructor(client, baseUrl, projectId) {
|
|
@@ -6,56 +8,59 @@ class User {
|
|
|
6
8
|
this.projectId_ = projectId;
|
|
7
9
|
}
|
|
8
10
|
|
|
9
|
-
async get(username, options) {
|
|
10
|
-
const
|
|
11
|
-
const
|
|
11
|
+
async get(username, options = {}) {
|
|
12
|
+
const queryString = getQueryStringFromOptions(options);
|
|
13
|
+
const httpOptions = options.httpOptions;
|
|
12
14
|
const response = (
|
|
13
|
-
await this.client_.fetch(`${this.baseUrl_}/groups/${this.projectId_}/databaseUsers/admin/${username}?${queryString}
|
|
14
|
-
)
|
|
15
|
+
await this.client_.fetch(`${this.baseUrl_}/groups/${this.projectId_}/databaseUsers/admin/${username}?${queryString}`, httpOptions)
|
|
16
|
+
);
|
|
15
17
|
return response;
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
async getAll(options) {
|
|
19
|
-
const
|
|
20
|
-
const
|
|
20
|
+
async getAll(options = {}) {
|
|
21
|
+
const queryString = getQueryStringFromOptions(options);
|
|
22
|
+
const httpOptions = options.httpOptions;
|
|
21
23
|
const response = (
|
|
22
|
-
await this.client_.fetch(`${this.baseUrl_}/groups/${this.projectId_}/databaseUsers?${queryString}
|
|
23
|
-
)
|
|
24
|
+
await this.client_.fetch(`${this.baseUrl_}/groups/${this.projectId_}/databaseUsers?${queryString}`, httpOptions)
|
|
25
|
+
);
|
|
24
26
|
return response;
|
|
25
27
|
}
|
|
26
28
|
|
|
27
|
-
async delete(username, options) {
|
|
28
|
-
const
|
|
29
|
-
const
|
|
29
|
+
async delete(username, options = {}) {
|
|
30
|
+
const queryString = getQueryStringFromOptions(options);
|
|
31
|
+
const httpOptions = options.httpOptions;
|
|
30
32
|
await this.client_.fetch(`${this.baseUrl_}/groups/${this.projectId_}/databaseUsers/admin/${username}?${queryString}`, {
|
|
31
|
-
"method": "DELETE"
|
|
33
|
+
"method": "DELETE",
|
|
34
|
+
...httpOptions
|
|
32
35
|
});
|
|
33
36
|
return true;
|
|
34
37
|
}
|
|
35
38
|
|
|
36
|
-
async update(username, body, options) {
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
+
async update(username, body, options = {}) {
|
|
40
|
+
const queryString = getQueryStringFromOptions(options);
|
|
41
|
+
const httpOptions = options.httpOptions;
|
|
39
42
|
const response = (
|
|
40
43
|
await this.client_.fetch(`${this.baseUrl_}/groups/${this.projectId_}/databaseUsers/admin/${username}?${queryString}`, {
|
|
41
44
|
"method": "PATCH",
|
|
42
|
-
"
|
|
43
|
-
"headers": {"Content-Type": "application/json"}
|
|
45
|
+
"data": body,
|
|
46
|
+
"headers": {"Content-Type": "application/json"},
|
|
47
|
+
...httpOptions
|
|
44
48
|
})
|
|
45
|
-
)
|
|
49
|
+
);
|
|
46
50
|
return response;
|
|
47
51
|
}
|
|
48
52
|
|
|
49
|
-
async create(body, options) {
|
|
50
|
-
const
|
|
51
|
-
const
|
|
53
|
+
async create(body, options = {}) {
|
|
54
|
+
const queryString = getQueryStringFromOptions(options);
|
|
55
|
+
const httpOptions = options.httpOptions;
|
|
52
56
|
const response = (
|
|
53
57
|
await this.client_.fetch(`${this.baseUrl_}/groups/${this.projectId_}/databaseUsers?${queryString}`, {
|
|
54
58
|
"method": "POST",
|
|
55
|
-
"
|
|
56
|
-
"headers": {"Content-Type": "application/json"}
|
|
59
|
+
"data": body,
|
|
60
|
+
"headers": {"Content-Type": "application/json"},
|
|
61
|
+
...httpOptions
|
|
57
62
|
})
|
|
58
|
-
)
|
|
63
|
+
);
|
|
59
64
|
return response;
|
|
60
65
|
}
|
|
61
66
|
}
|
package/test/alert.test.js
CHANGED
|
@@ -2,6 +2,9 @@ const {describe, it} = exports.lab = require("@hapi/lab").script();
|
|
|
2
2
|
const {expect} = require("@hapi/code");
|
|
3
3
|
const nock = require("nock");
|
|
4
4
|
const getClient = require("../src");
|
|
5
|
+
const Alert = require("../src/alert");
|
|
6
|
+
const HttpClient = require("../src/httpClient");
|
|
7
|
+
const sinon = require("sinon");
|
|
5
8
|
|
|
6
9
|
const baseUrl = "http://dummyBaseUrl";
|
|
7
10
|
const projectId = "dummyProjectId";
|
|
@@ -56,3 +59,43 @@ describe("Mongo Atlas Api Client - Alert", () => {
|
|
|
56
59
|
});
|
|
57
60
|
});
|
|
58
61
|
});
|
|
62
|
+
|
|
63
|
+
describe("Alert Class", () => {
|
|
64
|
+
|
|
65
|
+
const mockRequest = {
|
|
66
|
+
"request": sinon.stub().returns(new Promise(resolve => resolve({"data": "some test data"})))
|
|
67
|
+
};
|
|
68
|
+
const mockHttpClient = new HttpClient(mockRequest, "dummyPublicKey", "dummyPrivateKey");
|
|
69
|
+
|
|
70
|
+
const alert = new Alert(mockHttpClient, "dummyBaseUrl", "dummyProjectId");
|
|
71
|
+
|
|
72
|
+
describe("When GetAll method is called with querystring parameters and httpOptions", () => {
|
|
73
|
+
it("Should send appropriate parameters to underlying request", async () => {
|
|
74
|
+
const requestParams = {"digestAuth": "dummyPublicKey:dummyPrivateKey", "dataType": "json"};
|
|
75
|
+
await alert.getAll({"queryStringParam1": "value1", "httpOptions": {"options1": "value1"}});
|
|
76
|
+
expect(mockRequest.request.calledWith("dummyBaseUrl/groups/dummyProjectId/alerts?queryStringParam1=value1", {...requestParams, "options1": "value1"})).to.be.true();
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe("When Get method is called with querystring parameters and httpOptions", () => {
|
|
81
|
+
it("Should send appropriate parameters to underlying request", async () => {
|
|
82
|
+
const requestParams = {"digestAuth": "dummyPublicKey:dummyPrivateKey", "dataType": "json"};
|
|
83
|
+
await alert.get("alertId", {"queryStringParam1": "value1", "httpOptions": {"options1": "value1"}});
|
|
84
|
+
expect(mockRequest.request.calledWith("dummyBaseUrl/groups/dummyProjectId/alerts/alertId?queryStringParam1=value1", {...requestParams, "options1": "value1"})).to.be.true();
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
describe("When Acknowledge method is called with querystring parameters and httpOptions", () => {
|
|
89
|
+
it("Should send appropriate parameters to underlying request", async () => {
|
|
90
|
+
const requestParams = {
|
|
91
|
+
"digestAuth": "dummyPublicKey:dummyPrivateKey",
|
|
92
|
+
"dataType": "json",
|
|
93
|
+
"method": "PATCH",
|
|
94
|
+
"data": {"body": "text"},
|
|
95
|
+
"headers": {"Content-Type": "application/json"}};
|
|
96
|
+
await alert.acknowledge("alertId", {"body": "text"}, {"queryStringParam1": "value1", "httpOptions": {"options1": "value1"}});
|
|
97
|
+
expect(mockRequest.request.calledWith("dummyBaseUrl/groups/dummyProjectId/alerts/alertId?queryStringParam1=value1", {...requestParams, "options1": "value1"})).to.be.true();
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
});
|
package/test/atlasSearch.test.js
CHANGED
|
@@ -2,6 +2,9 @@ const {describe, it} = exports.lab = require("@hapi/lab").script();
|
|
|
2
2
|
const {expect} = require("@hapi/code");
|
|
3
3
|
const nock = require("nock");
|
|
4
4
|
const getClient = require("../src");
|
|
5
|
+
const AtlasSearch = require("../src/atlasSearch");
|
|
6
|
+
const HttpClient = require("../src/httpClient");
|
|
7
|
+
const sinon = require("sinon");
|
|
5
8
|
|
|
6
9
|
const baseUrl = "http://dummyBaseUrl";
|
|
7
10
|
const projectId = "dummyProjectId";
|
|
@@ -104,3 +107,91 @@ describe("Mongo Atlas Api Client - atlasSearch", () => {
|
|
|
104
107
|
});
|
|
105
108
|
});
|
|
106
109
|
});
|
|
110
|
+
|
|
111
|
+
describe("AtlasSearch Class", () => {
|
|
112
|
+
|
|
113
|
+
const mockRequest = {
|
|
114
|
+
"request": sinon.stub().returns(new Promise(resolve => resolve({"data": "some test data"})))
|
|
115
|
+
};
|
|
116
|
+
const mockHttpClient = new HttpClient(mockRequest, "dummyPublicKey", "dummyPrivateKey");
|
|
117
|
+
|
|
118
|
+
const atlasSearch = new AtlasSearch(mockHttpClient, "dummyBaseUrl", "dummyProjectId");
|
|
119
|
+
|
|
120
|
+
describe("When getAllAnalyzers method is called with querystring parameters and httpOptions", () => {
|
|
121
|
+
it("Should send appropriate parameters to underlying request", async () => {
|
|
122
|
+
const requestParams = {"digestAuth": "dummyPublicKey:dummyPrivateKey", "dataType": "json"};
|
|
123
|
+
await atlasSearch.getAllAnalyzers("clusterName", {"queryStringParam1": "value1", "httpOptions": {"options1": "value1"}});
|
|
124
|
+
expect(mockRequest.request.calledWith("dummyBaseUrl/groups/dummyProjectId/clusters/clusterName/fts/analyzers?queryStringParam1=value1", {...requestParams, "options1": "value1"})).to.be.true();
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
describe("When Get method is called with querystring parameters and httpOptions", () => {
|
|
129
|
+
it("Should send appropriate parameters to underlying request", async () => {
|
|
130
|
+
const requestParams = {"digestAuth": "dummyPublicKey:dummyPrivateKey", "dataType": "json"};
|
|
131
|
+
await atlasSearch.get("clusterName", "indexId", {"queryStringParam1": "value1", "httpOptions": {"options1": "value1"}});
|
|
132
|
+
expect(mockRequest.request.calledWith("dummyBaseUrl/groups/dummyProjectId/clusters/clusterName/fts/indexes/indexId?queryStringParam1=value1", {...requestParams, "options1": "value1"})).to.be.true();
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
describe("When upsertAnalyzer method is called with querystring parameters and httpOptions", () => {
|
|
137
|
+
it("Should send appropriate parameters to underlying request", async () => {
|
|
138
|
+
const requestParams = {
|
|
139
|
+
"digestAuth": "dummyPublicKey:dummyPrivateKey",
|
|
140
|
+
"dataType": "json",
|
|
141
|
+
"method": "PUT",
|
|
142
|
+
"data": {"body": "text"},
|
|
143
|
+
"headers": {"Content-Type": "application/json"}};
|
|
144
|
+
await atlasSearch.upsertAnalyzer("clusterName", {"body": "text"}, {"queryStringParam1": "value1", "httpOptions": {"options1": "value1"}});
|
|
145
|
+
expect(mockRequest.request.calledWith("dummyBaseUrl/groups/dummyProjectId/clusters/clusterName/fts/analyzers?queryStringParam1=value1", {...requestParams, "options1": "value1"})).to.be.true();
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
describe("When getAll method is called with querystring parameters and httpOptions", () => {
|
|
150
|
+
it("Should send appropriate parameters to underlying request", async () => {
|
|
151
|
+
const requestParams = {"digestAuth": "dummyPublicKey:dummyPrivateKey", "dataType": "json"};
|
|
152
|
+
await atlasSearch.getAll("clusterName", "databaseName", "collectionName", {"queryStringParam1": "value1", "httpOptions": {"options1": "value1"}});
|
|
153
|
+
expect(mockRequest.request.calledWith("dummyBaseUrl/groups/dummyProjectId/clusters/clusterName/fts/indexes/databaseName/collectionName?queryStringParam1=value1", {...requestParams, "options1": "value1"})).to.be.true();
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
describe("When delete method is called with querystring parameters and httpOptions", () => {
|
|
158
|
+
it("Should send appropriate parameters to underlying request", async () => {
|
|
159
|
+
const requestParams = {
|
|
160
|
+
"digestAuth": "dummyPublicKey:dummyPrivateKey",
|
|
161
|
+
"dataType": "json",
|
|
162
|
+
"method": "DELETE"
|
|
163
|
+
};
|
|
164
|
+
await atlasSearch.delete("clusterName", "indexId", {"queryStringParam1": "value1", "httpOptions": {"options1": "value1"}});
|
|
165
|
+
expect(mockRequest.request.calledWith("dummyBaseUrl/groups/dummyProjectId/clusters/clusterName/fts/indexes/indexId?queryStringParam1=value1", {...requestParams, "options1": "value1"})).to.be.true();
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
describe("When update method is called with querystring parameters and httpOptions", () => {
|
|
170
|
+
it("Should send appropriate parameters to underlying request", async () => {
|
|
171
|
+
const requestParams = {
|
|
172
|
+
"digestAuth": "dummyPublicKey:dummyPrivateKey",
|
|
173
|
+
"dataType": "json",
|
|
174
|
+
"method": "PATCH",
|
|
175
|
+
"data": {"body": "text"},
|
|
176
|
+
"headers": {"Content-Type": "application/json"}
|
|
177
|
+
};
|
|
178
|
+
await atlasSearch.update("clusterName", "indexId", {"body": "text"}, {"queryStringParam1": "value1", "httpOptions": {"options1": "value1"}});
|
|
179
|
+
expect(mockRequest.request.calledWith("dummyBaseUrl/groups/dummyProjectId/clusters/clusterName/fts/indexes/indexId?queryStringParam1=value1", {...requestParams, "options1": "value1"})).to.be.true();
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
describe("When create method is called with querystring parameters and httpOptions", () => {
|
|
184
|
+
it("Should send appropriate parameters to underlying request", async () => {
|
|
185
|
+
const requestParams = {
|
|
186
|
+
"digestAuth": "dummyPublicKey:dummyPrivateKey",
|
|
187
|
+
"dataType": "json",
|
|
188
|
+
"method": "POST",
|
|
189
|
+
"data": {"body": "text"},
|
|
190
|
+
"headers": {"Content-Type": "application/json"}
|
|
191
|
+
};
|
|
192
|
+
await atlasSearch.create("clusterName", {"body": "text"}, {"queryStringParam1": "value1", "httpOptions": {"options1": "value1"}});
|
|
193
|
+
expect(mockRequest.request.calledWith("dummyBaseUrl/groups/dummyProjectId/clusters/clusterName/fts/indexes?queryStringParam1=value1", {...requestParams, "options1": "value1"})).to.be.true();
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
});
|
package/test/atlasUser.test.js
CHANGED
|
@@ -2,6 +2,9 @@ const {describe, it} = exports.lab = require("@hapi/lab").script();
|
|
|
2
2
|
const {expect} = require("@hapi/code");
|
|
3
3
|
const nock = require("nock");
|
|
4
4
|
const getClient = require("../src");
|
|
5
|
+
const AtlasUser = require("../src/atlasUser");
|
|
6
|
+
const HttpClient = require("../src/httpClient");
|
|
7
|
+
const sinon = require("sinon");
|
|
5
8
|
|
|
6
9
|
const baseUrl = "http://dummyBaseUrl";
|
|
7
10
|
const projectId = "dummyProjectId";
|
|
@@ -80,3 +83,66 @@ describe("Mongo Atlas Api Client - Atlas User", () => {
|
|
|
80
83
|
});
|
|
81
84
|
});
|
|
82
85
|
});
|
|
86
|
+
|
|
87
|
+
describe("AtlasUser Class", () => {
|
|
88
|
+
|
|
89
|
+
const mockRequest = {
|
|
90
|
+
"request": sinon.stub().returns(new Promise(resolve => resolve({"data": "some test data"})))
|
|
91
|
+
};
|
|
92
|
+
const mockHttpClient = new HttpClient(mockRequest, "dummyPublicKey", "dummyPrivateKey");
|
|
93
|
+
|
|
94
|
+
const atlasUser = new AtlasUser(mockHttpClient, "dummyBaseUrl", "dummyProjectId");
|
|
95
|
+
|
|
96
|
+
describe("When getByName method is called with querystring parameters and httpOptions", () => {
|
|
97
|
+
it("Should send appropriate parameters to underlying request", async () => {
|
|
98
|
+
const requestParams = {"digestAuth": "dummyPublicKey:dummyPrivateKey", "dataType": "json"};
|
|
99
|
+
await atlasUser.getByName("username", {"queryStringParam1": "value1", "httpOptions": {"options1": "value1"}});
|
|
100
|
+
expect(mockRequest.request.calledWith("dummyBaseUrl/users/byName/username?queryStringParam1=value1", {...requestParams, "options1": "value1"})).to.be.true();
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
describe("When getById method is called with querystring parameters and httpOptions", () => {
|
|
105
|
+
it("Should send appropriate parameters to underlying request", async () => {
|
|
106
|
+
const requestParams = {"digestAuth": "dummyPublicKey:dummyPrivateKey", "dataType": "json"};
|
|
107
|
+
await atlasUser.getById("userId", {"queryStringParam1": "value1", "httpOptions": {"options1": "value1"}});
|
|
108
|
+
expect(mockRequest.request.calledWith("dummyBaseUrl/users/userId?queryStringParam1=value1", {...requestParams, "options1": "value1"})).to.be.true();
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
describe("When getAll method is called with querystring parameters and httpOptions", () => {
|
|
113
|
+
it("Should send appropriate parameters to underlying request", async () => {
|
|
114
|
+
const requestParams = {"digestAuth": "dummyPublicKey:dummyPrivateKey", "dataType": "json"};
|
|
115
|
+
await atlasUser.getAll({"queryStringParam1": "value1", "httpOptions": {"options1": "value1"}});
|
|
116
|
+
expect(mockRequest.request.calledWith("dummyBaseUrl/groups/dummyProjectId/users?queryStringParam1=value1", {...requestParams, "options1": "value1"})).to.be.true();
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
describe("When update method is called with querystring parameters and httpOptions", () => {
|
|
121
|
+
it("Should send appropriate parameters to underlying request", async () => {
|
|
122
|
+
const requestParams = {
|
|
123
|
+
"digestAuth": "dummyPublicKey:dummyPrivateKey",
|
|
124
|
+
"dataType": "json",
|
|
125
|
+
"method": "PATCH",
|
|
126
|
+
"data": {"body": "text"},
|
|
127
|
+
"headers": {"Content-Type": "application/json"}
|
|
128
|
+
};
|
|
129
|
+
await atlasUser.update("userId", {"body": "text"}, {"queryStringParam1": "value1", "httpOptions": {"options1": "value1"}});
|
|
130
|
+
expect(mockRequest.request.calledWith("dummyBaseUrl/users/userId?queryStringParam1=value1", {...requestParams, "options1": "value1"})).to.be.true();
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
describe("When create method is called with querystring parameters and httpOptions", () => {
|
|
135
|
+
it("Should send appropriate parameters to underlying request", async () => {
|
|
136
|
+
const requestParams = {
|
|
137
|
+
"digestAuth": "dummyPublicKey:dummyPrivateKey",
|
|
138
|
+
"dataType": "json",
|
|
139
|
+
"method": "POST",
|
|
140
|
+
"data": {"body": "text"},
|
|
141
|
+
"headers": {"Content-Type": "application/json"}
|
|
142
|
+
};
|
|
143
|
+
await atlasUser.create({"body": "text"}, {"queryStringParam1": "value1", "httpOptions": {"options1": "value1"}});
|
|
144
|
+
expect(mockRequest.request.calledWith("dummyBaseUrl/users?queryStringParam1=value1", {...requestParams, "options1": "value1"})).to.be.true();
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
});
|
package/test/dataLake.test.js
CHANGED
|
@@ -2,7 +2,6 @@ const {describe, it} = exports.lab = require("@hapi/lab").script();
|
|
|
2
2
|
const {expect} = require("@hapi/code");
|
|
3
3
|
const nock = require("nock");
|
|
4
4
|
const getClient = require("../src");
|
|
5
|
-
|
|
6
5
|
const baseUrl = "http://dummyBaseUrl";
|
|
7
6
|
const projectId = "dummyProjectId";
|
|
8
7
|
|
|
@@ -43,7 +42,7 @@ describe("Mongo Atlas Api Client - dataLake", () => {
|
|
|
43
42
|
.get(`/groups/${projectId}/dataLakes/mydataLakename/queryLogs.gz?key1=value1&key2=value2`)
|
|
44
43
|
.reply(200, Buffer.from("Some test string", "utf8"), {"headers": {"accept": "application/gzip"}});
|
|
45
44
|
const result = await client.dataLake.getLogsStream("mydataLakename", {"key1": "value1", "key2": "value2"});
|
|
46
|
-
expect(result).to.
|
|
45
|
+
expect(result.pipe).to.exist();
|
|
47
46
|
expect(expectedRequest.isDone()).to.be.true();
|
|
48
47
|
});
|
|
49
48
|
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const {describe, it} = exports.lab = require("@hapi/lab").script();
|
|
2
|
+
const {expect} = require("@hapi/code");
|
|
3
|
+
const {getQueryStringFromOptions} = require("../src/helper");
|
|
4
|
+
|
|
5
|
+
describe("Helper Methods", () => {
|
|
6
|
+
|
|
7
|
+
describe("When getQueryStringFromOptions is called with emmpty object", () => {
|
|
8
|
+
|
|
9
|
+
it("should return empty string", async () => {
|
|
10
|
+
const result = getQueryStringFromOptions({});
|
|
11
|
+
expect(result).to.equal("");
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
describe("When getQueryStringFromOptions is called without httpOptions but other properties", () => {
|
|
16
|
+
|
|
17
|
+
it("should return other properties as string", async () => {
|
|
18
|
+
const result = getQueryStringFromOptions({"a": 1, "b": 23, "httpOptions": {"key": "value"}});
|
|
19
|
+
expect(result).to.equal("a=1&b=23");
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe("When getQueryStringFromOptions is called with only httpOptions", () => {
|
|
24
|
+
|
|
25
|
+
it("should return empty string", async () => {
|
|
26
|
+
const result = getQueryStringFromOptions({"httpOptions": {"key": "value"}});
|
|
27
|
+
expect(result).to.equal("");
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe("When getQueryStringFromOptions is called without any parameters", () => {
|
|
32
|
+
|
|
33
|
+
it("should return empty string", async () => {
|
|
34
|
+
const result = getQueryStringFromOptions();
|
|
35
|
+
expect(result).to.equal("");
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
});
|