Skip to content

Commit 26e5c46

Browse files
committed
fix: skip
1 parent 7df45a4 commit 26e5c46

File tree

1 file changed

+38
-31
lines changed

1 file changed

+38
-31
lines changed

test/integration/auth/auth.prose.test.js

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,10 @@ const semver = require('semver');
1010
const { TopologyType } = require('../../../src');
1111

1212
describe('auth prose tests', () => {
13-
beforeEach(async function () {
14-
if (!semver.satisfies(this.configuration.version, '>=3.7.3')) {
15-
this.currentTest.skipReason = 'Requires version >=3.7.3';
16-
return this.skip();
17-
}
18-
if (this.configuration.topologyType === TopologyType.LoadBalanced) {
19-
this.currentTest.skipReason = 'Requires non-loadbalanced topology';
20-
return this.skip();
21-
}
22-
});
23-
2413
describe('SCRAM-SHA-256 prose test', () => {
2514
describe('SCRAM-SHA-256 prose test Steps 1-3', function () {
26-
const test = {};
15+
let sandbox;
16+
let oldDbName;
2717
const userMap = {
2818
sha1: {
2919
description: 'user with sha1 credentials',
@@ -51,18 +41,29 @@ describe('auth prose tests', () => {
5141

5242
const users = Object.keys(userMap).map(name => userMap[name]);
5343

54-
afterEach(() => test.sandbox.restore());
44+
afterEach(() => {
45+
if (sandbox) sandbox.restore();
46+
});
5547

5648
/**
5749
* Step 1
5850
* Create three test users, one with only SHA-1, one with only SHA-256 and one with both.
5951
*/
6052
beforeEach(async function () {
61-
test.sandbox = sinon.createSandbox();
53+
if (!semver.satisfies(this.configuration.version, '>=3.7.3')) {
54+
this.currentTest.skipReason = 'Requires version >=3.7.3';
55+
return this.skip();
56+
}
57+
if (this.configuration.topologyType === TopologyType.LoadBalanced) {
58+
this.currentTest.skipReason = 'Requires non-loadbalanced topology';
59+
return this.skip();
60+
}
61+
62+
sandbox = sinon.createSandbox();
6263
await setupDatabase(this.configuration);
6364

6465
const client = this.configuration.newClient();
65-
test.oldDbName = this.configuration.db;
66+
oldDbName = this.configuration.db;
6667
this.configuration.db = 'admin';
6768
const db = client.db(this.configuration.db);
6869

@@ -80,7 +81,7 @@ describe('auth prose tests', () => {
8081
afterEach(async function () {
8182
const client = this.configuration.newClient();
8283
const db = client.db(this.configuration.db);
83-
this.configuration.db = test.oldDbName;
84+
this.configuration.db = oldDbName;
8485

8586
await Promise.all(users.map(user => db.removeUser(user.username).catch(() => null)));
8687
await client.close();
@@ -167,7 +168,7 @@ describe('auth prose tests', () => {
167168
authSource: this.configuration.db
168169
};
169170

170-
test.sandbox.spy(ScramSHA256.prototype, 'auth');
171+
sandbox.spy(ScramSHA256.prototype, 'auth');
171172

172173
const client = this.configuration.newClient({}, options);
173174
await client.db().command({ ping: 1 });
@@ -188,19 +189,17 @@ describe('auth prose tests', () => {
188189
};
189190

190191
let runCommandSpy;
191-
test.sandbox
192-
.stub(ScramSHA256.prototype, 'auth')
193-
.callsFake(function (authContext, callback) {
194-
const connection = authContext.connection;
195-
const auth = ScramSHA256.prototype.auth.wrappedMethod;
196-
runCommandSpy = test.sandbox.spy(connection, 'command');
197-
function _callback(err, res) {
198-
runCommandSpy.restore();
199-
callback(err, res);
200-
}
201-
202-
auth.apply(this, [authContext, _callback]);
203-
});
192+
sandbox.stub(ScramSHA256.prototype, 'auth').callsFake(function (authContext, callback) {
193+
const connection = authContext.connection;
194+
const auth = ScramSHA256.prototype.auth.wrappedMethod;
195+
runCommandSpy = sandbox.spy(connection, 'command');
196+
function _callback(err, res) {
197+
runCommandSpy.restore();
198+
callback(err, res);
199+
}
200+
201+
auth.apply(this, [authContext, _callback]);
202+
});
204203

205204
const client = this.configuration.newClient({}, options);
206205
await client.db().command({ ping: 1 });
@@ -286,7 +285,7 @@ describe('auth prose tests', () => {
286285
authSource: this.configuration.db
287286
};
288287

289-
const commandSpy = test.sandbox.spy(Connection.prototype, 'command');
288+
const commandSpy = sandbox.spy(Connection.prototype, 'command');
290289
const client = this.configuration.newClient({}, options);
291290
await client.db().command({ ping: 1 });
292291
const calls = commandSpy
@@ -334,6 +333,14 @@ describe('auth prose tests', () => {
334333
];
335334

336335
beforeEach(async function () {
336+
if (!semver.satisfies(this.configuration.version, '>=3.7.3')) {
337+
this.currentTest.skipReason = 'Requires version >=3.7.3';
338+
return this.skip();
339+
}
340+
if (this.configuration.topologyType === TopologyType.LoadBalanced) {
341+
this.currentTest.skipReason = 'Requires non-loadbalanced topology';
342+
return this.skip();
343+
}
337344
await setupDatabase(this.configuration);
338345

339346
const client = this.configuration.newClient();

0 commit comments

Comments
 (0)