Skip to content

Commit 542505e

Browse files
committed
removed promisify
1 parent 863f028 commit 542505e

File tree

3 files changed

+23
-32
lines changed

3 files changed

+23
-32
lines changed

test/unit/operations/find.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { expect } from 'chai';
22
import * as sinon from 'sinon';
3-
import { promisify } from 'util';
43

54
import { FindOperation, ns, Server, ServerDescription } from '../../mongodb';
65
import { topologyWithPlaceholderClient } from '../../tools/utils';
@@ -43,7 +42,7 @@ describe('FindOperation', function () {
4342
it('should build basic find command with filter', async () => {
4443
const findOperation = new FindOperation(undefined, namespace, filter);
4544
const stub = sinon.stub(server, 'command').yieldsRight();
46-
await promisify(findOperation.executeCallback.bind(findOperation))(server, undefined);
45+
await findOperation.execute.bind(findOperation)(server, undefined);
4746
expect(stub).to.have.been.calledOnceWith(namespace, {
4847
find: namespace.collection,
4948
filter
@@ -56,7 +55,7 @@ describe('FindOperation', function () {
5655
};
5756
const findOperation = new FindOperation(undefined, namespace, {}, options);
5857
const stub = sinon.stub(server, 'command').yieldsRight();
59-
await promisify(findOperation.executeCallback.bind(findOperation))(server, undefined);
58+
await findOperation.execute.bind(findOperation)(server, undefined);
6059
expect(stub).to.have.been.calledOnceWith(
6160
namespace,
6261
sinon.match.has('oplogReplay', options.oplogReplay)

test/unit/operations/get_more.test.ts

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { expect } from 'chai';
22
import * as sinon from 'sinon';
3-
import { promisify } from 'util';
43

54
import {
65
Aspect,
@@ -64,7 +63,7 @@ describe('GetMoreOperation', function () {
6463
maxTimeMS: 500
6564
};
6665

67-
await promisify(operation.executeCallback.bind(operation))(server, undefined);
66+
await operation.execute.bind(operation)(server, undefined);
6867
expect(stub.calledOnce).to.be.true;
6968
const call = stub.getCall(0);
7069
expect(call.args[0]).to.equal(namespace);
@@ -109,7 +108,7 @@ describe('GetMoreOperation', function () {
109108
it('should build basic getMore command with cursorId and collection', async () => {
110109
const getMoreOperation = new GetMoreOperation(namespace, cursorId, server, {});
111110
const stub = sinon.stub(server, 'command').yieldsRight();
112-
await promisify(getMoreOperation.executeCallback.bind(getMoreOperation))(server, undefined);
111+
await getMoreOperation.execute.bind(getMoreOperation)(server, undefined);
113112
expect(stub).to.have.been.calledOnceWith(namespace, {
114113
getMore: cursorId,
115114
collection: namespace.collection
@@ -122,7 +121,7 @@ describe('GetMoreOperation', function () {
122121
};
123122
const getMoreOperation = new GetMoreOperation(namespace, cursorId, server, options);
124123
const stub = sinon.stub(server, 'command').yieldsRight();
125-
await promisify(getMoreOperation.executeCallback.bind(getMoreOperation))(server, undefined);
124+
await getMoreOperation.execute.bind(getMoreOperation)(server, undefined);
126125
expect(stub).to.have.been.calledOnceWith(
127126
namespace,
128127
sinon.match.has('batchSize', options.batchSize)
@@ -135,7 +134,7 @@ describe('GetMoreOperation', function () {
135134
};
136135
const getMoreOperation = new GetMoreOperation(namespace, cursorId, server, options);
137136
const stub = sinon.stub(server, 'command').yieldsRight();
138-
await promisify(getMoreOperation.executeCallback.bind(getMoreOperation))(server, undefined);
137+
await getMoreOperation.execute.bind(getMoreOperation)(server, undefined);
139138
expect(stub).to.have.been.calledOnceWith(
140139
namespace,
141140
sinon.match.has('maxTimeMS', options.maxAwaitTimeMS)
@@ -193,7 +192,7 @@ describe('GetMoreOperation', function () {
193192
};
194193
const operation = new GetMoreOperation(namespace, cursorId, server, optionsWithComment);
195194
const stub = sinon.stub(server, 'command').yieldsRight();
196-
await promisify(operation.executeCallback.bind(operation))(server, undefined);
195+
await operation.execute.bind(operation)(server, undefined);
197196
expect(stub).to.have.been.calledOnceWith(namespace, getMore);
198197
});
199198
}
@@ -216,10 +215,9 @@ describe('GetMoreOperation', function () {
216215
server,
217216
options
218217
);
219-
const error = await promisify(getMoreOperation.executeCallback.bind(getMoreOperation))(
220-
server,
221-
undefined
222-
).catch(error => error);
218+
const error = await getMoreOperation.execute
219+
.bind(getMoreOperation)(server, undefined)
220+
.catch(error => error);
223221
expect(error).to.be.instanceOf(MongoRuntimeError);
224222
});
225223

@@ -230,10 +228,9 @@ describe('GetMoreOperation', function () {
230228
server,
231229
options
232230
);
233-
const error = await promisify(getMoreOperation.executeCallback.bind(getMoreOperation))(
234-
server,
235-
undefined
236-
).catch(error => error);
231+
const error = await getMoreOperation.execute
232+
.bind(getMoreOperation)(server, undefined)
233+
.catch(error => error);
237234
expect(error).to.be.instanceOf(MongoRuntimeError);
238235
});
239236

@@ -244,10 +241,9 @@ describe('GetMoreOperation', function () {
244241
server,
245242
options
246243
);
247-
const error = await promisify(getMoreOperation.executeCallback.bind(getMoreOperation))(
248-
server,
249-
undefined
250-
).catch(error => error);
244+
const error = await getMoreOperation.execute
245+
.bind(getMoreOperation)(server, undefined)
246+
.catch(error => error);
251247
expect(error).to.be.instanceOf(MongoRuntimeError);
252248
});
253249
});

test/unit/operations/kill_cursors.test.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { expect } from 'chai';
22
import * as sinon from 'sinon';
3-
import { promisify } from 'util';
43

54
import {
65
KillCursorsOperation,
@@ -65,9 +64,9 @@ describe('class KillCursorsOperation', () => {
6564
options
6665
) as any;
6766

68-
const error = await promisify(
69-
killCursorsOperation.executeCallback.bind(killCursorsOperation)
70-
)(differentServer, undefined).catch(error => error);
67+
const error = await killCursorsOperation.execute
68+
.bind(killCursorsOperation)(differentServer, undefined)
69+
.catch(error => error);
7170

7271
expect(error).to.be.instanceOf(MongoRuntimeError);
7372
});
@@ -80,9 +79,9 @@ describe('class KillCursorsOperation', () => {
8079
options
8180
) as any;
8281

83-
const error = await promisify(
84-
killCursorsOperation.executeCallback.bind(killCursorsOperation)
85-
)(server, undefined).catch(error => error);
82+
const error = await killCursorsOperation.execute
83+
.bind(killCursorsOperation)(server, undefined)
84+
.catch(error => error);
8685

8786
expect(error).to.be.instanceOf(MongoRuntimeError);
8887
});
@@ -95,10 +94,7 @@ describe('class KillCursorsOperation', () => {
9594
options
9695
) as any;
9796
const stub = sinon.stub(server, 'command').yieldsRight();
98-
await promisify(killCursorsOperation.executeCallback.bind(killCursorsOperation))(
99-
server,
100-
undefined
101-
);
97+
await killCursorsOperation.execute.bind(killCursorsOperation)(server, undefined);
10298
expect(stub).to.have.been.calledOnceWith(namespace, {
10399
killCursors: namespace.collection,
104100
cursors: [cursorId]

0 commit comments

Comments
 (0)