Skip to content

Commit 3d73bee

Browse files
committed
chore: pass ignoreUndefined
1 parent e884537 commit 3d73bee

File tree

3 files changed

+129
-98
lines changed

3 files changed

+129
-98
lines changed

test/integration/crud/bulk.test.ts

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -48,37 +48,49 @@ describe('Bulk', function () {
4848

4949
describe('#bulkWrite', function () {
5050
context('when including an update with all undefined atomic operators', function () {
51-
context('when performing an update many', function () {
52-
it('throws an error', async function () {
53-
const collection = client.db('test').collection('test');
54-
const error = await collection
55-
.bulkWrite([
56-
{
57-
updateMany: {
58-
filter: { age: { $lte: 5 } },
59-
update: { $set: undefined, $unset: undefined }
60-
}
61-
}
62-
])
63-
.catch(error => error);
64-
expect(error.message).to.include('All atomic operators provided have undefined values.');
51+
context('when ignoreUndefined is true', function () {
52+
context('when performing an update many', function () {
53+
it('throws an error', async function () {
54+
const collection = client.db('test').collection('test');
55+
const error = await collection
56+
.bulkWrite(
57+
[
58+
{
59+
updateMany: {
60+
filter: { age: { $lte: 5 } },
61+
update: { $set: undefined, $unset: undefined }
62+
}
63+
}
64+
],
65+
{ ignoreUndefined: true }
66+
)
67+
.catch(error => error);
68+
expect(error.message).to.include(
69+
'All atomic operators provided have undefined values.'
70+
);
71+
});
6572
});
66-
});
6773

68-
context('when performing an update one', function () {
69-
it('throws an error', async function () {
70-
const collection = client.db('test').collection('test');
71-
const error = await collection
72-
.bulkWrite([
73-
{
74-
updateOne: {
75-
filter: { age: { $lte: 5 } },
76-
update: { $set: undefined, $unset: undefined }
77-
}
78-
}
79-
])
80-
.catch(error => error);
81-
expect(error.message).to.include('All atomic operators provided have undefined values.');
74+
context('when performing an update one', function () {
75+
it('throws an error', async function () {
76+
const collection = client.db('test').collection('test');
77+
const error = await collection
78+
.bulkWrite(
79+
[
80+
{
81+
updateOne: {
82+
filter: { age: { $lte: 5 } },
83+
update: { $set: undefined, $unset: undefined }
84+
}
85+
}
86+
],
87+
{ ignoreUndefined: true }
88+
)
89+
.catch(error => error);
90+
expect(error.message).to.include(
91+
'All atomic operators provided have undefined values.'
92+
);
93+
});
8294
});
8395
});
8496
});

test/integration/crud/client_bulk_write.test.ts

Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -35,44 +35,56 @@ describe('Client Bulk Write', function () {
3535
});
3636

3737
describe('#bulkWrite', function () {
38-
context('when including an update with all undefined atomic operators', function () {
39-
context('when performing an update many', function () {
40-
beforeEach(async function () {
41-
client = this.configuration.newClient();
42-
});
38+
context('when ignoreUndefined is true', function () {
39+
context('when including an update with all undefined atomic operators', function () {
40+
context('when performing an update many', function () {
41+
beforeEach(async function () {
42+
client = this.configuration.newClient();
43+
});
4344

44-
it('throws an error', async function () {
45-
const error = await client
46-
.bulkWrite([
47-
{
48-
name: 'updateMany',
49-
namespace: 'foo.bar',
50-
filter: { age: { $lte: 5 } },
51-
update: { $set: undefined, $unset: undefined }
52-
}
53-
])
54-
.catch(error => error);
55-
expect(error.message).to.include('All atomic operators provided have undefined values.');
45+
it('throws an error', async function () {
46+
const error = await client
47+
.bulkWrite(
48+
[
49+
{
50+
name: 'updateMany',
51+
namespace: 'foo.bar',
52+
filter: { age: { $lte: 5 } },
53+
update: { $set: undefined, $unset: undefined }
54+
}
55+
],
56+
{ ignoreUndefined: true }
57+
)
58+
.catch(error => error);
59+
expect(error.message).to.include(
60+
'All atomic operators provided have undefined values.'
61+
);
62+
});
5663
});
57-
});
5864

59-
context('when performing an update one', function () {
60-
beforeEach(async function () {
61-
client = this.configuration.newClient();
62-
});
65+
context('when performing an update one', function () {
66+
beforeEach(async function () {
67+
client = this.configuration.newClient();
68+
});
6369

64-
it('throws an error', async function () {
65-
const error = await client
66-
.bulkWrite([
67-
{
68-
name: 'updateOne',
69-
namespace: 'foo.bar',
70-
filter: { age: { $lte: 5 } },
71-
update: { $set: undefined, $unset: undefined }
72-
}
73-
])
74-
.catch(error => error);
75-
expect(error.message).to.include('All atomic operators provided have undefined values.');
70+
it('throws an error', async function () {
71+
const error = await client
72+
.bulkWrite(
73+
[
74+
{
75+
name: 'updateOne',
76+
namespace: 'foo.bar',
77+
filter: { age: { $lte: 5 } },
78+
update: { $set: undefined, $unset: undefined }
79+
}
80+
],
81+
{ ignoreUndefined: true }
82+
)
83+
.catch(error => error);
84+
expect(error.message).to.include(
85+
'All atomic operators provided have undefined values.'
86+
);
87+
});
7688
});
7789
});
7890
});

test/integration/crud/crud_api.test.ts

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ import {
1515
ReturnDocument
1616
} from '../../mongodb';
1717
import { type FailPoint } from '../../tools/utils';
18-
import { assert as test } from '../shared';
19-
2018
// instanceof cannot be use reliably to detect the new models in js due to scoping and new
2119
// contexts killing class info find/distinct/count thus cannot be overloaded without breaking
2220
// backwards compatibility in a fundamental way
@@ -908,18 +906,21 @@ describe('CRUD API', function () {
908906
await collection.drop();
909907
});
910908

911-
context('when including an update with all undefined atomic operators', function () {
912-
beforeEach(async function () {
913-
client = this.configuration.newClient();
914-
});
909+
context(
910+
'when including an update with all undefined atomic operators ignoring undefined',
911+
function () {
912+
beforeEach(async function () {
913+
client = this.configuration.newClient();
914+
});
915915

916-
it('throws an error', async function () {
917-
const error = await collection
918-
.updateOne({ a: 1 }, { $set: undefined, $unset: undefined })
919-
.catch(error => error);
920-
expect(error.message).to.include('All atomic operators provided have undefined values.');
921-
});
922-
});
916+
it('throws an error', async function () {
917+
const error = await collection
918+
.updateOne({ a: 1 }, { $set: undefined, $unset: undefined }, { ignoreUndefined: true })
919+
.catch(error => error);
920+
expect(error.message).to.include('All atomic operators provided have undefined values.');
921+
});
922+
}
923+
);
923924
});
924925

925926
describe('#updateMany', function () {
@@ -934,18 +935,21 @@ describe('CRUD API', function () {
934935
await collection.drop();
935936
});
936937

937-
context('when including an update with all undefined atomic operators', function () {
938-
beforeEach(async function () {
939-
client = this.configuration.newClient();
940-
});
938+
context(
939+
'when including an update with all undefined atomic operators ignoring undefined',
940+
function () {
941+
beforeEach(async function () {
942+
client = this.configuration.newClient();
943+
});
941944

942-
it('throws an error', async function () {
943-
const error = await collection
944-
.updateMany({ a: 1 }, { $set: undefined, $unset: undefined })
945-
.catch(error => error);
946-
expect(error.message).to.include('All atomic operators provided have undefined values.');
947-
});
948-
});
945+
it('throws an error', async function () {
946+
const error = await collection
947+
.updateMany({ a: 1 }, { $set: undefined, $unset: undefined }, { ignoreUndefined: true })
948+
.catch(error => error);
949+
expect(error.message).to.include('All atomic operators provided have undefined values.');
950+
});
951+
}
952+
);
949953
});
950954

951955
describe('#findOneAndUpdate', function () {
@@ -960,18 +964,21 @@ describe('CRUD API', function () {
960964
await collection.drop();
961965
});
962966

963-
context('when including an update with all undefined atomic operators', function () {
964-
beforeEach(async function () {
965-
client = this.configuration.newClient();
966-
});
967+
context(
968+
'when including an update with all undefined atomic operators ignoring undefined',
969+
function () {
970+
beforeEach(async function () {
971+
client = this.configuration.newClient();
972+
});
967973

968-
it('throws an error', async function () {
969-
const error = await collection
970-
.findOneAndUpdate({ a: 1 }, { $set: undefined, $unset: undefined })
971-
.catch(error => error);
972-
expect(error.message).to.include('All atomic operators provided have undefined values.');
973-
});
974-
});
974+
it('throws an error', async function () {
975+
const error = await collection
976+
.findOneAndUpdate({ a: 1 }, { $set: undefined, $unset: undefined })
977+
.catch(error => error);
978+
expect(error.message).to.include('All atomic operators provided have undefined values.');
979+
});
980+
}
981+
);
975982

976983
context('when includeResultMetadata is true', function () {
977984
beforeEach(async function () {

0 commit comments

Comments
 (0)