Skip to content

Commit

Permalink
Fix delete nothing
Browse files Browse the repository at this point in the history
  • Loading branch information
schiwekM committed Oct 15, 2024
1 parent 9e2b920 commit 10cdc1a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/modification.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ const addDiffToCtx = async function (req) {

// get diff
let diff = await req.diff()
// //Defaulting to an empty object in cases where no diff exists
// This happens when a DELETE or UPDATE has a where clause but does not DELETE or UPDATE anything
diff ??= {};
diff = _getDataWithAppliedTransitions(diff, req)

// add keys, if necessary
Expand Down
12 changes: 12 additions & 0 deletions test/personal-data/crud.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,18 @@ describe('personal data audit logging in CRUD', () => {
})
})

test('delete non existing entity does not cause any logs', async () => {
const {Pages} = cds.entities('CRUD_1');
await cds.delete(Pages).where(`ID = 123456789`);

expect(_logs).not.toContainMatchObject({
object: {
type: 'CRUD_1.Pages',
id: { ID: 123456789 }
}
})
});

test('delete Pages with integers - flat', async () => {
await DELETE('/crud-1/Pages(1)', { auth: ALICE })

Expand Down

0 comments on commit 10cdc1a

Please sign in to comment.