Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/legacy_wrappers/change_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@ Object.defineProperty(module.exports, '__esModule', { value: true });

module.exports.makeLegacyChangeStream = function (baseClass) {
class LegacyChangeStream extends baseClass {
close(callback) {
return maybeCallback(super.close(), callback);
close(options, callback) {
callback =
typeof callback === 'function'
? callback
: typeof options === 'function'
? options
: undefined;
options = typeof options !== 'function' ? options : undefined;
return maybeCallback(super.close(options), callback);
}
hasNext(callback) {
return maybeCallback(super.hasNext(), callback);
Expand Down
33 changes: 27 additions & 6 deletions src/legacy_wrappers/gridfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,37 @@ Object.defineProperty(module.exports, '__esModule', { value: true });

module.exports.makeLegacyGridFSBucket = function (baseClass) {
class LegacyGridFSBucket extends baseClass {
delete(id, callback) {
return maybeCallback(super.delete(id), callback);
delete(id, options, callback) {
callback =
typeof callback === 'function'
? callback
: typeof options === 'function'
? options
: undefined;
options = typeof options !== 'function' ? options : undefined;
return maybeCallback(super.delete(id, options), callback);
}

rename(id, filename, callback) {
return maybeCallback(super.rename(id, filename), callback);
rename(id, filename, options, callback) {
callback =
typeof callback === 'function'
? callback
: typeof options === 'function'
? options
: undefined;
options = typeof options !== 'function' ? options : undefined;
return maybeCallback(super.rename(id, filename, options), callback);
}

drop(callback) {
return maybeCallback(super.drop(), callback);
drop(options, callback) {
callback =
typeof callback === 'function'
? callback
: typeof options === 'function'
? options
: undefined;
options = typeof options !== 'function' ? options : undefined;
return maybeCallback(super.drop(options), callback);
}

// conversion
Expand Down
36 changes: 36 additions & 0 deletions test/unit/legacy_wrappers/change_streams.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';

const { MongoClient: LegacyMongoClient } = require('../../../src/index');
const mongodbDriver = require('mongodb');
const sinon = require('sinon');
const { expect } = require('chai');

const iLoveJs = 'mongodb://iLoveJavascript';

describe('legacy_wrappers/change_streams.js', () => {
let client;
let changeStream;
beforeEach(async function () {
client = new LegacyMongoClient(iLoveJs);
changeStream = client.db('test').collection('test').watch();
});

afterEach(async function () {
sinon.restore();
await client.close();
});

context('close', function () {
it('correctly handles parameters when options are provided', function () {
const spy = sinon.spy(mongodbDriver.ChangeStream.prototype, 'close');
const opts = { timeoutMS: 100 };
changeStream.close(opts, () => {});
expect(spy).to.be.calledWithExactly(opts);
});
it('correctly handles parameters when options are not provided', function () {
const spy = sinon.spy(mongodbDriver.ChangeStream.prototype, 'close');
changeStream.close(() => {});
expect(spy).to.be.calledWithExactly(undefined);
});
});
});
48 changes: 48 additions & 0 deletions test/unit/legacy_wrappers/gridfs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,52 @@ describe('legacy_wrappers/gridfs.js', () => {
LegacyGridFSBucketWriteStream
);
});

context('delete', function () {
it('correctly handles parameters when options are provided', function () {
const spy = sinon.spy(mongodbDriver.GridFSBucket.prototype, 'delete');
const opts = { timeoutMS: 10 };
const oid = new mongodbDriver.ObjectId();
bucket.delete(oid, opts, () => {});
expect(spy).to.be.calledWithExactly(oid, opts);
});
it('correctly handles parameters when options are not provided', function () {
const spy = sinon.spy(mongodbDriver.GridFSBucket.prototype, 'delete');
const oid = new mongodbDriver.ObjectId();
bucket.delete(oid, () => {});
expect(spy).to.be.calledWithExactly(oid, undefined);
});
});

context('rename', function () {
it('correctly handles parameters when options are provided', function () {
const spy = sinon.spy(mongodbDriver.GridFSBucket.prototype, 'rename');
const opts = { timeoutMS: 10 };
const oid = new mongodbDriver.ObjectId();
bucket.rename(oid, 'name', opts, () => {});
expect(spy).to.be.calledWithExactly(oid, 'name', opts);
});

it('correctly handles parameters when options are not provided', function () {
const spy = sinon.spy(mongodbDriver.GridFSBucket.prototype, 'rename');
const oid = new mongodbDriver.ObjectId();
bucket.rename(oid, 'name', () => {});
expect(spy).to.be.calledWithExactly(oid, 'name', undefined);
});
});

context('drop', function () {
it('correctly handles parameters when options are provided', function () {
const spy = sinon.spy(mongodbDriver.GridFSBucket.prototype, 'drop');
const opts = { timeoutMS: 10 };
bucket.drop(opts, () => {});
expect(spy).to.be.calledWithExactly(opts);
});

it('correctly handles parameters when options are not provided', function () {
const spy = sinon.spy(mongodbDriver.GridFSBucket.prototype, 'drop');
bucket.drop(() => {});
expect(spy).to.be.calledWithExactly(undefined);
});
});
});