Skip to content

Commit 7b75770

Browse files
committed
fix: tests
1 parent d96dc4f commit 7b75770

File tree

6 files changed

+55
-52
lines changed

6 files changed

+55
-52
lines changed

test/integration/crud/crud_api.test.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -634,30 +634,30 @@ describe('CRUD API', function () {
634634
await collection.drop();
635635
});
636636

637-
context('when returnRawResult is false', function () {
637+
context('when includeResultMetadata is true', function () {
638638
beforeEach(async function () {
639639
await collection.insertMany([{ a: 1, b: 1 }], { writeConcern: { w: 1 } });
640640
});
641641

642642
it('returns the modify result', async function () {
643643
const result = await collection.findOneAndDelete(
644644
{ a: 1 },
645-
{ projection: { b: 1 }, sort: { a: 1 }, returnRawResult: false }
645+
{ projection: { b: 1 }, sort: { a: 1 } }
646646
);
647647
expect(result?.lastErrorObject.n).to.equal(1);
648648
expect(result?.value.b).to.equal(1);
649649
});
650650
});
651651

652-
context('when returnRawResult is true', function () {
652+
context('when includeResultMetadata is false', function () {
653653
beforeEach(async function () {
654654
await collection.insertMany([{ a: 1, b: 1 }], { writeConcern: { w: 1 } });
655655
});
656656

657657
it('returns the deleted document', async function () {
658658
const result = await collection.findOneAndDelete(
659659
{ a: 1 },
660-
{ projection: { b: 1 }, sort: { a: 1 } }
660+
{ projection: { b: 1 }, sort: { a: 1 }, includeResultMetadata: false }
661661
);
662662
expect(result?.b).to.equal(1);
663663
});
@@ -681,7 +681,7 @@ describe('CRUD API', function () {
681681
await collection.drop();
682682
});
683683

684-
context('when returnRawResult is false', function () {
684+
context('when includeResultMetadata is true', function () {
685685
beforeEach(async function () {
686686
await collection.insertMany([{ a: 1, b: 1 }], { writeConcern: { w: 1 } });
687687
});
@@ -694,8 +694,7 @@ describe('CRUD API', function () {
694694
projection: { b: 1, c: 1 },
695695
sort: { a: 1 },
696696
returnDocument: ReturnDocument.AFTER,
697-
upsert: true,
698-
returnRawResult: false
697+
upsert: true
699698
}
700699
);
701700
expect(result?.lastErrorObject.n).to.equal(1);
@@ -704,7 +703,7 @@ describe('CRUD API', function () {
704703
});
705704
});
706705

707-
context('when returnRawResult is true', function () {
706+
context('when includeResultMetadata is false', function () {
708707
beforeEach(async function () {
709708
await collection.insertMany([{ a: 1, b: 1 }], { writeConcern: { w: 1 } });
710709
});
@@ -717,7 +716,8 @@ describe('CRUD API', function () {
717716
projection: { b: 1, c: 1 },
718717
sort: { a: 1 },
719718
returnDocument: ReturnDocument.AFTER,
720-
upsert: true
719+
upsert: true,
720+
includeResultMetadata: false
721721
}
722722
);
723723
expect(result?.b).to.equal(1);
@@ -743,7 +743,7 @@ describe('CRUD API', function () {
743743
await collection.drop();
744744
});
745745

746-
context('when returnRawResult is false', function () {
746+
context('when includeResultMetadata is true', function () {
747747
beforeEach(async function () {
748748
await collection.insertMany([{ a: 1, b: 1 }], { writeConcern: { w: 1 } });
749749
});
@@ -756,8 +756,7 @@ describe('CRUD API', function () {
756756
projection: { b: 1, d: 1 },
757757
sort: { a: 1 },
758758
returnDocument: ReturnDocument.AFTER,
759-
upsert: true,
760-
returnRawResult: false
759+
upsert: true
761760
}
762761
);
763762
expect(result?.lastErrorObject.n).to.equal(1);
@@ -766,7 +765,7 @@ describe('CRUD API', function () {
766765
});
767766
});
768767

769-
context('when returnRawResult is true', function () {
768+
context('when includeResultMetadata is false', function () {
770769
beforeEach(async function () {
771770
await collection.insertMany([{ a: 1, b: 1 }], { writeConcern: { w: 1 } });
772771
});
@@ -779,7 +778,8 @@ describe('CRUD API', function () {
779778
projection: { b: 1, d: 1 },
780779
sort: { a: 1 },
781780
returnDocument: ReturnDocument.AFTER,
782-
upsert: true
781+
upsert: true,
782+
includeResultMetadata: false
783783
}
784784
);
785785
expect(result?.b).to.equal(1);

test/integration/crud/find.test.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -805,8 +805,8 @@ describe('Find', function () {
805805
{ $set: { b: 3 } },
806806
{ returnDocument: ReturnDocument.AFTER, projection: { a: 1 } },
807807
function (err, updated_doc) {
808-
test.equal(2, Object.keys(updated_doc).length);
809-
test.equal(1, updated_doc.a);
808+
expect(Object.keys(updated_doc.value).length).to.equal(2);
809+
expect(updated_doc.value.a).to.equal(1);
810810
client.close(done);
811811
}
812812
);
@@ -880,7 +880,7 @@ describe('Find', function () {
880880
{ $set: { name: 'test2' } },
881881
{},
882882
function (err, updated_doc) {
883-
expect(updated_doc).to.not.exist;
883+
expect(updated_doc.value).to.not.exist;
884884
test.ok(err == null || err.errmsg.match('No matching object found'));
885885
client.close(done);
886886
}
@@ -1001,8 +1001,8 @@ describe('Find', function () {
10011001
{ $set: { b: 3 } },
10021002
{ returnDocument: ReturnDocument.AFTER },
10031003
function (err, result) {
1004-
test.equal(2, result.a);
1005-
test.equal(3, result.b);
1004+
expect(result.value.a).to.equal(2);
1005+
expect(result.value.b).to.equal(3);
10061006
p_client.close(done);
10071007
}
10081008
);
@@ -1093,12 +1093,12 @@ describe('Find', function () {
10931093
{ $set: { 'c.c': 100 } },
10941094
{ returnDocument: ReturnDocument.AFTER },
10951095
function (err, item) {
1096-
test.equal(doc._id.toString(), item._id.toString());
1097-
test.equal(doc.a, item.a);
1098-
test.equal(doc.b, item.b);
1099-
test.equal(doc.c.a, item.c.a);
1100-
test.equal(doc.c.b, item.c.b);
1101-
test.equal(100, item.c.c);
1096+
expect(item.value._id.toString()).to.equal(doc._id.toString());
1097+
expect(item.value.a).to.equal(doc.a);
1098+
expect(item.value.b).to.equal(doc.b);
1099+
expect(item.value.c.a).to.equal(doc.c.a);
1100+
expect(item.value.c.b).to.equal(doc.c.b);
1101+
expect(item.value.c.c).to.equal(100);
11021102
client.close(done);
11031103
}
11041104
);
@@ -1288,7 +1288,7 @@ describe('Find', function () {
12881288
{ returnDocument: ReturnDocument.AFTER },
12891289
function (err, updated_doc) {
12901290
expect(err).to.not.exist;
1291-
expect(updated_doc).to.not.exist;
1291+
expect(updated_doc.value).to.not.exist;
12921292
client.close(done);
12931293
}
12941294
);
@@ -2160,8 +2160,8 @@ describe('Find', function () {
21602160
{ $set: { b: 3 } },
21612161
{ returnDocument: ReturnDocument.AFTER },
21622162
function (err, updated_doc) {
2163-
test.equal(1, updated_doc.a);
2164-
test.equal(3, updated_doc.b);
2163+
expect(updated_doc.value.a).to.equal(1);
2164+
expect(updated_doc.value.b).to.equal(3);
21652165

21662166
client.close(done);
21672167
}

test/integration/crud/find_and_modify.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('Collection (#findOneAnd...)', function () {
2828

2929
it('returns the raw result', async function () {
3030
const result = await collection.findOneAndDelete({ a: 1 });
31-
expect(result.b).to.equal(1);
31+
expect(result.value.b).to.equal(1);
3232
});
3333
});
3434

@@ -43,7 +43,7 @@ describe('Collection (#findOneAnd...)', function () {
4343
monitorCommands: true
4444
});
4545
client.on('commandStarted', function (event) {
46-
if (event.commandName === 'findAndModify') started.push(event);
46+
if (event.commandName === 'findAndModify') started.push(event.command);
4747
});
4848
collection = client.db('test').collection('findAndModifyTest');
4949
await collection.insertMany([{ a: 1, b: 1 }], { writeConcern: { w: 1 } });
@@ -179,7 +179,7 @@ describe('Collection (#findOneAnd...)', function () {
179179

180180
it('returns the raw result', async function () {
181181
const result = await collection.findOneAndUpdate({ a: 1 }, { $set: { a: 1 } });
182-
expect(result.b).to.equal(1);
182+
expect(result.value.b).to.equal(1);
183183
});
184184
});
185185

@@ -194,7 +194,7 @@ describe('Collection (#findOneAnd...)', function () {
194194
monitorCommands: true
195195
});
196196
client.on('commandStarted', function (event) {
197-
if (event.commandName === 'findAndModify') started.push(event);
197+
if (event.commandName === 'findAndModify') started.push(event.command);
198198
});
199199
collection = client.db('test').collection('findAndModifyTest');
200200
await collection.insertMany([{ a: 1, b: 1 }], { writeConcern: { w: 1 } });
@@ -240,7 +240,7 @@ describe('Collection (#findOneAnd...)', function () {
240240

241241
it('returns the raw result', async function () {
242242
const result = await collection.findOneAndUpdate({ a: 1 }, { $set: { a: 1 } });
243-
expect(result.b).to.equal(1);
243+
expect(result.value.b).to.equal(1);
244244
});
245245
}
246246
});
@@ -365,7 +365,7 @@ describe('Collection (#findOneAnd...)', function () {
365365

366366
it('returns the raw result', async function () {
367367
const result = await collection.findOneAndReplace({ a: 1 }, { a: 1 });
368-
expect(result.b).to.equal(1);
368+
expect(result.value.b).to.equal(1);
369369
});
370370
});
371371

@@ -380,7 +380,7 @@ describe('Collection (#findOneAnd...)', function () {
380380
monitorCommands: true
381381
});
382382
client.on('commandStarted', function (event) {
383-
if (event.commandName === 'findAndModify') started.push(event);
383+
if (event.commandName === 'findAndModify') started.push(event.command);
384384
});
385385
collection = client.db('test').collection('findAndModifyTest');
386386
await collection.insertMany([{ a: 1, b: 1 }], { writeConcern: { w: 1 } });
@@ -484,7 +484,7 @@ describe('Collection (#findOneAnd...)', function () {
484484

485485
it('passes through the writeConcern', async function () {
486486
await collection.findOneAndReplace({}, { b: 1 });
487-
expect(started[0].command.writeConcern).to.deep.equal({ fsync: 1 });
487+
expect(started[0].command.writeConcern).to.deep.equal({ w: 1 });
488488
});
489489
});
490490

@@ -514,7 +514,7 @@ describe('Collection (#findOneAnd...)', function () {
514514

515515
it('passes through the writeConcern', async function () {
516516
await collection.findOneAndReplace({}, { b: 1 });
517-
expect(started[0].command.writeConcern).to.deep.equal({ fsync: 1 });
517+
expect(started[0].command.writeConcern).to.deep.equal({ w: 1 });
518518
});
519519
});
520520
}

test/integration/crud/insert.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ describe('crud - insert', function () {
886886
serializeFunctions: true
887887
},
888888
function (err, result) {
889-
test.ok(result.f._bsontype === 'Code');
889+
test.ok(result.value.f._bsontype === 'Code');
890890
client.close(done);
891891
}
892892
);

test/integration/node-specific/operation_examples.test.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -940,8 +940,8 @@ describe('Operations', function () {
940940
);
941941
})
942942
.then(function (doc) {
943-
expect(doc.a).to.equal(1);
944-
expect(doc.b1).to.equal(1);
943+
expect(doc.value.a).to.equal(1);
944+
expect(doc.value.b1).to.equal(1);
945945

946946
// Simple findAndModify command returning the new document and
947947
// removing it at the same time
@@ -965,8 +965,8 @@ describe('Operations', function () {
965965
);
966966
})
967967
.then(function (doc) {
968-
expect(doc.d).to.equal(1);
969-
expect(doc.f).to.equal(1);
968+
expect(doc.value.d).to.equal(1);
969+
expect(doc.value.f).to.equal(1);
970970
return client.close();
971971
});
972972
});
@@ -1014,8 +1014,8 @@ describe('Operations', function () {
10141014
return collection.findOneAndDelete({ b: 1 }, [['b', 1]]);
10151015
})
10161016
.then(function (doc) {
1017-
expect(doc.b).to.equal(1);
1018-
expect(doc.d).to.equal(1);
1017+
expect(doc.value.b).to.equal(1);
1018+
expect(doc.value.d).to.equal(1);
10191019

10201020
// Verify that the document is gone
10211021
return collection.findOne({ b: 1 });
@@ -4259,7 +4259,8 @@ describe('Operations', function () {
42594259
return col.findOneAndDelete({ a: 1 }, { projection: { b: 1 }, sort: { a: 1 } });
42604260
})
42614261
.then(function (r) {
4262-
expect(r.b).to.equal(1);
4262+
expect(r.lastErrorObject.n).to.equal(1);
4263+
expect(r.value.b).to.equal(1);
42634264

42644265
return client.close();
42654266
});
@@ -4310,8 +4311,9 @@ describe('Operations', function () {
43104311
}
43114312
)
43124313
.then(function (r) {
4313-
expect(r.b).to.equal(1);
4314-
expect(r.c).to.equal(1);
4314+
expect(r.lastErrorObject.n).to.equal(1);
4315+
expect(r.value.b).to.equal(1);
4316+
expect(r.value.c).to.equal(1);
43154317

43164318
return client.close();
43174319
});
@@ -4365,8 +4367,9 @@ describe('Operations', function () {
43654367
);
43664368
})
43674369
.then(function (r) {
4368-
expect(r.b).to.equal(1);
4369-
expect(r.d).to.equal(1);
4370+
expect(r.lastErrorObject.n).to.equal(1);
4371+
expect(r.value.b).to.equal(1);
4372+
expect(r.value.d).to.equal(1);
43704373

43714374
return client.close();
43724375
});

test/tools/unified-spec-runner/operations.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,19 +317,19 @@ operations.set('findOne', async ({ entities, operation }) => {
317317
operations.set('findOneAndReplace', async ({ entities, operation }) => {
318318
const collection = entities.getEntity('collection', operation.object);
319319
const { filter, replacement, ...opts } = operation.arguments!;
320-
return await collection.findOneAndReplace(filter, replacement, translateOptions(opts));
320+
return (await collection.findOneAndReplace(filter, replacement, translateOptions(opts))).value;
321321
});
322322

323323
operations.set('findOneAndUpdate', async ({ entities, operation }) => {
324324
const collection = entities.getEntity('collection', operation.object);
325325
const { filter, update, ...opts } = operation.arguments!;
326-
return await collection.findOneAndUpdate(filter, update, translateOptions(opts));
326+
return (await collection.findOneAndUpdate(filter, update, translateOptions(opts))).value;
327327
});
328328

329329
operations.set('findOneAndDelete', async ({ entities, operation }) => {
330330
const collection = entities.getEntity('collection', operation.object);
331331
const { filter, ...opts } = operation.arguments!;
332-
return await collection.findOneAndDelete(filter, opts);
332+
return (await collection.findOneAndDelete(filter, opts)).value;
333333
});
334334

335335
operations.set('failPoint', async ({ entities, operation }) => {

0 commit comments

Comments
 (0)