This repository was archived by the owner on Feb 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 106
/
Copy pathwire_protocol_test.js
47 lines (39 loc) · 1.73 KB
/
wire_protocol_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
'use strict';
const chai = require('chai');
const expect = chai.expect;
const bson = require('bson');
const sinon = require('sinon');
const Pool = require('../../../lib/connection/pool.js');
const wireProtocol2_6 = require('../../../lib/wireprotocol/2_6_support.js');
const wireProtocol3_2 = require('../../../lib/wireprotocol/3_2_support.js');
describe('WireProtocol', function() {
it('2.6 should only set bypassDocumentValidation to true if explicitly set by user to true', function() {
testPoolWrite(true, new wireProtocol2_6(), true);
});
it('2.6 should not set bypassDocumentValidation to anything if not explicitly set by user to true', function() {
testPoolWrite(false, new wireProtocol2_6(), undefined);
});
it('3.2 should only set bypassDocumentValidation to true if explicitly set by user to true', function() {
testPoolWrite(true, new wireProtocol3_2(), true);
});
it('3.2 should not set bypassDocumentValidation to anything if not explicitly set by user to true', function() {
testPoolWrite(false, new wireProtocol3_2(), undefined);
});
function testPoolWrite(bypassDocumentValidation, wireProtocol, expected) {
const pool = sinon.createStubInstance(Pool);
const isMaster = {};
const ns = 'fake.namespace';
const ops = [{ a: 1 }, { b: 2 }];
const options = { bypassDocumentValidation: bypassDocumentValidation };
wireProtocol.insert(pool, isMaster, ns, bson, ops, options, () => {});
if (expected) {
expect(pool.write.lastCall.args[0])
.to.have.nested.property('query.bypassDocumentValidation')
.that.equals(expected);
} else {
expect(pool.write.lastCall.args[0]).to.not.have.nested.property(
'query.bypassDocumentValidation'
);
}
}
});