@@ -7,6 +7,9 @@ const generateTopologyTests = require('./spec-runner').generateTopologyTests;
7
7
const loadSpecTests = require ( '../spec' ) . loadSpecTests ;
8
8
const { withMonitoredClient } = require ( './shared' ) ;
9
9
10
+ const mock = require ( '../tools/mock' ) ;
11
+ const { MongoClient } = require ( '../../src' ) ;
12
+
10
13
describe ( 'Write Concern' , function ( ) {
11
14
describe ( 'spec tests' , function ( ) {
12
15
const testContext = new TestRunnerContext ( ) ;
@@ -58,4 +61,38 @@ describe('Write Concern', function () {
58
61
withMonitoredClient ( 'insert' , { queryOptions : { journal : true } } , journalOptionTest )
59
62
) ;
60
63
} ) ;
64
+
65
+ let server ;
66
+ before ( ( ) => {
67
+ return mock . createServer ( ) . then ( s => {
68
+ server = s ;
69
+ } ) ;
70
+ } ) ;
71
+
72
+ after ( ( ) => mock . cleanup ( ) ) ;
73
+
74
+ it ( 'should pipe writeConcern from client down to API call' , function ( ) {
75
+ server . setMessageHandler ( request => {
76
+ if ( request . document && request . document . ismaster ) {
77
+ return request . reply ( mock . DEFAULT_ISMASTER ) ;
78
+ }
79
+ expect ( request . document . writeConcern ) . to . exist ;
80
+ expect ( request . document . writeConcern . w ) . to . equal ( 'majority' ) ;
81
+ return request . reply ( { ok : 1 } ) ;
82
+ } ) ;
83
+
84
+ const uri = `mongodb://${ server . uri ( ) } ` ;
85
+ const client = new MongoClient ( uri , { writeConcern : 'majority' } ) ;
86
+ return client
87
+ . connect ( )
88
+ . then ( ( ) => {
89
+ const db = client . db ( 'wc_test' ) ;
90
+ const collection = db . collection ( 'wc' ) ;
91
+
92
+ return collection . insertMany ( [ { a : 2 } ] ) ;
93
+ } )
94
+ . then ( ( ) => {
95
+ return client . close ( ) ;
96
+ } ) ;
97
+ } ) ;
61
98
} ) ;
0 commit comments