mongodb-atlas-api-client 3.21.0 → 4.0.2

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,12 +1,12 @@
1
- const {describe, it} = exports.lab = require("@hapi/lab").script();
2
- const {expect} = require("@hapi/code");
3
- const nock = require("nock");
4
- const getClient = require("../src");
5
- const AtlasUser = require("../src/atlasUser");
6
- const HttpClient = require("../src/httpClient");
7
- const sinon = require("sinon");
8
-
9
- const baseUrl = "http://dummyBaseUrl";
1
+ const {describe, it, afterEach, before, beforeEach} = exports.lab = require("@hapi/lab").script();
2
+ const {expect} = require('@hapi/code');
3
+ const getClient = require('../src/index.js');
4
+ const AtlasUser = require('../src/atlasUser.js');
5
+ const HttpClient = require('../src/httpClient.js');
6
+ const {stub} = require("sinon");
7
+ const {MockAgent, setGlobalDispatcher} = require('urllib');
8
+
9
+ const baseUrl = "http://localhost:7001";
10
10
  const projectId = "dummyProjectId";
11
11
 
12
12
  const client = getClient({
@@ -18,6 +18,21 @@ const client = getClient({
18
18
 
19
19
  describe("Mongo Atlas Api Client - Atlas User", () => {
20
20
 
21
+ let mockAgent;
22
+ let mockPool;
23
+ before(() => {
24
+ mockAgent = new MockAgent();
25
+ setGlobalDispatcher(mockAgent);
26
+ });
27
+
28
+ beforeEach(() => {
29
+ mockPool = mockAgent.get(baseUrl);
30
+ });
31
+
32
+ afterEach(() => {
33
+ mockAgent.assertNoPendingInterceptors();
34
+ });
35
+
21
36
  describe("When atlasUser is exported from index", () => {
22
37
  it("should export atlasUser functions", async () => {
23
38
  expect(client.atlasUser.getById).to.be.function();
@@ -30,56 +45,63 @@ describe("Mongo Atlas Api Client - Atlas User", () => {
30
45
 
31
46
  describe("When getByName is called with querystring parameters", () => {
32
47
  it("should return response", async () => {
33
- const expectedRequest = nock(baseUrl)
34
- .get("/users/byName/myuser?key1=value1&key2=value2")
48
+ mockPool.intercept({
49
+ "path": "/users/byName/myuser?key1=value1&key2=value2",
50
+ "method": "get"
51
+ })
35
52
  .reply(200, {"user": "name"});
36
53
  const result = await client.atlasUser.getByName("myuser", {"key1": "value1", "key2": "value2"});
37
54
  expect(result).to.equal({"user": "name"});
38
- expect(expectedRequest.isDone()).to.be.true();
39
55
  });
40
56
  });
41
57
 
42
58
  describe("When getById is called with querystring parameters", () => {
43
59
  it("should return response", async () => {
44
- const expectedRequest = nock(baseUrl)
45
- .get("/users/someid?key1=value1&key2=value2")
60
+ mockPool.intercept({
61
+ "path": "/users/someid?key1=value1&key2=value2",
62
+ "method": "get"
63
+ })
46
64
  .reply(200, {"user": "name"});
47
65
  const result = await client.atlasUser.getById("someid", {"key1": "value1", "key2": "value2"});
48
66
  expect(result).to.equal({"user": "name"});
49
- expect(expectedRequest.isDone()).to.be.true();
50
67
  });
51
68
  });
52
69
 
53
70
  describe("When getAll is called with querystring parameters", () => {
54
71
  it("should return response", async () => {
55
- const expectedRequest = nock(baseUrl)
56
- .get(`/groups/${projectId}/users?key1=value1&key2=value2`)
72
+ mockPool.intercept({
73
+ "path": `/groups/${projectId}/users?key1=value1&key2=value2`,
74
+ "method": "get"
75
+ })
57
76
  .reply(200, [{"user": "name"}]);
58
77
  const result = await client.atlasUser.getAll({"key1": "value1", "key2": "value2"});
59
78
  expect(result).to.equal([{"user": "name"}]);
60
- expect(expectedRequest.isDone()).to.be.true();
61
79
  });
62
80
  });
63
81
 
64
82
  describe("When update is called with querystring parameters", () => {
65
83
  it("should return response", async () => {
66
- const expectedRequest = nock(baseUrl)
67
- .patch("/users/someId?key1=value1&key2=value2")
84
+ mockPool.intercept({
85
+ "path": "/users/someId?key1=value1&key2=value2",
86
+ "method": "PATCH",
87
+ "data": {"body": "value"}
88
+ })
68
89
  .reply(200, [{"user": "name"}]);
69
90
  const result = await client.atlasUser.update("someId", {"body": "value"}, {"key1": "value1", "key2": "value2"});
70
91
  expect(result).to.equal([{"user": "name"}]);
71
- expect(expectedRequest.isDone()).to.be.true();
72
92
  });
73
93
  });
74
94
 
75
95
  describe("When create is called with querystring parameters", () => {
76
96
  it("should return response", async () => {
77
- const expectedRequest = nock(baseUrl)
78
- .post("/users?key1=value1&key2=value2")
97
+ mockPool.intercept({
98
+ "path": "/users?key1=value1&key2=value2",
99
+ "method": "POST",
100
+ "data": {"body": "value"}
101
+ })
79
102
  .reply(200, [{"user": "name"}]);
80
103
  const result = await client.atlasUser.create({"body": "value"}, {"key1": "value1", "key2": "value2"});
81
104
  expect(result).to.equal([{"user": "name"}]);
82
- expect(expectedRequest.isDone()).to.be.true();
83
105
  });
84
106
  });
85
107
  });
@@ -87,7 +109,7 @@ describe("Mongo Atlas Api Client - Atlas User", () => {
87
109
  describe("AtlasUser Class", () => {
88
110
 
89
111
  const mockRequest = {
90
- "request": sinon.stub().returns(new Promise(resolve => resolve({"data": "some test data"})))
112
+ "request": stub().returns(new Promise(resolve => resolve({"data": "some test data"})))
91
113
  };
92
114
  const mockHttpClient = new HttpClient(mockRequest, "dummyPublicKey", "dummyPrivateKey");
93
115
 
@@ -1,9 +1,9 @@
1
- const {describe, it} = exports.lab = require("@hapi/lab").script();
2
- const {expect} = require("@hapi/code");
3
- const nock = require("nock");
4
- const getClient = require("../src");
1
+ const {describe, it, afterEach, before, beforeEach} = exports.lab = require("@hapi/lab").script();
2
+ const {expect} = require('@hapi/code');
3
+ const getClient = require('../src/index.js');
4
+ const {MockAgent, setGlobalDispatcher} = require('urllib');
5
5
 
6
- const baseUrl = "http://dummyBaseUrl";
6
+ const baseUrl = "http://localhost:7001";
7
7
  const projectId = "dummyProjectId";
8
8
 
9
9
  const client = getClient({
@@ -15,6 +15,21 @@ const client = getClient({
15
15
 
16
16
  describe("Mongo Atlas Api Client - cloudProviderAccess", () => {
17
17
 
18
+ let mockAgent;
19
+ let mockPool;
20
+ before(() => {
21
+ mockAgent = new MockAgent();
22
+ setGlobalDispatcher(mockAgent);
23
+ });
24
+
25
+ beforeEach(() => {
26
+ mockPool = mockAgent.get(baseUrl);
27
+ });
28
+
29
+ afterEach(() => {
30
+ mockAgent.assertNoPendingInterceptors();
31
+ });
32
+
18
33
  describe("When cloudProviderAccess is exported from index", () => {
19
34
  it("should export cloudProviderAccess functions", async () => {
20
35
  expect(client.cloudProviderAccess.getAll).to.be.function();
@@ -26,45 +41,55 @@ describe("Mongo Atlas Api Client - cloudProviderAccess", () => {
26
41
 
27
42
  describe("When getAll is called with querystring parameters", () => {
28
43
  it("should return response", async () => {
29
- const expectedRequest = nock(baseUrl)
30
- .get(`/groups/${projectId}/cloudProviderAccess?key1=value1&key2=value2`)
44
+ mockPool.intercept({
45
+ "path": `/groups/${projectId}/cloudProviderAccess?key1=value1&key2=value2`,
46
+ "method": "GET"
47
+ })
31
48
  .reply(200, [{"cloudProviderAccess": "name"}]);
32
49
  const result = await client.cloudProviderAccess.getAll({"key1": "value1", "key2": "value2"});
33
50
  expect(result).to.equal([{"cloudProviderAccess": "name"}]);
34
- expect(expectedRequest.isDone()).to.be.true();
51
+
35
52
  });
36
53
  });
37
54
 
38
55
  describe("When update is called with querystring parameters", () => {
39
56
  it("should return response", async () => {
40
- const expectedRequest = nock(baseUrl)
41
- .patch(`/groups/${projectId}/cloudProviderAccess/roleId?key1=value1&key2=value2`)
57
+ mockPool.intercept({
58
+ "path": `/groups/${projectId}/cloudProviderAccess/roleId?key1=value1&key2=value2`,
59
+ "method": "PATCH",
60
+ "data": {"body": "value"}
61
+ })
42
62
  .reply(200, [{"cloudProviderAccess": "name"}]);
43
63
  const result = await client.cloudProviderAccess.update("roleId", {"body": "value"}, {"key1": "value1", "key2": "value2"});
44
64
  expect(result).to.equal([{"cloudProviderAccess": "name"}]);
45
- expect(expectedRequest.isDone()).to.be.true();
65
+
46
66
  });
47
67
  });
48
68
 
49
69
  describe("When create is called with querystring parameters", () => {
50
70
  it("should return response", async () => {
51
- const expectedRequest = nock(baseUrl)
52
- .post(`/groups/${projectId}/cloudProviderAccess?key1=value1&key2=value2`)
71
+ mockPool.intercept({
72
+ "path": `/groups/${projectId}/cloudProviderAccess?key1=value1&key2=value2`,
73
+ "method": "POST",
74
+ "data": {"body": "value"}
75
+ })
53
76
  .reply(200, [{"cloudProviderAccess": "name"}]);
54
77
  const result = await client.cloudProviderAccess.create({"body": "value"}, {"key1": "value1", "key2": "value2"});
55
78
  expect(result).to.equal([{"cloudProviderAccess": "name"}]);
56
- expect(expectedRequest.isDone()).to.be.true();
79
+
57
80
  });
58
81
  });
59
82
 
60
83
  describe("When delete is called with querystring parameters", () => {
61
84
  it("should return response", async () => {
62
- const expectedRequest = nock(baseUrl)
63
- .delete(`/groups/${projectId}/cloudProviderAccess/aws/roleId?key1=value1&key2=value2`)
85
+ mockPool.intercept({
86
+ "path": `/groups/${projectId}/cloudProviderAccess/aws/roleId?key1=value1&key2=value2`,
87
+ "method": "DELETE"
88
+ })
64
89
  .reply(200, true);
65
90
  const result = await client.cloudProviderAccess.delete("aws", "roleId", {"key1": "value1", "key2": "value2"});
66
91
  expect(result).to.be.true();
67
- expect(expectedRequest.isDone()).to.be.true();
92
+
68
93
  });
69
94
  });
70
95
  });
@@ -1,9 +1,9 @@
1
- const {describe, it} = exports.lab = require("@hapi/lab").script();
2
- const {expect} = require("@hapi/code");
3
- const nock = require("nock");
4
- const getClient = require("../src");
1
+ const {describe, it, afterEach, before, beforeEach} = exports.lab = require("@hapi/lab").script();
2
+ const {expect} = require('@hapi/code');
3
+ const getClient = require('../src/index.js');
4
+ const {MockAgent, setGlobalDispatcher} = require('urllib');
5
5
 
6
- const baseUrl = "http://dummyBaseUrl";
6
+ const baseUrl = "http://localhost:7001";
7
7
  const projectId = "dummyProjectId";
8
8
 
9
9
  const client = getClient({
@@ -15,6 +15,21 @@ const client = getClient({
15
15
 
16
16
  describe("Mongo Atlas Api Client - CloudBackup", () => {
17
17
 
18
+ let mockAgent;
19
+ let mockPool;
20
+ before(() => {
21
+ mockAgent = new MockAgent();
22
+ setGlobalDispatcher(mockAgent);
23
+ });
24
+
25
+ beforeEach(() => {
26
+ mockPool = mockAgent.get(baseUrl);
27
+ });
28
+
29
+ afterEach(() => {
30
+ mockAgent.assertNoPendingInterceptors();
31
+ });
32
+
18
33
  describe("When cluster is exported from index", () => {
19
34
  it("should export cluster functions", async () => {
20
35
  expect(client.cloudBackup.getReplicaSetCloudBackup).to.be.function();
@@ -26,45 +41,54 @@ describe("Mongo Atlas Api Client - CloudBackup", () => {
26
41
 
27
42
  describe("When getReplicaSetCloudBackup is called with querystring parameters", () => {
28
43
  it("should return response", async () => {
29
- const expectedRequest = nock(baseUrl)
30
- .get(`/groups/${projectId}/clusters/mycluster/backup/snapshots/mysnapshot?key1=value1&key2=value2`)
44
+ mockPool.intercept({
45
+ "path": `/groups/${projectId}/clusters/mycluster/backup/snapshots/mysnapshot?key1=value1&key2=value2`,
46
+ "method": "get"
47
+ })
31
48
  .reply(200, {"replicaSetName": "mycluster"});
32
49
  const result = await client.cloudBackup.getReplicaSetCloudBackup("mycluster", "mysnapshot", {"key1": "value1", "key2": "value2"});
33
50
  expect(result).to.equal({"replicaSetName": "mycluster"});
34
- expect(expectedRequest.isDone()).to.be.true();
51
+
35
52
  });
36
53
  });
37
54
 
38
55
  describe("When getAllReplicaSetCloudBackups is called with querystring parameters", () => {
39
56
  it("should return response", async () => {
40
- const expectedRequest = nock(baseUrl)
41
- .get(`/groups/${projectId}/clusters/mycluster/backup/snapshots?key1=value1&key2=value2`)
57
+ mockPool.intercept({
58
+ "path": `/groups/${projectId}/clusters/mycluster/backup/snapshots?key1=value1&key2=value2`,
59
+ "method": "get"
60
+ })
42
61
  .reply(200, [{"replicaSetName": "mycluster"}]);
43
62
  const result = await client.cloudBackup.getAllReplicaSetCloudBackups("mycluster", {"key1": "value1", "key2": "value2"});
44
63
  expect(result).to.equal([{"replicaSetName": "mycluster"}]);
45
- expect(expectedRequest.isDone()).to.be.true();
64
+
46
65
  });
47
66
  });
48
67
 
49
68
  describe("When getSnapshotRestoreJob is called with querystring parameters", () => {
50
69
  it("should return response", async () => {
51
- const expectedRequest = nock(baseUrl)
52
- .get(`/groups/${projectId}/clusters/mycluster/backup/restoreJobs/myrestorejob?key1=value1&key2=value2`)
70
+ mockPool.intercept({
71
+ "path": `/groups/${projectId}/clusters/mycluster/backup/restoreJobs/myrestorejob?key1=value1&key2=value2`,
72
+ "method": "get"
73
+ })
53
74
  .reply(200, {"id": "myrestorejob"});
54
75
  const result = await client.cloudBackup.getSnapshotRestoreJob("mycluster", "myrestorejob", {"key1": "value1", "key2": "value2"});
55
76
  expect(result).to.equal({"id": "myrestorejob"});
56
- expect(expectedRequest.isDone()).to.be.true();
77
+
57
78
  });
58
79
  });
59
80
 
60
81
  describe("When createSnapshotRestoreJob is called with querystring parameters", () => {
61
82
  it("should return response", async () => {
62
- const expectedRequest = nock(baseUrl)
63
- .post(`/groups/${projectId}/clusters/mycluster/backup/restoreJobs?key1=value1&key2=value2`)
83
+ mockPool.intercept({
84
+ "path": `/groups/${projectId}/clusters/mycluster/backup/restoreJobs?key1=value1&key2=value2`,
85
+ "method": "post",
86
+ "data": {"body": "value"}
87
+ })
64
88
  .reply(200, {"id": "myrestorejob"});
65
89
  const result = await client.cloudBackup.createSnapshotRestoreJob("mycluster", {"body": "value"}, {"key1": "value1", "key2": "value2"});
66
90
  expect(result).to.equal({"id": "myrestorejob"});
67
- expect(expectedRequest.isDone()).to.be.true();
91
+
68
92
  });
69
93
  });
70
94
  });
@@ -1,9 +1,9 @@
1
- const {describe, it} = exports.lab = require("@hapi/lab").script();
2
- const {expect} = require("@hapi/code");
3
- const nock = require("nock");
4
- const getClient = require("../src");
1
+ const {describe, it, afterEach, before, beforeEach} = exports.lab = require("@hapi/lab").script();
2
+ const {expect} = require('@hapi/code');
3
+ const getClient = require('../src/index.js');
4
+ const {MockAgent, setGlobalDispatcher} = require('urllib');
5
5
 
6
- const baseUrl = "http://dummyBaseUrl";
6
+ const baseUrl = "http://localhost:7001";
7
7
  const projectId = "dummyProjectId";
8
8
 
9
9
  const client = getClient({
@@ -15,6 +15,21 @@ const client = getClient({
15
15
 
16
16
  describe("Mongo Atlas Api Client - Cluster", () => {
17
17
 
18
+ let mockAgent;
19
+ let mockPool;
20
+ before(() => {
21
+ mockAgent = new MockAgent();
22
+ setGlobalDispatcher(mockAgent);
23
+ });
24
+
25
+ beforeEach(() => {
26
+ mockPool = mockAgent.get(baseUrl);
27
+ });
28
+
29
+ afterEach(() => {
30
+ mockAgent.assertNoPendingInterceptors();
31
+ });
32
+
18
33
  describe("When cluster is exported from index", () => {
19
34
  it("should export cluster functions", async () => {
20
35
  expect(client.cluster.get).to.be.function();
@@ -30,89 +45,109 @@ describe("Mongo Atlas Api Client - Cluster", () => {
30
45
 
31
46
  describe("When get is called with querystring parameters", () => {
32
47
  it("should return response", async () => {
33
- const expectedRequest = nock(baseUrl)
34
- .get(`/groups/${projectId}/clusters/mycluster?key1=value1&key2=value2`)
48
+ mockPool.intercept({
49
+ "path": `/groups/${projectId}/clusters/mycluster?key1=value1&key2=value2`,
50
+ "method": "get"
51
+ })
35
52
  .reply(200, {"cluster": "name"});
36
53
  const result = await client.cluster.get("mycluster", {"key1": "value1", "key2": "value2"});
37
54
  expect(result).to.equal({"cluster": "name"});
38
- expect(expectedRequest.isDone()).to.be.true();
55
+
39
56
  });
40
57
  });
41
58
 
42
59
  describe("When getAdvanceConfiguration is called with querystring parameters", () => {
43
60
  it("should return response", async () => {
44
- const expectedRequest = nock(baseUrl)
45
- .get(`/groups/${projectId}/clusters/mycluster/processArgs?key1=value1&key2=value2`)
61
+ mockPool.intercept({
62
+ "path": `/groups/${projectId}/clusters/mycluster/processArgs?key1=value1&key2=value2`,
63
+ "method": "get"
64
+ })
46
65
  .reply(200, {"cluster": "name"});
47
66
  const result = await client.cluster.getAdvanceConfiguration("mycluster", {"key1": "value1", "key2": "value2"});
48
67
  expect(result).to.equal({"cluster": "name"});
49
- expect(expectedRequest.isDone()).to.be.true();
68
+
50
69
  });
51
70
  });
52
71
 
53
72
  describe("When getAll is called with querystring parameters", () => {
54
73
  it("should return response", async () => {
55
- const expectedRequest = nock(baseUrl)
56
- .get(`/groups/${projectId}/clusters?key1=value1&key2=value2`)
74
+ mockPool.intercept({
75
+ "path": `/groups/${projectId}/clusters?key1=value1&key2=value2`,
76
+ "method": "get"
77
+ })
57
78
  .reply(200, [{"cluster": "name"}]);
58
79
  const result = await client.cluster.getAll({"key1": "value1", "key2": "value2"});
59
80
  expect(result).to.equal([{"cluster": "name"}]);
60
- expect(expectedRequest.isDone()).to.be.true();
81
+
61
82
  });
62
83
  });
63
84
 
64
85
  describe("When update is called with querystring parameters", () => {
65
86
  it("should return response", async () => {
66
- const expectedRequest = nock(baseUrl)
67
- .patch(`/groups/${projectId}/clusters/myCluster?key1=value1&key2=value2`)
87
+ mockPool.intercept({
88
+ "path": `/groups/${projectId}/clusters/myCluster?key1=value1&key2=value2`,
89
+ "method": "patch",
90
+ "data": {"body": "value"}
91
+ })
68
92
  .reply(200, [{"cluster": "name"}]);
69
93
  const result = await client.cluster.update("myCluster", {"body": "value"}, {"key1": "value1", "key2": "value2"});
70
94
  expect(result).to.equal([{"cluster": "name"}]);
71
- expect(expectedRequest.isDone()).to.be.true();
95
+
72
96
  });
73
97
  });
74
98
 
75
99
  describe("When updateAdvanceConfiguration is called with querystring parameters", () => {
76
100
  it("should return response", async () => {
77
- const expectedRequest = nock(baseUrl)
78
- .patch(`/groups/${projectId}/clusters/myCluster/processArgs?key1=value1&key2=value2`)
101
+ mockPool.intercept({
102
+ "path": `/groups/${projectId}/clusters/myCluster/processArgs?key1=value1&key2=value2`,
103
+ "method": "patch",
104
+ "data": {"body": "value"}
105
+ })
79
106
  .reply(200, [{"cluster": "name"}]);
80
107
  const result = await client.cluster.updateAdvanceConfiguration("myCluster", {"body": "value"}, {"key1": "value1", "key2": "value2"});
81
108
  expect(result).to.equal([{"cluster": "name"}]);
82
- expect(expectedRequest.isDone()).to.be.true();
109
+
83
110
  });
84
111
  });
85
112
 
86
113
  describe("When create is called with querystring parameters", () => {
87
114
  it("should return response", async () => {
88
- const expectedRequest = nock(baseUrl)
89
- .post(`/groups/${projectId}/clusters?key1=value1&key2=value2`)
115
+ mockPool.intercept({
116
+ "path": `/groups/${projectId}/clusters?key1=value1&key2=value2`,
117
+ "method": "post",
118
+ "data": {"body": "value"}
119
+ })
90
120
  .reply(200, [{"cluster": "name"}]);
91
121
  const result = await client.cluster.create({"body": "value"}, {"key1": "value1", "key2": "value2"});
92
122
  expect(result).to.equal([{"cluster": "name"}]);
93
- expect(expectedRequest.isDone()).to.be.true();
123
+
94
124
  });
95
125
  });
96
126
 
97
127
  describe("When testPrimaryFailOver is called with querystring parameters", () => {
98
128
  it("should return response", async () => {
99
- const expectedRequest = nock(baseUrl)
100
- .post(`/groups/${projectId}/clusters/mycluster/restartPrimaries?key1=value1&key2=value2`)
129
+ mockPool.intercept({
130
+ "path": `/groups/${projectId}/clusters/mycluster/restartPrimaries?key1=value1&key2=value2`,
131
+ "method": "post",
132
+ "data": {"body": "value"}
133
+ })
101
134
  .reply(200, [{"cluster": "name"}]);
102
135
  const result = await client.cluster.testPrimaryFailOver("mycluster", {"key1": "value1", "key2": "value2"});
103
136
  expect(result).to.equal([{"cluster": "name"}]);
104
- expect(expectedRequest.isDone()).to.be.true();
137
+
105
138
  });
106
139
  });
107
140
 
108
141
  describe("When delete is called with querystring parameters", () => {
109
142
  it("should return response", async () => {
110
- const expectedRequest = nock(baseUrl)
111
- .delete(`/groups/${projectId}/clusters/mycluster?key1=value1&key2=value2`)
143
+ mockPool.intercept({
144
+ "path": `/groups/${projectId}/clusters/mycluster?key1=value1&key2=value2`,
145
+ "method": "delete"
146
+ })
112
147
  .reply(200, true);
113
148
  const result = await client.cluster.delete("mycluster", {"key1": "value1", "key2": "value2"});
114
149
  expect(result).to.be.true();
115
- expect(expectedRequest.isDone()).to.be.true();
150
+
116
151
  });
117
152
  });
118
153
  });
@@ -1,9 +1,9 @@
1
- const {describe, it} = exports.lab = require("@hapi/lab").script();
2
- const {expect} = require("@hapi/code");
3
- const nock = require("nock");
4
- const getClient = require("../src");
1
+ const {describe, it, afterEach, before, beforeEach} = exports.lab = require("@hapi/lab").script();
2
+ const {expect} = require('@hapi/code');
3
+ const getClient = require('../src/index.js');
4
+ const {MockAgent, setGlobalDispatcher} = require('urllib');
5
5
 
6
- const baseUrl = "http://dummyBaseUrl";
6
+ const baseUrl = "http://localhost:7001";
7
7
  const projectId = "dummyProjectId";
8
8
 
9
9
  const client = getClient({
@@ -15,6 +15,21 @@ const client = getClient({
15
15
 
16
16
  describe("Mongo Atlas Api Client - Custom Db Role", () => {
17
17
 
18
+ let mockAgent;
19
+ let mockPool;
20
+ before(() => {
21
+ mockAgent = new MockAgent();
22
+ setGlobalDispatcher(mockAgent);
23
+ });
24
+
25
+ beforeEach(() => {
26
+ mockPool = mockAgent.get(baseUrl);
27
+ });
28
+
29
+ afterEach(() => {
30
+ mockAgent.assertNoPendingInterceptors();
31
+ });
32
+
18
33
  describe("When customDbRole is exported from index", () => {
19
34
  it("should export customDbRole functions", async () => {
20
35
  expect(client.customDbRole.get).to.be.function();
@@ -27,56 +42,68 @@ describe("Mongo Atlas Api Client - Custom Db Role", () => {
27
42
 
28
43
  describe("When get is called with querystring parameters", () => {
29
44
  it("should return response", async () => {
30
- const expectedRequest = nock(baseUrl)
31
- .get(`/groups/${projectId}/customDBRoles/roles/rolename?key1=value1&key2=value2`)
45
+ mockPool.intercept({
46
+ "path": `/groups/${projectId}/customDBRoles/roles/rolename?key1=value1&key2=value2`,
47
+ "method": "get"
48
+ })
32
49
  .reply(200, {"customDbRole": "name"});
33
50
  const result = await client.customDbRole.get("rolename", {"key1": "value1", "key2": "value2"});
34
51
  expect(result).to.equal({"customDbRole": "name"});
35
- expect(expectedRequest.isDone()).to.be.true();
52
+
36
53
  });
37
54
  });
38
55
 
39
56
  describe("When getAll is called with querystring parameters", () => {
40
57
  it("should return response", async () => {
41
- const expectedRequest = nock(baseUrl)
42
- .get(`/groups/${projectId}/customDBRoles/roles?key1=value1&key2=value2`)
58
+ mockPool.intercept({
59
+ "path": `/groups/${projectId}/customDBRoles/roles?key1=value1&key2=value2`,
60
+ "method": "get"
61
+ })
43
62
  .reply(200, [{"customDbRole": "name"}]);
44
63
  const result = await client.customDbRole.getAll({"key1": "value1", "key2": "value2"});
45
64
  expect(result).to.equal([{"customDbRole": "name"}]);
46
- expect(expectedRequest.isDone()).to.be.true();
65
+
47
66
  });
48
67
  });
49
68
 
50
69
  describe("When update is called with querystring parameters", () => {
51
70
  it("should return response", async () => {
52
- const expectedRequest = nock(baseUrl)
53
- .patch(`/groups/${projectId}/customDBRoles/roles/rolename?key1=value1&key2=value2`)
71
+ mockPool.intercept({
72
+ "path": `/groups/${projectId}/customDBRoles/roles/rolename?key1=value1&key2=value2`,
73
+ "method": "PATCH",
74
+ "data": {"body": "value"}
75
+ })
54
76
  .reply(200, [{"customDbRole": "name"}]);
55
77
  const result = await client.customDbRole.update("rolename", {"body": "value"}, {"key1": "value1", "key2": "value2"});
56
78
  expect(result).to.equal([{"customDbRole": "name"}]);
57
- expect(expectedRequest.isDone()).to.be.true();
79
+
58
80
  });
59
81
  });
60
82
 
61
83
  describe("When delete is called with querystring parameters", () => {
62
84
  it("should return response", async () => {
63
- const expectedRequest = nock(baseUrl)
64
- .delete(`/groups/${projectId}/customDBRoles/roles/rolename?key1=value1&key2=value2`)
85
+ mockPool.intercept({
86
+ "path": `/groups/${projectId}/customDBRoles/roles/rolename?key1=value1&key2=value2`,
87
+ "method": "delete"
88
+ })
65
89
  .reply(200, true);
66
90
  const result = await client.customDbRole.delete("rolename", {"key1": "value1", "key2": "value2"});
67
91
  expect(result).to.be.true();
68
- expect(expectedRequest.isDone()).to.be.true();
92
+
69
93
  });
70
94
  });
71
95
 
72
96
  describe("When create is called with querystring parameters", () => {
73
97
  it("should return response", async () => {
74
- const expectedRequest = nock(baseUrl)
75
- .post(`/groups/${projectId}/customDBRoles/roles?key1=value1&key2=value2`)
98
+ mockPool.intercept({
99
+ "path": `/groups/${projectId}/customDBRoles/roles?key1=value1&key2=value2`,
100
+ "method": "post",
101
+ "data": {"body": "value"}
102
+ })
76
103
  .reply(200, [{"customDbRole": "name"}]);
77
104
  const result = await client.customDbRole.create({"body": "value"}, {"key1": "value1", "key2": "value2"});
78
105
  expect(result).to.equal([{"customDbRole": "name"}]);
79
- expect(expectedRequest.isDone()).to.be.true();
106
+
80
107
  });
81
108
  });
82
109
  });