MCPcopy
hub / github.com/mongodb/node-mongodb-native / testFindOneAndUpdate

Function testFindOneAndUpdate

test/unit/collection.test.ts:71–98  ·  view source on GitHub ↗
(config)

Source from the content-addressed store, hash-verified

69
70 context('#findOneAndModify', () => {
71 async function testFindOneAndUpdate(config) {
72 const client = new MongoClient(`mongodb://${server.uri()}/test`);
73
74 server.setMessageHandler(request => {
75 const doc = request.document;
76 if (doc.findAndModify) {
77 expect(doc.bypassDocumentValidation).equal(config.expected);
78 request.reply({
79 ok: 1
80 });
81 }
82
83 if (isHello(doc)) {
84 request.reply(Object.assign({}, HELLO));
85 } else if (doc.endSessions) {
86 request.reply({ ok: 1 });
87 }
88 });
89
90 await client.connect();
91 const db = client.db('test');
92 const collection = db.collection('test_c');
93
94 const options = { bypassDocumentValidation: config.actual };
95
96 await collection.findOneAndUpdate({ name: 'Andy' }, { $inc: { score: 1 } }, options);
97 await client.close();
98 }
99
100 it('should only set bypass document validation if strictly true in findOneAndUpdate', async function () {
101 await testFindOneAndUpdate({ expected: true, actual: true });

Callers 1

collection.test.tsFile · 0.85

Calls 8

connectMethod · 0.95
dbMethod · 0.95
closeMethod · 0.95
isHelloFunction · 0.90
setMessageHandlerMethod · 0.80
findOneAndUpdateMethod · 0.80
collectionMethod · 0.65
uriMethod · 0.45

Tested by

no test coverage detected