Skip to content

Commit ec590cd

Browse files
committed
support options for changesStream.close
1 parent f21bacf commit ec590cd

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

src/legacy_wrappers/change_stream.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@ Object.defineProperty(module.exports, '__esModule', { value: true });
77

88
module.exports.makeLegacyChangeStream = function (baseClass) {
99
class LegacyChangeStream extends baseClass {
10-
close(callback) {
11-
return maybeCallback(super.close(), callback);
10+
close(options, callback) {
11+
callback =
12+
typeof callback === 'function'
13+
? callback
14+
: typeof options === 'function'
15+
? options
16+
: undefined;
17+
options = typeof options !== 'function' ? options : undefined;
18+
return maybeCallback(super.close(options), callback);
1219
}
1320
hasNext(callback) {
1421
return maybeCallback(super.hasNext(), callback);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'use strict';
2+
3+
const { MongoClient: LegacyMongoClient } = require('../../../src/index');
4+
const mongodbDriver = require('mongodb');
5+
const sinon = require('sinon');
6+
const { expect } = require('chai');
7+
8+
const iLoveJs = 'mongodb://iLoveJavascript';
9+
10+
describe('legacy_wrappers/change_streams.js', () => {
11+
let client;
12+
let changeStream;
13+
beforeEach(async function () {
14+
client = new LegacyMongoClient(iLoveJs);
15+
changeStream = client.db('test').collection('test').watch();
16+
});
17+
18+
afterEach(async function () {
19+
sinon.restore();
20+
await client.close();
21+
});
22+
23+
context('close', function () {
24+
it('correctly handles parameters when options are provided', function () {
25+
const spy = sinon.spy(mongodbDriver.ChangeStream.prototype, 'close');
26+
const opts = { timeoutMS: 100 };
27+
changeStream.close(opts, () => {});
28+
expect(spy).to.be.calledWithExactly(opts);
29+
});
30+
it('correctly handles parameters when options are not provided', function () {
31+
const spy = sinon.spy(mongodbDriver.ChangeStream.prototype, 'close');
32+
changeStream.close(() => {});
33+
expect(spy).to.be.calledWithExactly(undefined);
34+
});
35+
});
36+
});

0 commit comments

Comments
 (0)