Skip to content

Commit fb3e43f

Browse files
committed
test(NODE-4264): part 1 of removing connect from tests
1 parent 1261432 commit fb3e43f

33 files changed

+3053
-5252
lines changed

global.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ declare global {
1212
topology?: TopologyTypeRequirement;
1313
mongodb?: string;
1414
os?: NodeJS.Platform | `!${NodeJS.Platform}`;
15-
apiVersion?: '1';
15+
apiVersion?: '1' | boolean;
1616
clientSideEncryption?: boolean;
1717
serverless?: 'forbid' | 'allow' | 'require';
1818
auth?: 'enabled' | 'disabled';

test/integration/auth/mongodb_aws.test.js

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const { removeAuthFromConnectionString } = require('../../tools/utils');
44
const sinon = require('sinon');
55
const http = require('http');
66
const { performance } = require('perf_hooks');
7-
const { MongoAWSError } = require('../../../src');
7+
const { MongoAWSError, MongoError } = require('../../../src');
88

99
describe('MONGODB-AWS', function () {
1010
beforeEach(function () {
@@ -15,37 +15,28 @@ describe('MONGODB-AWS', function () {
1515
}
1616
});
1717

18-
it('should not authorize when not authenticated', function (done) {
19-
const config = this.configuration;
20-
const url = removeAuthFromConnectionString(config.url());
21-
const client = config.newClient(url); // strip provided URI of credentials
22-
client.connect(err => {
23-
expect(err).to.not.exist;
24-
this.defer(() => client.close());
18+
it('should not authorize when not authenticated', async function () {
19+
const url = removeAuthFromConnectionString(this.configuration.url());
20+
const client = this.configuration.newClient(url); // strip provided URI of credentials
2521

26-
client.db('aws').command({ count: 'test' }, (err, count) => {
27-
expect(err).to.exist;
28-
expect(count).to.not.exist;
22+
const error = await client
23+
.db('aws')
24+
.command({ ping: 1 })
25+
.catch(error => error);
2926

30-
done();
31-
});
32-
});
27+
expect(error).to.be.instanceOf(MongoAWSError);
3328
});
3429

35-
it('should authorize when successfully authenticated', function (done) {
36-
const config = this.configuration;
37-
const client = config.newClient(process.env.MONGODB_URI); // use the URI built by the test environment
38-
client.connect(err => {
39-
expect(err).to.not.exist;
40-
this.defer(() => client.close());
30+
it('should authorize when successfully authenticated', async function () {
31+
const client = this.configuration.newClient(process.env.MONGODB_URI); // use the URI built by the test environment
4132

42-
client.db('aws').command({ count: 'test' }, (err, count) => {
43-
expect(err).to.not.exist;
44-
expect(count).to.exist;
33+
const result = await client
34+
.db('aws')
35+
.command({ ping: 1 })
36+
.catch(error => error);
4537

46-
done();
47-
});
48-
});
38+
expect(result).to.not.be.instanceOf(MongoAWSError);
39+
expect(result).to.have.property('ok', 1);
4940
});
5041

5142
it('should allow empty string in authMechanismProperties.AWS_SESSION_TOKEN to override AWS_SESSION_TOKEN environment variable', function () {
@@ -84,10 +75,10 @@ describe('MONGODB-AWS', function () {
8475
client = config.newClient(process.env.MONGODB_URI, { authMechanism: 'MONGODB-AWS' }); // use the URI built by the test environment
8576
const startTime = performance.now();
8677

87-
let caughtError = null;
88-
await client.connect().catch(err => {
89-
caughtError = err;
90-
});
78+
const caughtError = await client
79+
.db()
80+
.command({ ping: 1 })
81+
.catch(error => error);
9182

9283
const endTime = performance.now();
9384
const timeTaken = endTime - startTime;

test/integration/auth/scram_sha_1.test.js

Lines changed: 0 additions & 76 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { expect } from 'chai';
2+
3+
import type { MongoClient } from '../../../src';
4+
5+
describe('SCRAM-SHA-1', function () {
6+
let client: MongoClient;
7+
8+
beforeEach(async function () {
9+
const onlyScram1AuthMech =
10+
this.configuration.parameters?.authenticationMechanisms.length === 1 &&
11+
this.configuration.parameters?.authenticationMechanisms[0] === 'SCRAM-SHA-1';
12+
13+
if (!onlyScram1AuthMech) {
14+
this.currentTest.skipReason = `MongoDB auth mechanism must only be SCRAM-SHA-1, got ${this.configuration.parameters?.authenticationMechanisms}`;
15+
return this.skip();
16+
}
17+
18+
client = this.configuration.newClient();
19+
});
20+
21+
afterEach(async () => {
22+
await client.close();
23+
});
24+
25+
it('successfuly authenticates', async () => {
26+
const result = await client.db().admin().command({ ping: 1 });
27+
expect(result).to.have.property('ok', 1);
28+
});
29+
});

test/integration/bson-decimal128/decimal128.test.js

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,43 +9,30 @@ describe('Decimal128', function () {
99
return setupDatabase(this.configuration);
1010
});
1111

12-
it('should correctly insert decimal128 value', {
13-
// Add a tag that our runner can trigger on
14-
// in this case we are setting that node needs to be higher than 0.10.X to run
15-
metadata: {
16-
requires: {
17-
mongodb: '>=3.3.6',
18-
topology: ['single']
19-
}
20-
},
12+
it('should correctly insert decimal128 value', function (done) {
13+
var configuration = this.configuration;
14+
var client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 });
15+
var db = client.db(configuration.db);
16+
var object = {
17+
id: 1,
18+
value: Decimal128.fromString('1.28')
19+
};
2120

22-
test: function (done) {
23-
var configuration = this.configuration;
24-
var client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 });
25-
client.connect(function (err, client) {
26-
var db = client.db(configuration.db);
27-
var object = {
28-
id: 1,
29-
value: Decimal128.fromString('1')
30-
};
21+
db.collection('decimal128').insertOne(object, function (err) {
22+
expect(err).to.not.exist;
3123

32-
db.collection('decimal128').insertOne(object, function (err) {
24+
db.collection('decimal128').findOne(
25+
{
26+
id: 1
27+
},
28+
function (err, doc) {
3329
expect(err).to.not.exist;
30+
test.ok(doc.value instanceof Decimal128);
31+
test.equal('1.28', doc.value.toString());
3432

35-
db.collection('decimal128').findOne(
36-
{
37-
id: 1
38-
},
39-
function (err, doc) {
40-
expect(err).to.not.exist;
41-
test.ok(doc.value instanceof Decimal128);
42-
test.equal('1', doc.value.toString());
43-
44-
client.close(done);
45-
}
46-
);
47-
});
48-
});
49-
}
33+
client.close(done);
34+
}
35+
);
36+
});
5037
});
5138
});

test/integration/causal-consistency/causal_consistency.prose.test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ describe('Causal Consistency - prose tests', function () {
3737
test.client.on('commandSucceeded', event => {
3838
if (ignoredCommands.indexOf(event.commandName) === -1) test.commands.succeeded.push(event);
3939
});
40-
41-
return test.client.connect();
4240
});
4341

4442
afterEach(() => {

0 commit comments

Comments
 (0)