Skip to content

Commit

Permalink
skipAutomaticSetModifiedData in update added
Browse files Browse the repository at this point in the history
  • Loading branch information
mdanelutti committed Sep 13, 2023
1 parent ebfa779 commit 75f3f2b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,10 +510,12 @@ class Model {
const db = await this.getDb();
this.validateMethodImplemented(db, 'update');

if(Array.isArray(values))
values.push(this.addModifiedData());
else
this.addModifiedData(values);
if(!params?.skipAutomaticSetModifiedData) {
if(Array.isArray(values))
values.push(this.addModifiedData());
else
this.addModifiedData(values);
}

this.setExecutionStart();

Expand Down
12 changes: 12 additions & 0 deletions tests/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,18 @@ describe('Model', () => {
}, {}, undefined);
});

it('Should skip the automatically field `dateModified` if the flag `skipAutomaticSetModifiedData` is setted', async () => {

sinon.stub(DBDriver.prototype, 'update')
.resolves();

await myClientModel.update({ some: 'data' }, {}, { skipAutomaticSetModifiedData: true });

sinon.assert.calledOnceWithExactly(DBDriver.prototype.update, myClientModel, {
some: 'data'
}, {}, { skipAutomaticSetModifiedData: true });
});

it('Should add the userModified field when session exists (data is array)', async () => {

sinon.stub(DBDriver.prototype, 'update')
Expand Down

0 comments on commit 75f3f2b

Please sign in to comment.