Skip to content

Commit b2b8a72

Browse files
committed
test: add null tests
1 parent 710dc0e commit b2b8a72

File tree

1 file changed

+58
-20
lines changed

1 file changed

+58
-20
lines changed

test/integration/crud/find_and_modify.test.ts

Lines changed: 58 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,24 @@ describe('Collection (#findOneAnd...)', function () {
4545
await client?.close();
4646
});
4747

48-
it('returns the deleted document', async function () {
49-
const result = await collection.findOneAndDelete(
50-
{ a: 1 },
51-
{ includeResultMetadata: false }
52-
);
53-
expect(result.b).to.equal(1);
48+
context('when there is a match', function () {
49+
it('returns the deleted document', async function () {
50+
const result = await collection.findOneAndDelete(
51+
{ a: 1 },
52+
{ includeResultMetadata: false }
53+
);
54+
expect(result.b).to.equal(1);
55+
});
56+
});
57+
58+
context('when there is no match', function () {
59+
it('returns null', async function () {
60+
const result = await collection.findOneAndDelete(
61+
{ a: 2 },
62+
{ includeResultMetadata: false }
63+
);
64+
expect(result).to.equal(null);
65+
});
5466
});
5567
});
5668

@@ -179,13 +191,26 @@ describe('Collection (#findOneAnd...)', function () {
179191
await client?.close();
180192
});
181193

182-
it('returns the modified document', async function () {
183-
const result = await collection.findOneAndUpdate(
184-
{ a: 1 },
185-
{ $set: { a: 1 } },
186-
{ includeResultMetadata: false }
187-
);
188-
expect(result.b).to.equal(1);
194+
context('when there is a match', function () {
195+
it('returns the modified document', async function () {
196+
const result = await collection.findOneAndUpdate(
197+
{ a: 1 },
198+
{ $set: { a: 1 } },
199+
{ includeResultMetadata: false }
200+
);
201+
expect(result.b).to.equal(1);
202+
});
203+
});
204+
205+
context('when there is no match', function () {
206+
it('returns null', async function () {
207+
const result = await collection.findOneAndUpdate(
208+
{ a: 2 },
209+
{ $set: { a: 1 } },
210+
{ includeResultMetadata: false }
211+
);
212+
expect(result).to.equal(null);
213+
});
189214
});
190215
});
191216

@@ -344,13 +369,26 @@ describe('Collection (#findOneAnd...)', function () {
344369
await client?.close();
345370
});
346371

347-
it('returns the replaced document', async function () {
348-
const result = await collection.findOneAndReplace(
349-
{ a: 1 },
350-
{ a: 1 },
351-
{ includeResultMetadata: false }
352-
);
353-
expect(result.b).to.equal(1);
372+
context('when there is a match', function () {
373+
it('returns the replaced document', async function () {
374+
const result = await collection.findOneAndReplace(
375+
{ a: 1 },
376+
{ a: 1 },
377+
{ includeResultMetadata: false }
378+
);
379+
expect(result.b).to.equal(1);
380+
});
381+
});
382+
383+
context('when there is no match', function () {
384+
it('returns null', async function () {
385+
const result = await collection.findOneAndReplace(
386+
{ a: 2 },
387+
{ a: 1 },
388+
{ includeResultMetadata: false }
389+
);
390+
expect(result).to.equal(null);
391+
});
354392
});
355393
});
356394

0 commit comments

Comments
 (0)