-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
get_more.test.js
63 lines (54 loc) · 1.95 KB
/
get_more.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'use strict';
const sinon = require('sinon');
const { expect } = require('chai');
const { Long } = require('../../../src/bson');
const { GetMoreOperation } = require('../../../src/operations/get_more');
const { Server } = require('../../../src/sdam/server');
const { ClientSession } = require('../../../src/sessions');
const { ReadPreference } = require('../../../src/read_preference');
describe('GetMoreOperation', function () {
const ns = 'db.coll';
const cursorId = Long.fromNumber(1);
const options = {
batchSize: 100,
comment: 'test',
maxTimeMS: 500,
readPreference: ReadPreference.primary
};
describe('#constructor', function () {
const server = sinon.createStubInstance(Server, {});
const operation = new GetMoreOperation(ns, cursorId, server, options);
it('sets the namespace', function () {
expect(operation.ns).to.equal(ns);
});
it('sets the cursorId', function () {
expect(operation.cursorId).to.equal(cursorId);
});
it('sets the server', function () {
expect(operation.server).to.equal(server);
});
it('sets the options', function () {
expect(operation.options).to.deep.equal(options);
});
});
describe('#execute', function () {
const getMoreStub = sinon.stub().yields(undefined);
const server = sinon.createStubInstance(Server, {
getMore: getMoreStub
});
const session = sinon.createStubInstance(ClientSession);
const opts = { ...options, session };
const operation = new GetMoreOperation(ns, cursorId, server, opts);
it('executes a getmore on the provided server', function (done) {
const callback = () => {
const call = getMoreStub.getCall(0);
expect(getMoreStub.calledOnce).to.be.true;
expect(call.args[0]).to.equal(ns);
expect(call.args[1]).to.equal(cursorId);
expect(call.args[2]).to.deep.equal(opts);
done();
};
operation.execute(server, session, callback);
});
});
});