Skip to content

Commit fd3c890

Browse files
committed
test: fix failing null check test
1 parent 2d4c7db commit fd3c890

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

test/functional/crud_api.test.js

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22
const test = require('./shared').assert;
33
const { expect } = require('chai');
4-
const { ReturnDocument } = require('../../src');
4+
const { ReturnDocument, ObjectId } = require('../../src');
55
const setupDatabase = require('./shared').setupDatabase;
66

77
// instanceof cannot be use reliably to detect the new models in js due to scoping and new
@@ -14,6 +14,27 @@ describe('CRUD API', function () {
1414
return setupDatabase(this.configuration);
1515
});
1616

17+
it('should correctly execute findOne method using crud api', async function () {
18+
const configuration = this.configuration;
19+
const client = configuration.newClient();
20+
await client.connect();
21+
const db = client.db(configuration.db);
22+
const collection = db.collection('t');
23+
24+
await collection.insertOne({ findOneTest: 1 });
25+
26+
const findOneResult = await collection.findOne({ findOneTest: 1 });
27+
28+
expect(findOneResult).to.have.property('findOneTest', 1);
29+
expect(findOneResult).to.have.property('_id').that.is.instanceOf(ObjectId);
30+
31+
const findNoneResult = await collection.findOne({ findOneTest: 2 });
32+
expect(findNoneResult).to.be.null;
33+
34+
await collection.drop();
35+
await client.close();
36+
});
37+
1738
it('should correctly execute find method using crud api', {
1839
// Add a tag that our runner can trigger on
1940
// in this case we are setting that node needs to be higher than 0.10.X to run

test/functional/sessions.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,8 @@ describe('Sessions', function () {
301301
controlSession = client.startSession();
302302

303303
// set up sessions with two sets of cluster times
304-
expect(await collection.findOne({}, { session: controlSession })).to.be.undefined;
305-
expect(await collection.findOne({}, { session: testSession })).to.be.undefined;
304+
expect(await collection.findOne({}, { session: controlSession })).to.be.null;
305+
expect(await collection.findOne({}, { session: testSession })).to.be.null;
306306
await collection.insertOne({ apple: 'green' });
307307
expect(await collection.findOne({}, { session: otherSession }))
308308
.property('apple')

0 commit comments

Comments
 (0)