Skip to content

Commit f21bacf

Browse files
committed
support new options arguments
1 parent fe3b692 commit f21bacf

File tree

2 files changed

+75
-6
lines changed

2 files changed

+75
-6
lines changed

src/legacy_wrappers/gridfs.js

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,37 @@ Object.defineProperty(module.exports, '__esModule', { value: true });
77

88
module.exports.makeLegacyGridFSBucket = function (baseClass) {
99
class LegacyGridFSBucket extends baseClass {
10-
delete(id, callback) {
11-
return maybeCallback(super.delete(id), callback);
10+
delete(id, 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.delete(id, options), callback);
1219
}
1320

14-
rename(id, filename, callback) {
15-
return maybeCallback(super.rename(id, filename), callback);
21+
rename(id, filename, options, callback) {
22+
callback =
23+
typeof callback === 'function'
24+
? callback
25+
: typeof options === 'function'
26+
? options
27+
: undefined;
28+
options = typeof options !== 'function' ? options : undefined;
29+
return maybeCallback(super.rename(id, filename, options), callback);
1630
}
1731

18-
drop(callback) {
19-
return maybeCallback(super.drop(), callback);
32+
drop(options, callback) {
33+
callback =
34+
typeof callback === 'function'
35+
? callback
36+
: typeof options === 'function'
37+
? options
38+
: undefined;
39+
options = typeof options !== 'function' ? options : undefined;
40+
return maybeCallback(super.drop(options), callback);
2041
}
2142

2243
// conversion

test/unit/legacy_wrappers/gridfs.test.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,52 @@ describe('legacy_wrappers/gridfs.js', () => {
4848
LegacyGridFSBucketWriteStream
4949
);
5050
});
51+
52+
context('delete', function () {
53+
it('correctly handles parameters when options are provided', function () {
54+
const spy = sinon.spy(mongodbDriver.GridFSBucket.prototype, 'delete');
55+
const opts = { timeoutMS: 10 };
56+
const oid = new mongodbDriver.ObjectId();
57+
bucket.delete(oid, opts, () => {});
58+
expect(spy).to.be.calledWithExactly(oid, opts);
59+
});
60+
it('correctly handles parameters when options are not provided', function () {
61+
const spy = sinon.spy(mongodbDriver.GridFSBucket.prototype, 'delete');
62+
const oid = new mongodbDriver.ObjectId();
63+
bucket.delete(oid, () => {});
64+
expect(spy).to.be.calledWithExactly(oid, undefined);
65+
});
66+
});
67+
68+
context('rename', function () {
69+
it('correctly handles parameters when options are provided', function () {
70+
const spy = sinon.spy(mongodbDriver.GridFSBucket.prototype, 'rename');
71+
const opts = { timeoutMS: 10 };
72+
const oid = new mongodbDriver.ObjectId();
73+
bucket.rename(oid, 'name', opts, () => {});
74+
expect(spy).to.be.calledWithExactly(oid, 'name', opts);
75+
});
76+
77+
it('correctly handles parameters when options are not provided', function () {
78+
const spy = sinon.spy(mongodbDriver.GridFSBucket.prototype, 'rename');
79+
const oid = new mongodbDriver.ObjectId();
80+
bucket.rename(oid, 'name', () => {});
81+
expect(spy).to.be.calledWithExactly(oid, 'name', undefined);
82+
});
83+
});
84+
85+
context('drop', function () {
86+
it('correctly handles parameters when options are provided', function () {
87+
const spy = sinon.spy(mongodbDriver.GridFSBucket.prototype, 'drop');
88+
const opts = { timeoutMS: 10 };
89+
bucket.drop(opts, () => {});
90+
expect(spy).to.be.calledWithExactly(opts);
91+
});
92+
93+
it('correctly handles parameters when options are not provided', function () {
94+
const spy = sinon.spy(mongodbDriver.GridFSBucket.prototype, 'drop');
95+
bucket.drop(() => {});
96+
expect(spy).to.be.calledWithExactly(undefined);
97+
});
98+
});
5199
});

0 commit comments

Comments
 (0)