mongodb-atlas-api-client 3.21.0 → 4.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.
@@ -8,7 +8,7 @@ jobs:
8
8
  runs-on: ubuntu-latest
9
9
  strategy:
10
10
  matrix:
11
- node: [ 14, 16, 18 ]
11
+ node: [ 18, 20, 22 ]
12
12
  name: Node ${{ matrix.node }} sample
13
13
  steps:
14
14
  - uses: actions/checkout@v3
@@ -0,0 +1,20 @@
1
+ name: Run tests on pull request create/update
2
+
3
+ on:
4
+ pull_request:
5
+
6
+ jobs:
7
+ build:
8
+ runs-on: ubuntu-latest
9
+ strategy:
10
+ matrix:
11
+ node: [ 18, 20, 22 ]
12
+ name: Node ${{ matrix.node }} sample
13
+ steps:
14
+ - uses: actions/checkout@v3
15
+ - name: Setup node
16
+ uses: actions/setup-node@v3
17
+ with:
18
+ node-version: ${{ matrix.node }}
19
+ - run: npm install
20
+ - run: npm test
@@ -14,7 +14,7 @@ jobs:
14
14
  fetch-depth: 0 # otherwise, you will failed to push refs to dest repo:
15
15
  - uses: actions/setup-node@v1
16
16
  with:
17
- node-version: 16
17
+ node-version: 20
18
18
  registry-url: https://registry.npmjs.org/
19
19
  - run: npm install
20
20
  - run: npm test
