Skip to content

Commit 724174c

Browse files
test(model): make tests more strict by asserting timestamps option doesn't matter when passing overwriteImmutable and updating createdAt
1 parent 13d27bc commit 724174c

File tree

1 file changed

+35
-34
lines changed

1 file changed

+35
-34
lines changed

test/model.updateOne.test.js

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2680,7 +2680,7 @@ describe('model: updateOne: ', function() {
26802680
assert.equal(doc.age, 20);
26812681
});
26822682

2683-
describe('bulkWrite overwriteImmutable option (gh-15781)', function() {
2683+
describe.only('bulkWrite overwriteImmutable option (gh-15781)', function() {
26842684
it('updateOne can update immutable field with overwriteImmutable: true', async function() {
26852685
// Arrange
26862686
const { User } = createTestContext();
@@ -2761,46 +2761,47 @@ describe('model: updateOne: ', function() {
27612761
assert.equal(updatesDocs[0].createdAt.valueOf(), createdAt.valueOf());
27622762
assert.equal(updatesDocs[1].createdAt.valueOf(), createdAt.valueOf());
27632763
});
2764-
}
27652764

2766-
it('can not update immutable fields without overwriteImmutable: true', async function() {
2765+
it(`can not update immutable fields without overwriteImmutable: true and timestamps: ${timestamps}`, async function() {
27672766
// Arrange
2768-
const { User } = createTestContext();
2769-
const users = await User.create([
2770-
{ name: 'Bob', ssn: '222-22-2222' },
2771-
{ name: 'Eve', ssn: '333-33-3333' }
2772-
]);
2773-
const newCreatedAt = new Date('2020-01-01');
2774-
2775-
// Act
2776-
await User.bulkWrite([
2777-
{
2778-
updateOne: {
2779-
filter: { _id: users[0]._id },
2780-
update: { ssn: '888-88-8888', createdAt: newCreatedAt }
2781-
}
2767+
const { User } = createTestContext();
2768+
const users = await User.create([
2769+
{ name: 'Bob', ssn: '222-22-2222' },
2770+
{ name: 'Eve', ssn: '333-33-3333' }
2771+
]);
2772+
const newCreatedAt = new Date('2020-01-01');
27822773

2783-
},
2784-
{
2785-
updateMany: {
2786-
filter: { _id: users[1]._id },
2787-
update: { ssn: '777-77-7777', createdAt: newCreatedAt }
2774+
// Act
2775+
await User.bulkWrite([
2776+
{
2777+
updateOne: {
2778+
filter: { _id: users[0]._id },
2779+
update: { ssn: '888-88-8888', createdAt: newCreatedAt }
2780+
},
2781+
timestamps
2782+
},
2783+
{
2784+
updateMany: {
2785+
filter: { _id: users[1]._id },
2786+
update: { ssn: '777-77-7777', createdAt: newCreatedAt }
2787+
},
2788+
timestamps
27882789
}
2789-
}
2790-
]);
2790+
]);
27912791

27922792

2793-
// Assert
2794-
const [updatedUser1, updatedUser2] = await Promise.all([
2795-
User.findById(users[0]._id),
2796-
User.findById(users[1]._id)
2797-
]);
2798-
assert.strictEqual(updatedUser1.ssn, '222-22-2222');
2799-
assert.notStrictEqual(updatedUser1.createdAt.valueOf(), newCreatedAt.valueOf());
2793+
// Assert
2794+
const [updatedUser1, updatedUser2] = await Promise.all([
2795+
User.findById(users[0]._id),
2796+
User.findById(users[1]._id)
2797+
]);
2798+
assert.strictEqual(updatedUser1.ssn, '222-22-2222');
2799+
assert.notStrictEqual(updatedUser1.createdAt.valueOf(), newCreatedAt.valueOf());
28002800

2801-
assert.strictEqual(updatedUser2.ssn, '333-33-3333');
2802-
assert.notStrictEqual(updatedUser2.createdAt.valueOf(), newCreatedAt.valueOf());
2803-
});
2801+
assert.strictEqual(updatedUser2.ssn, '333-33-3333');
2802+
assert.notStrictEqual(updatedUser2.createdAt.valueOf(), newCreatedAt.valueOf());
2803+
});
2804+
}
28042805

28052806
function createTestContext() {
28062807
const userSchema = new Schema({

0 commit comments

Comments
 (0)