-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
find_cursor.test.js
71 lines (63 loc) · 2.11 KB
/
find_cursor.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
64
65
66
67
68
69
70
71
'use strict';
const expect = require('chai').expect;
const { MongoError } = require('../../../src/error');
const mock = require('../../tools/mock');
const { Topology } = require('../../../src/sdam/topology');
const { Long } = require('bson');
const { MongoDBNamespace } = require('../../../src/utils');
const { FindCursor } = require('../../../src/cursor/find_cursor');
const test = {};
describe('Find Cursor', function () {
describe('Response', function () {
afterEach(() => mock.cleanup());
beforeEach(() => {
return mock.createServer().then(mockServer => {
test.server = mockServer;
});
});
it('should throw when document is error', {
metadata: { requires: { topology: ['single'] } },
test: function (done) {
const errdoc = {
errmsg: 'Cursor not found (namespace: "liveearth.entityEvents", id: 2018648316188432590).'
};
const client = new Topology(test.server.hostAddress());
test.server.setMessageHandler(request => {
const doc = request.document;
if (doc.ismaster || doc.hello) {
request.reply(
Object.assign({}, mock.DEFAULT_ISMASTER, {
maxWireVersion: 6
})
);
} else if (doc.find) {
request.reply({
cursor: {
id: Long.fromNumber(1),
ns: 'test.test',
firstBatch: []
},
ok: 1
});
} else if (doc.getMore) {
request.reply(errdoc);
} else if (doc.killCursors) {
request.reply({ ok: 1 });
}
});
client.on('error', done);
client.once('connect', () => {
const cursor = new FindCursor(client, MongoDBNamespace.fromString('test.test'), {}, {});
// Execute next
cursor.next(function (err) {
expect(err).to.exist;
expect(err).to.be.instanceof(MongoError);
expect(err.message).to.equal(errdoc.errmsg);
client.close(done);
});
});
client.connect();
}
});
});
});