@@ -0,0 +1,251 @@
1
+ // eslint.config.js
2
+ const pluginJs = require("@eslint/js");
3
+
4
+ module.export = [
5
+ pluginJs.configs.recommended,
6
+ {
7
+ "rules": {
8
+ // Possible Errors
9
+ // The following rules point out areas where you might have made mistakes.
10
+
11
+ "comma-dangle": [2, "never"], // - disallow or enforce trailing commas (recommended)
12
+ "getter-return": 2, // - enforces that a return statement is present in property getters
13
+ "no-async-promise-executor": 2, // - disallow using an async function as a Promise executor
14
+ "no-await-in-loop": 2, // - disallow await inside of loops
15
+ "no-compare-neg-zero": 2, // - disallow checking for equality against negative zero
16
+ "no-cond-assign": 2, // - disallow assignment in conditional expressions (recommended)
17
+ "no-console": 2, // - disallow use of console in the node environment (recommended)
18
+ "no-constant-condition": 2, // - disallow use of constant expressions in conditions (recommended)
19
+ "no-control-regex": 2, // - disallow control characters in regular expressions (recommended)
20
+ "no-debugger": 2, // - disallow use of debugger (recommended)
21
+ "no-dupe-args": 2, // - disallow duplicate arguments in functions (recommended)
22
+ "no-dupe-keys": 2, // - disallow duplicate keys when creating object literals (recommended)
23
+ "no-duplicate-case": 2, // - disallow a duplicate case label. (recommended)
24
+ "no-empty-character-class": 2, // - disallow the use of empty character classes in regular expressions (recommended)
25
+ "no-empty": 2, // - disallow empty statements (recommended)
26
+ "no-ex-assign": 2, // - disallow assigning to the exception in a catch block (recommended)
27
+ "no-extra-boolean-cast": 2, // - disallow double-negation boolean casts in a boolean context (recommended)
28
+ "no-extra-parens": 0, // - disallow unnecessary parentheses
29
+ "no-extra-semi": 2, // - disallow unnecessary semicolons (recommended)
30
+ "no-func-assign": 2, // - disallow overwriting functions written as function declarations (recommended)
31
+ "no-inner-declarations": [2, "functions"], // - disallow function or variable declarations in nested blocks (recommended)
32
+ "no-invalid-regexp": 2, // - disallow invalid regular expression strings in the RegExp constructor (recommended)
33
+ "no-irregular-whitespace": 2, // - disallow irregular whitespace outside of strings and comments (recommended)
34
+ "no-negated-in-lhs": 2, // - disallow negation of the left operand of an in expression (recommended)
35
+ "no-obj-calls": 2, // - disallow the use of object properties of the global object (Math and JSON) as functions (recommended)
36
+ "no-regex-spaces": 2, // - disallow multiple spaces in a regular expression literal (recommended)
37
+ "no-sparse-arrays": 0, // - disallow sparse arrays (recommended) Note: set to false because array destructuring in ES6
38
+ "no-unreachable": 2, // - disallow unreachable statements after a return, throw, continue, or break statement (recommended)
39
+ "use-isnan": 2, // - disallow comparisons with the value NaN (recommended)
40
+ "valid-typeof": 2, // - Ensure that the results of typeof are compared against a valid string (recommended)
41
+ "no-unexpected-multiline": 2, // - Avoid code that looks like two expressions but is actually one
42
+
43
+ // Best Practices
44
+ // These are rules designed to prevent you from making mistakes. They either prescribe a better way of doing something or help you avoid footguns.
45
+
46
+ "accessor-pairs": 2, // - Enforces getter/setter pairs in objects
47
+ "block-scoped-var": 0, // - treat var statements as if they were block scoped
48
+ "complexity": [1, 9], // - specify the maximum cyclomatic complexity allowed in a program
49
+ "consistent-return": 1, // - require return statements to either always or never specify values
50
+ "curly": [2, "all"], // - specify curly brace conventions for all control statements
51
+ "default-case": 0, // - require default case in switch statements
52
+ "dot-notation": 2, // - encourages use of dot notation whenever possible
53
+ "dot-location": [2, "property"], // - enforces consistent newlines before or after dots
54
+ "eqeqeq": 2, // - require the use of === and !==
55
+ "guard-for-in": 2, // - make sure for-in loops have an if statement
56
+ "no-alert": 2, // - disallow the use of alert, confirm, and prompt
57
+ "no-caller": 2, // - disallow use of arguments.caller or arguments.callee
58
+ "no-div-regex": 2, // - disallow division operators explicitly at beginning of regular expression
59
+ "no-else-return": 2, // - disallow else after a return in an if
60
+ "no-eq-null": 2, // - disallow comparisons to null without a type-checking operator
61
+ "no-eval": 2, // - disallow use of eval()
62
+ "no-extend-native": 2, // - disallow adding to native types
63
+ "no-extra-bind": 2, // - disallow unnecessary function binding
64
+ "no-fallthrough": 2, // - disallow fallthrough of case statements (recommended)
65
+ "no-floating-decimal": 2, // - disallow the use of leading or trailing decimal points in numeric literals
66
+ "no-implicit-coercion": 2, // - disallow the type conversions with shorter notations
67
+ "no-implied-eval": 2, // - disallow use of eval()-like methods
68
+ "no-invalid-this": 2, // - disallow this keywords outside of classes or class-like objects
69
+ "no-iterator": 2, // - disallow usage of __iterator__ property
70
+ "no-labels": 2, // - disallow use of labeled statements
71
+ "no-lone-blocks": 2, // - disallow unnecessary nested blocks
72
+ "no-loop-func": 2, // - disallow creation of functions within loops
73
+ "no-multi-spaces": [
74
+ 2,
75
+ {
76
+ "ignoreEOLComments": true
77
+ }
78
+ ], // - disallow use of multiple spaces
79
+ "no-multi-str": 2, // - disallow use of multiline strings
80
+ "no-native-reassign": 2, // - disallow reassignments of native objects
81
+ "no-new-func": 2, // - disallow use of new operator for Function object
82
+ "no-new-wrappers": 2, // - disallows creating new instances of String,Number, and Boolean
83
+ "no-new": 2, // - disallow use of the new operator when not part of an assignment or comparison
84
+ "no-octal-escape": 2, // - disallow use of octal escape sequences in string literals, such as var foo = "Copyright \251";
85
+ "no-octal": 2, // - disallow use of octal literals (recommended)
86
+ "no-param-reassign": 2, // - disallow reassignment of function parameters
87
+ "no-process-env": 2, // - disallow use of process.env
88
+ "no-proto": 2, // - disallow usage of __proto__ property
89
+ "no-redeclare": 2, // - disallow declaring the same variable more than once (recommended)
90
+ "no-return-assign": 2, // - disallow use of assignment in return statement
91
+ "no-return-await": 2, // - disallows unnecessary return await
92
+ "no-script-url": 2, // - disallow use of javascript: urls.
93
+ "no-self-assign": 2, // - disallow Self Assignment
94
+ "no-self-compare": 2, // - disallow comparisons where both sides are exactly the same
95
+ "no-sequences": 2, // - disallow use of the comma operator
96
+ "no-throw-literal": 2, // - restrict what can be thrown as an exception
97
+ "no-unused-expressions": 0, // - disallow usage of expressions in statement position
98
+ "no-useless-call": 2, // - disallow unnecessary .call() and .apply()
99
+ "no-void": 2, // - disallow use of the void operator
100
+ "no-warning-comments": 0, // - disallow usage of configurable warning terms in comments - e.g. TODO or FIXME
101
+ "no-with": 2, // - disallow use of the with statement
102
+ "radix": 2, // - require use of the second argument for parseInt()
103
+ "vars-on-top": 2, // - require declaration of all vars at the top of their containing scope
104
+ "wrap-iife": 2, // - require immediate function invocation to be wrapped in parentheses
105
+ "yoda": 2, // - require or disallow Yoda conditions
106
+
107
+ // Strict Mode
108
+ // These rules relate to using strict mode.
109
+
110
+ "strict": [2, "global"], // - controls location of Use Strict Directives
111
+
112
+ // Variables
113
+ // These rules have to do with variable declarations.
114
+
115
+ "init-declarations": 0, // - enforce or disallow variable initializations at definition
116
+ "no-catch-shadow": 2, // - disallow the catch clause parameter name being the same as a variable in the outer scope
117
+ "no-delete-var": 2, // - disallow deletion of variables (recommended)
118
+ "no-label-var": 2, // - disallow labels that share a name with a variable
119
+ "no-shadow-restricted-names": 2, // - disallow shadowing of names such as arguments
120
+ "no-shadow": 2, // - disallow declaration of variables already declared in the outer scope
121
+ "no-undef-init": 2, // - disallow use of undefined when initializing variables
122
+ "no-undef": 2, // - disallow use of undeclared variables unless mentioned in a /*global */ block (recommended)
123
+ "no-undefined": 0, // - disallow use of undefined variable
124
+ "no-unused-vars": 2, // - disallow declaration of variables that are not used in the code (recommended)
125
+ "no-use-before-define": 2, // - disallow use of variables before they are defined
126
+
127
+ // Node.js
128
+ // These rules are specific to JavaScript running on Node.js.
129
+
130
+ "callback-return": 2, // - enforce return after a callback
131
+ "global-require": 2, // - enforce require() on the top-level module scope
132
+ "handle-callback-err": 2, // - enforce error handling in callbacks
133
+ "no-mixed-requires": 2, // - disallow mixing regular variable and require declarations
134
+ "no-new-require": 2, // - disallow use of new operator with the require function
135
+ "no-path-concat": 2, // - disallow string concatenation with __dirname and __filename
136
+ "no-process-exit": 2, // - disallow process.exit()
137
+ "no-restricted-modules": 2, // - restrict usage of specified node modules
138
+ "no-sync": 2, // - disallow use of synchronous methods
139
+ "no-buffer-constructor": 2, // - disallow use of the deprecated Buffer() constructor
140
+
141
+ // Stylistic Issues
142
+ // These rules are purely matters of style and are quite subjective.
143
+
144
+ "array-bracket-spacing": 2, // - enforce spacing inside array brackets
145
+ "brace-style": 2, // - enforce one true brace style
146
+ "camelcase": 2, // - require camel case names
147
+ "comma-spacing": 2, // - enforce spacing before and after comma
148
+ "comma-style": 2, // - enforce one true comma style
149
+ "computed-property-spacing": 2, // - require or disallow padding inside computed properties
150
+ "consistent-this": 2, // - enforce consistent naming when capturing the current execution context
151
+ "eol-last": 2, // - enforce newline at the end of file, with no multiple empty lines
152
+ "func-names": 0, // - require function expressions to have a name
153
+ "func-style": [2, "declaration"], // - enforce use of function declarations or expressions
154
+ "id-length": [2,
155
+ {
156
+ "min": 2,
157
+ "max": 70,
158
+ "exceptions": ["i", "j", "k", "n", "Q", "_"]
159
+ }
160
+ ], // - this option enforces minimum and maximum identifier lengths (variable names, property names etc.) (off by default)
161
+ "id-match": 0, // - require identifiers to match the provided regular expression
162
+ "indent": [2, 2, // - specify tab or space width for your code
163
+ {
164
+ "SwitchCase": 1
165
+ }
166
+ ],
167
+ "key-spacing": 2, // - enforce spacing between keys and values in object literal properties
168
+ "lines-around-comment": [2,
169
+ {
170
+ "beforeBlockComment": true,
171
+ "afterBlockComment": false,
172
+ "beforeLineComment": false,
173
+ "afterLineComment": false,
174
+ "allowBlockStart": true,
175
+ "allowBlockEnd": true
176
+ }
177
+ ], // - enforce empty lines around comments
178
+ "linebreak-style": 2, // - disallow mixed 'LF' and 'CRLF' as linebreaks
179
+ "max-nested-callbacks": [2, 6], // - specify the maximum depth callbacks can be nested
180
+ "max-statements-per-line": [
181
+ 2,
182
+ {
183
+ "max": 1
184
+ }
185
+ ], // - enforce a maximum number of statements per line
186
+ "new-cap": 0, // - require a capital letter for constructors
187
+ "new-parens": 2, // - disallow the omission of parentheses when invoking a constructor with no arguments
188
+ "newline-after-var": 0, // - require or disallow an empty newline after variable declarations
189
+ "no-array-constructor": 2, // - disallow use of the Array constructor
190
+ "no-continue": 2, // - disallow use of the continue statement
191
+ "no-inline-comments": 0, // - disallow comments inline after code
192
+ "no-lonely-if": 2, // - disallow if as the only statement in an else block
193
+ "no-mixed-spaces-and-tabs": 2, // - disallow mixed spaces and tabs for indentation (recommended)
194
+ "no-multiple-empty-lines": [
195
+ 2,
196
+ {
197
+ "max": 2,
198
+ "maxEOF": 1,
199
+ "maxBOF": 0
200
+ }
201
+ ], // - disallow multiple empty lines
202
+ "no-nested-ternary": 2, // - disallow nested ternary expressions
203
+ "no-new-object": 2, // - disallow the use of the Object constructor
204
+ "no-spaced-func": 2, // - disallow space between function identifier and application
205
+ "no-ternary": 0, // - disallow the use of ternary operators
206
+ "no-trailing-spaces": 2, // - disallow trailing whitespace at the end of lines
207
+ "no-underscore-dangle": 0, // - disallow dangling underscores in identifiers
208
+ "no-unneeded-ternary": 2, // - disallow the use of Boolean literals in conditional expressions
209
+ "object-curly-spacing": 2, // - require or disallow padding inside curly braces
210
+ "one-var": [1, "never"], // - require or disallow one variable declaration per function
211
+ "operator-assignment": [2, "always"], // - require assignment operator shorthand where possible or prohibit it entirely
212
+ "operator-linebreak": 2, // - enforce operators to be placed before or after line breaks
213
+ "padded-blocks": 0, // - enforce padding within blocks
214
+ "quote-props": 2, // - require quotes around object literal property names
215
+ "quotes": [2, "double"], // - specify whether backticks, double or single quotes should be used
216
+ "semi-spacing": 2, // - enforce spacing before and after semicolons
217
+ "semi": 2, // - require or disallow use of semicolons instead of ASI
218
+ "sort-vars": 0, // - sort variables within the same declaration block
219
+ "keyword-spacing": 2, // - require a space after certain keywords
220
+ "space-before-blocks": 2, // - require or disallow a space before blocks
221
+ "space-before-function-paren": [2,
222
+ {
223
+ "anonymous": "always",
224
+ "named": "never"
225
+ }
226
+ ], // - require or disallow a space before function opening parenthesis
227
+ "space-in-parens": 2, // - require or disallow spaces inside parentheses
228
+ "space-infix-ops": 2, // - require spaces around operators
229
+ "space-unary-ops": 2, // - require or disallow spaces before/after unary operators
230
+ "spaced-comment": 2, // - require or disallow a space immediately following the // or /* in a comment
231
+ "wrap-regex": 2, // - require regex literals to be wrapped in parentheses
232
+
233
+ // ECMAScript 6
234
+ // These rules are only relevant to ES6 environments.
235
+
236
+ "arrow-parens": [2, "as-needed"], // - require parens in arrow function arguments
237
+ "arrow-spacing": 2, // - require space before/after arrow function's arrow
238
+ "constructor-super": 2, // - verify calls of super() in constructors
239
+ "generator-star-spacing": 2, // - enforce spacing around the * in generator functions
240
+ "no-class-assign": 2, // - disallow modifying variables of class declarations
241
+ "no-const-assign": 2, // - disallow modifying variables that are declared using const
242
+ "no-this-before-super": 2, // - disallow use of this/super before calling super() in constructors.
243
+ "no-var": 2, // - require let or const instead of var
244
+ "object-shorthand": [2, "methods"], // - require method and property shorthand syntax for object literals
245
+ "prefer-const": 2, // - suggest using const declaration for variables that are never modified after declared
246
+ "prefer-spread": 2, // - suggest using the spread operator instead of .apply().
247
+ "require-yield": 2, // - disallow generator functions that do not have yield
248
+ "prefer-template": 2
249
+ }
250
+ }
251
+ ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mongodb-atlas-api-client",
3
- "version": "3.21.0",
3
+ "version": "4.0.0",
4
4
  "description": "A mongodb atlas api client for nodejs.",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -36,14 +36,14 @@
36
36
  },
