Skip to content

Commit f726080

Browse files
committed
Consider @changelog: false on an entity level
1 parent a2723ae commit f726080

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

cds-plugin.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const hasParent = 'change-tracking-parentEntity';
77

88
const isChangeTracked = (entity) => {
99
if (entity.query?.SET?.op === 'union') return false; // REVISIT: should that be an error or warning?
10+
if (entity['@changelog'] === false) return false;
1011
if (entity['@changelog']) return true;
1112
if (Object.values(entity.elements).some((e) => e['@changelog'])) return true;
1213
return false;

tests/bookshop/srv/feature-testing.cds

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ using {sap.change_tracking as my} from '../db/index';
22
using {sap.changelog as change} from '@cap-js/change-tracking';
33

44
service VariantTesting {
5+
@cds.redirection.target
56
entity DifferentFieldTypes as projection on my.DifferentFieldTypes;
67

78
entity RootSample as projection on my.RootSample;
@@ -15,4 +16,7 @@ service VariantTesting {
1516

1617
entity ChangeView as projection on change.ChangeView;
1718

19+
@changelog: false
20+
entity NotTrackedDifferentFieldTypes as projection on my.DifferentFieldTypes;
21+
1822
}

tests/integration/configuration.test.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const cds = require('@sap/cds');
22
const path = require('path');
33

44
const bookshop = path.resolve(__dirname, './../bookshop');
5-
const { POST, DELETE, GET } = cds.test(bookshop);
5+
const { POST, PATCH, DELETE, GET } = cds.test(bookshop);
66

77
describe('Configuration scenarios', () => {
88
it('When preserveDeletes is enabled, all changelogs should be retained after the root entity is deleted, and a changelog for the deletion operation should be generated', async () => {
@@ -180,6 +180,28 @@ describe('Configuration scenarios', () => {
180180
expect(changes2.length).toEqual(1);
181181
});
182182
});
183+
184+
it('Should not track if entity is annotated @changelog: false', async () => {
185+
const { data: record } = await POST(`/odata/v4/variant-testing/DifferentFieldTypes`, {
186+
number: 1,
187+
bool: true,
188+
title: 'My test-record'
189+
});
190+
191+
await PATCH(`/odata/v4/variant-testing/NotTrackedDifferentFieldTypes(ID=${record.ID})`, {
192+
number: 2,
193+
bool: false
194+
});
195+
196+
const {
197+
data: { value: changes }
198+
} = await GET(`/odata/v4/variant-testing/NotTrackedDifferentFieldTypes(ID=${record.ID})/changes`);
199+
200+
const createChanges = changes.filter((c) => c.modification === 'Create');
201+
const updateChanges = changes.filter((c) => c.modification === 'Update');
202+
expect(createChanges.length).toEqual(2);
203+
expect(updateChanges.length).toEqual(0);
204+
});
183205
});
184206

185207
describe('MTX Build', () => {

0 commit comments

Comments
 (0)