mongodb-atlas-api-client 2.32.0 → 3.0.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.
@@ -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 urlparams = new URLSearchParams(options);
11
- const queryString = urlparams.toString();
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
- ).json();
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 urlparams = new URLSearchParams(options);
20
- const queryString = urlparams.toString();
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
- ).json();
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 urlparams = new URLSearchParams(options);
29
- const queryString = urlparams.toString();
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 urlparams = new URLSearchParams(options);
38
- const queryString = urlparams.toString();
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
- "body": JSON.stringify(body),
43
- "headers": {"Content-Type": "application/json"}
45
+ "data": body,
46
+ "headers": {"Content-Type": "application/json"},
47
+ ...httpOptions
44
48
  })
45
- ).json();
49
+ );
46
50
  return response;
47
51
  }
48
52
 
49
- async create(body, options) {
50
- const urlparams = new URLSearchParams(options);
51
- const queryString = urlparams.toString();
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
- "body": JSON.stringify(body),
56
- "headers": {"Content-Type": "application/json"}
59
+ "data": body,
60
+ "headers": {"Content-Type": "application/json"},
61
+ ...httpOptions
57
62
  })
58
- ).json();
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 urlparams = new URLSearchParams(options);
11
- const queryString = urlparams.toString();
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
- ).json();
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 urlparams = new URLSearchParams(options);
20
- const queryString = urlparams.toString();
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
- ).json();
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 urlparams = new URLSearchParams(options);
29
- const queryString = urlparams.toString();
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 urlparams = new URLSearchParams(options);
38
- const queryString = urlparams.toString();
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
- "body": JSON.stringify(body),
43
- "headers": {"Content-Type": "application/json"}
45
+ "data": body,
46
+ "headers": {"Content-Type": "application/json"},
47
+ ...httpOptions
44
48
  })
45
- ).json();
49
+ );
46
50
  return response;
47
51
  }
48
52
 
49
- async create(body, options) {
50
- const urlparams = new URLSearchParams(options);
51
- const queryString = urlparams.toString();
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
- "body": JSON.stringify(body),
56
- "headers": {"Content-Type": "application/json"}
59
+ "data": body,
60
+ "headers": {"Content-Type": "application/json"},
61
+ ...httpOptions
57
62
  })
58
- ).json();
63
+ );
59
64
  return response;
60
65
  }
61
66
  }
@@ -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
+ });
@@ -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
+ });
@@ -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.be.object();
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
+ });
package/.travis.yml DELETED
@@ -1,6 +0,0 @@
1
- language: node_js
2
- node_js:
3
- - "10"
4
- - "12"
5
- - "14"
6
- script: "npm run travis"