37
37
  "homepage": "https://github.com/montumodi/mongodb-atlas-api-client#readme",
38
38
  "devDependencies": {
39
- "@hapi/code": "^8.0.2",
40
- "@hapi/lab": "^24.3.2",
41
- "depcheck": "^1.4.2",
42
- "eslint": "^7.32.0",
43
- "nock": "^13.1.3",
44
- "sinon": "^14.0.0"
39
+ "@eslint/js": "^9.10.0",
40
+ "@hapi/code": "^9.0.3",
41
+ "@hapi/lab": "^25.3.1",
42
+ "depcheck": "^1.4.7",
43
+ "eslint": "^9.10.0",
44
+ "sinon": "^18.0.0"
45
45
  },
46
46
  "dependencies": {
47
- "urllib": "^2.38.0"
47
+ "urllib": "^4.2.0"
48
48
  }
49
49
  }
@@ -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 Alert = require("../src/alert");
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 Alert = require('../src/alert.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 - Alert", () => {
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 alert is exported from index", () => {
22
37
  it("should export alert functions", async () => {
23
38
  expect(client.alert.get).to.be.function();
@@ -28,34 +43,38 @@ describe("Mongo Atlas Api Client - Alert", () => {
28
43
 
29
44
  describe("When get is called with querystring parameters", () => {
30
45
  it("should return response", async () => {
31
- const expectedRequest = nock(baseUrl)
32
- .get(`/groups/${projectId}/alerts/myAlertId?key1=value1&key2=value2`)
46
+ mockPool.intercept({
47
+ "path": `/groups/${projectId}/alerts/myAlertId?key1=value1&key2=value2`,
48
+ "method": "get"
49
+ })
33
50
  .reply(200, {"alert": "name"});
34
51
  const result = await client.alert.get("myAlertId", {"key1": "value1", "key2": "value2"});
35
52
  expect(result).to.equal({"alert": "name"});
36
- expect(expectedRequest.isDone()).to.be.true();
37
53
  });
38
54
  });
39
55
 
40
56
  describe("When getAll is called with querystring parameters", () => {
41
57
  it("should return response", async () => {
42
- const expectedRequest = nock(baseUrl)
43
- .get(`/groups/${projectId}/alerts?key1=value1&key2=value2`)
58
+ mockPool.intercept({
59
+ "path": `/groups/${projectId}/alerts?key1=value1&key2=value2`,
60
+ "method": "get"
61
+ })
44
62
  .reply(200, [{"alert": "name"}]);
45
63
  const result = await client.alert.getAll({"key1": "value1", "key2": "value2"});
46
64
  expect(result).to.equal([{"alert": "name"}]);
47
- expect(expectedRequest.isDone()).to.be.true();
48
65
  });
49
66
  });
50
67
 
51
68
  describe("When acknowledge is called with querystring parameters", () => {
52
69
  it("should return response", async () => {
53
- const expectedRequest = nock(baseUrl)
54
- .patch(`/groups/${projectId}/alerts/myAlertId?key1=value1&key2=value2`)
70
+ mockPool.intercept({
71
+ "path": `/groups/${projectId}/alerts/myAlertId?key1=value1&key2=value2`,
72
+ "method": "PATCH",
73
+ "data": {"body": "value"}
74
+ })
55
75
  .reply(200, [{"alert": "name"}]);
56
76
  const result = await client.alert.acknowledge("myAlertId", {"body": "value"}, {"key1": "value1", "key2": "value2"});
57
77
  expect(result).to.equal([{"alert": "name"}]);
58
- expect(expectedRequest.isDone()).to.be.true();
59
78
  });
60
79
  });
61
80
  });
@@ -63,7 +82,7 @@ describe("Mongo Atlas Api Client - Alert", () => {
63
82
  describe("Alert Class", () => {
64
83
 
65
84
  const mockRequest = {
66
- "request": sinon.stub().returns(new Promise(resolve => resolve({"data": "some test data"})))
85
+ "request": stub().returns(new Promise(resolve => resolve({"data": "some test data"})))
67
86
  };
68
87
  const mockHttpClient = new HttpClient(mockRequest, "dummyPublicKey", "dummyPrivateKey");
69
88
 
@@ -98,4 +117,4 @@ describe("Alert Class", () => {
98
117
  });
99
118
  });
100
119
 
101
- });
120
+ });
@@ -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 AtlasSearch = require("../src/atlasSearch");
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 AtlasSearch = require('../src/atlasSearch.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 - atlasSearch", () => {
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 atlasSearch is exported from index", () => {
22
37
  it("should export atlasSearch functions", async () => {
23
38
  expect(client.atlasSearch.get).to.be.function();
@@ -32,78 +47,81 @@ describe("Mongo Atlas Api Client - atlasSearch", () => {
32
47
 
33
48
  describe("When get is called with querystring parameters", () => {
34
49
  it("should return response", async () => {
35
- const expectedRequest = nock(baseUrl)
36
- .get(`/groups/${projectId}/clusters/mycluster/fts/indexes/myindexId?key1=value1&key2=value2`)
37
- .reply(200, {"atlasSearch": "name"});
50
+ mockPool.intercept({
51
+ "path": `/groups/${projectId}/clusters/mycluster/fts/indexes/myindexId?key1=value1&key2=value2`,
52
+ "method": "GET"
53
+ }).reply(200, {"atlasSearch": "name"});
38
54
  const result = await client.atlasSearch.get("mycluster", "myindexId", {"key1": "value1", "key2": "value2"});
39
55
  expect(result).to.equal({"atlasSearch": "name"});
40
- expect(expectedRequest.isDone()).to.be.true();
41
56
  });
42
57
  });
43
58
 
44
59
  describe("When getAll is called with querystring parameters", () => {
45
60
  it("should return response", async () => {
46
- const expectedRequest = nock(baseUrl)
47
- .get(`/groups/${projectId}/clusters/mycluster/fts/indexes/mydatabasename/mycollectionname?key1=value1&key2=value2`)
48
- .reply(200, [{"atlasSearch": "name"}]);
61
+ mockPool.intercept({
62
+ "path": `/groups/${projectId}/clusters/mycluster/fts/indexes/mydatabasename/mycollectionname?key1=value1&key2=value2`,
63
+ "method": "GET"
64
+ }).reply(200, [{"atlasSearch": "name"}]);
49
65
  const result = await client.atlasSearch.getAll("mycluster", "mydatabasename", "mycollectionname", {"key1": "value1", "key2": "value2"});
50
66
  expect(result).to.equal([{"atlasSearch": "name"}]);
51
- expect(expectedRequest.isDone()).to.be.true();
52
67
  });
53
68
  });
54
69
 
55
70
  describe("When getAllAnalyzers is called with querystring parameters", () => {
56
71
  it("should return response", async () => {
57
- const expectedRequest = nock(baseUrl)
58
- .get(`/groups/${projectId}/clusters/mycluster/fts/analyzers?key1=value1&key2=value2`)
59
- .reply(200, [{"atlasSearch": "name"}]);
72
+ mockPool.intercept({
73
+ "path": `/groups/${projectId}/clusters/mycluster/fts/analyzers?key1=value1&key2=value2`,
74
+ "method": "GET"
75
+ }).reply(200, [{"atlasSearch": "name"}]);
60
76
  const result = await client.atlasSearch.getAllAnalyzers("mycluster", {"key1": "value1", "key2": "value2"});
61
77
  expect(result).to.equal([{"atlasSearch": "name"}]);
62
- expect(expectedRequest.isDone()).to.be.true();
63
78
  });
64
79
  });
65
80
 
66
81
  describe("When update is called with querystring parameters", () => {
67
82
  it("should return response", async () => {
68
- const expectedRequest = nock(baseUrl)
69
- .patch(`/groups/${projectId}/clusters/mycluster/fts/indexes/indexId?key1=value1&key2=value2`)
70
- .reply(200, [{"atlasSearch": "name"}]);
83
+ mockPool.intercept({
84
+ "path": `/groups/${projectId}/clusters/mycluster/fts/indexes/indexId?key1=value1&key2=value2`,
85
+ "method": "PATCH",
86
+ "data": {"body": "value"}
87
+ }).reply(200, [{"atlasSearch": "name"}]);
71
88
  const result = await client.atlasSearch.update("mycluster", "indexId", {"body": "value"}, {"key1": "value1", "key2": "value2"});
72
89
  expect(result).to.equal([{"atlasSearch": "name"}]);
73
- expect(expectedRequest.isDone()).to.be.true();
74
90
  });
75
91
  });
76
92
 
77
93
  describe("When upsertAnalyzer is called with querystring parameters", () => {
78
94
  it("should return response", async () => {
79
- const expectedRequest = nock(baseUrl)
80
- .put(`/groups/${projectId}/clusters/mycluster/fts/analyzers?key1=value1&key2=value2`)
81
- .reply(200, [{"atlasSearch": "name"}]);
95
+ mockPool.intercept({
96
+ "path": `/groups/${projectId}/clusters/mycluster/fts/analyzers?key1=value1&key2=value2`,
97
+ "method": "PUT",
98
+ "data": {"body": "value"}
99
+ }).reply(200, [{"atlasSearch": "name"}]);
82
100
  const result = await client.atlasSearch.upsertAnalyzer("mycluster", {"body": "value"}, {"key1": "value1", "key2": "value2"});
83
101
  expect(result).to.equal([{"atlasSearch": "name"}]);
84
- expect(expectedRequest.isDone()).to.be.true();
85
102
  });
86
103
  });
87
104
 
88
105
  describe("When create is called with querystring parameters", () => {
89
106
  it("should return response", async () => {
90
- const expectedRequest = nock(baseUrl)
91
- .post(`/groups/${projectId}/clusters/mycluster/fts/indexes?key1=value1&key2=value2`)
92
- .reply(200, [{"atlasSearch": "name"}]);
107
+ mockPool.intercept({
108
+ "path": `/groups/${projectId}/clusters/mycluster/fts/indexes?key1=value1&key2=value2`,
109
+ "method": "POST",
110
+ "data": {"body": "value"}
111
+ }).reply(200, [{"atlasSearch": "name"}]);
93
112
  const result = await client.atlasSearch.create("mycluster", {"body": "value"}, {"key1": "value1", "key2": "value2"});
94
113
  expect(result).to.equal([{"atlasSearch": "name"}]);
95
- expect(expectedRequest.isDone()).to.be.true();
96
114
  });
97
115
  });
98
116
 
99
117
  describe("When delete is called with querystring parameters", () => {
100
118
  it("should return response", async () => {
101
- const expectedRequest = nock(baseUrl)
102
- .delete(`/groups/${projectId}/clusters/mycluster/fts/indexes/indexId?key1=value1&key2=value2`)
103
- .reply(200, true);
119
+ mockPool.intercept({
120
+ "path": `/groups/${projectId}/clusters/mycluster/fts/indexes/indexId?key1=value1&key2=value2`,
121
+ "method": "DELETE"
122
+ }).reply(200, true);
104
123
  const result = await client.atlasSearch.delete("mycluster", "indexId", {"key1": "value1", "key2": "value2"});
105
124
  expect(result).to.be.true();
106
- expect(expectedRequest.isDone()).to.be.true();
107
125
  });
108
126
  });
109
127
  });
@@ -111,7 +129,7 @@ describe("Mongo Atlas Api Client - atlasSearch", () => {
111
129
  describe("AtlasSearch Class", () => {
112
130
 
113
131
  const mockRequest = {
114
- "request": sinon.stub().returns(new Promise(resolve => resolve({"data": "some test data"})))
132
+ "request": stub().returns(new Promise(resolve => resolve({"data": "some test data"})))
115
133
  };
116
134
  const mockHttpClient = new HttpClient(mockRequest, "dummyPublicKey", "dummyPrivateKey");
117
135