Skip to content

Commit f505e97

Browse files
fix: Unmanaged entity case for composition of many. (#142)
Fix issue: 1. #79 Co-authored-by: Nick Josipovic <[email protected]>
1 parent 2380bee commit f505e97

File tree

7 files changed

+112
-1
lines changed

7 files changed

+112
-1
lines changed

lib/change-log.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,9 @@ const _formatCompositionValue = function (
216216
childNodeChange,
217217
childNodeChanges
218218
) {
219-
if (curChange.modification === "delete") {
219+
if (curChange.modification === undefined) {
220+
return
221+
} else if (curChange.modification === "delete") {
220222
curChange.valueChangedFrom = objId
221223
curChange.valueChangedTo = ""
222224
} else if (curChange.modification === "update") {

tests/bookshop/db/_i18n/i18n.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,12 @@ Level2Entity.objectTitle=Level2 Entity
6767
## Level3Entity
6868
#XTIT
6969
Level3Entity.objectTitle=Level3 Entity
70+
71+
## Schools
72+
#XTIT
73+
Schools.name=Name
74+
75+
## Classes
76+
#XTIT
77+
Classes.name=Name
78+
Classes.teacher=Teacher
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ID;up__ID;name;teacher
2+
9d703c23-54a8-4eff-81c1-cdce6b0528c4;5ab2a87b-3a56-4d97-a697-7af72333c123;History 400;Ms. Davis
3+
9d703c23-54a8-4eff-81c1-cdec5a0422c3;5ab2a87b-3a56-4d97-a697-7af72333c123;Physics 500;Mrs. Johnson
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
ID;name;location
2+
64625905-c234-4d0d-9bc1-283ee8958331;Sunshine Elementary School;San Francisco
3+
5ab2a87b-3a56-4d97-a697-7af72333c123;Blue Sky High School;Los Angeles
4+
8aaed432-8336-4b0d-be7e-3ef1ce7f23ea;Starlight Middle School;San Diego

tests/bookshop/db/schema.cds

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,3 +281,17 @@ entity Children : managed {
281281
@changelog
282282
key two : Association to one SecondEntity;
283283
}
284+
285+
// Test for Unmanaged entity
286+
entity Schools : managed, cuid {
287+
@title: '{i18n>Schools.name}'
288+
name : String;
289+
location : String;
290+
classes : Composition of many {
291+
key ID : UUID;
292+
@title: '{i18n>Classes.name}'
293+
name : String;
294+
@title: '{i18n>Classes.teacher}'
295+
teacher : String;
296+
};
297+
}

tests/bookshop/srv/admin-service.cds

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ service AdminService {
77
@odata.draft.enabled
88
entity RootEntity @(cds.autoexpose) as projection on my.RootEntity;
99

10+
@odata.draft.enabled
11+
entity Schools @(cds.autoexpose) as projection on my.Schools;
12+
1013
entity RootObject as projection on my.RootObject;
1114
entity Level1Object as projection on my.Level1Object;
1215
entity Level2Object as projection on my.Level2Object;
@@ -171,3 +174,7 @@ annotate AdminService.Customers with {
171174
country @changelog;
172175
age @changelog;
173176
}
177+
178+
annotate AdminService.Schools with {
179+
classes @changelog : [classes.name, classes.teacher]
180+
};

tests/integration/fiori-draft-enabled.test.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,33 @@ describe("change log integration test", () => {
248248
expect(isUsedChange.entity).to.equal("Book");
249249
expect(isUsedChange.valueChangedFrom).to.equal("");
250250
expect(isUsedChange.valueChangedTo).to.equal("true");
251+
252+
// Test for Unmanaged entity(Create)
253+
const unmanagedAction = POST.bind(
254+
{},
255+
`/odata/v4/admin/Schools(ID=5ab2a87b-3a56-4d97-a697-7af72333c123,IsActiveEntity=false)/classes`,
256+
{
257+
ID: "9d703c23-54a8-4eff-81c1-cdec5c4267c5",
258+
name: "Biology 101",
259+
teacher: "Mr. Smith",
260+
up__ID: "9d703c23-54a8-4eff-81c1-cdce6b0528c4"
261+
}
262+
);
263+
await utils.apiAction("admin", "Schools", "5ab2a87b-3a56-4d97-a697-7af72333c123", "AdminService", unmanagedAction);
264+
const schoolChanges = await adminService.run(
265+
SELECT.from(ChangeView).where({
266+
entity: "sap.capire.bookshop.Schools",
267+
attribute: "classes",
268+
})
269+
);
270+
271+
expect(schoolChanges.length).to.equal(1);
272+
const schoolChange = schoolChanges[0];
273+
expect(schoolChange.entityKey).to.equal("5ab2a87b-3a56-4d97-a697-7af72333c123");
274+
expect(schoolChange.attribute).to.equal("classes");
275+
expect(schoolChange.modification).to.equal("Create");
276+
expect(schoolChange.valueChangedFrom).to.equal("");
277+
expect(schoolChange.valueChangedTo).to.equal("Biology 101, Mr. Smith");
251278
});
252279

253280
it("2.2 Child entity update - should log basic data type changes (ERP4SMEPREPWORKAPPPLAT-32 ERP4SMEPREPWORKAPPPLAT-613)", async () => {
@@ -357,6 +384,33 @@ describe("change log integration test", () => {
357384

358385
expect(priceChanges.length).to.equal(0);
359386

387+
// Test for Unmanaged entity(Create)
388+
const unmanagedAction = POST.bind(
389+
{},
390+
`/odata/v4/admin/Schools(ID=5ab2a87b-3a56-4d97-a697-7af72333c123,IsActiveEntity=false)/classes`,
391+
{
392+
ID: "9d703c23-54a8-4eff-81c1-cdec5c4267c5",
393+
name: "Biology 101",
394+
teacher: "Mr. Smith",
395+
up__ID: "9d703c23-54a8-4eff-81c1-cdce6b0528c4"
396+
}
397+
);
398+
await utils.apiAction("admin", "Schools", "5ab2a87b-3a56-4d97-a697-7af72333c123", "AdminService", unmanagedAction);
399+
const schoolChanges = await adminService.run(
400+
SELECT.from(ChangeView).where({
401+
entity: "sap.capire.bookshop.Schools",
402+
attribute: "classes",
403+
})
404+
);
405+
406+
expect(schoolChanges.length).to.equal(1);
407+
const schoolChange = schoolChanges[0];
408+
expect(schoolChange.entityKey).to.equal("5ab2a87b-3a56-4d97-a697-7af72333c123");
409+
expect(schoolChange.attribute).to.equal("classes");
410+
expect(schoolChange.modification).to.equal("Create");
411+
expect(schoolChange.valueChangedFrom).to.equal("");
412+
expect(schoolChange.valueChangedTo).to.equal("Biology 101, Mr. Smith");
413+
360414
delete cds.services.AdminService.entities.Books.elements.price["@changelog"];
361415
});
362416

@@ -431,6 +485,24 @@ describe("change log integration test", () => {
431485
expect(volumnTitleChange.entity).to.equal("Volumn");
432486
expect(volumnTitleChange.valueChangedFrom).to.equal("Wuthering Heights I");
433487
expect(volumnTitleChange.valueChangedTo).to.equal("");
488+
489+
// Test for Unmanaged entity(Delete)
490+
const unmanagedAction = DELETE.bind({},`/odata/v4/admin/Schools_classes(up__ID=5ab2a87b-3a56-4d97-a697-7af72333c123,ID=9d703c23-54a8-4eff-81c1-cdec5a0422c3,IsActiveEntity=false)`);
491+
await utils.apiAction("admin", "Schools", "5ab2a87b-3a56-4d97-a697-7af72333c123", "AdminService", unmanagedAction);
492+
const schoolChanges = await adminService.run(
493+
SELECT.from(ChangeView).where({
494+
entity: "sap.capire.bookshop.Schools",
495+
attribute: "classes",
496+
})
497+
);
498+
499+
expect(schoolChanges.length).to.equal(1);
500+
const schoolChange = schoolChanges[0];
501+
expect(schoolChange.entityKey).to.equal("5ab2a87b-3a56-4d97-a697-7af72333c123");
502+
expect(schoolChange.attribute).to.equal("classes");
503+
expect(schoolChange.modification).to.equal("Delete");
504+
expect(schoolChange.valueChangedFrom).to.equal("Physics 500, Mrs. Johnson");
505+
expect(schoolChange.valueChangedTo).to.equal("");
434506
});
435507

436508
it("2.4 Child entity update without objectID annotation - should log object type for object ID (ERP4SMEPREPWORKAPPPLAT-32 ERP4SMEPREPWORKAPPPLAT-613 ERP4SMEPREPWORKAPPPLAT-538)", async () => {

0 commit comments

Comments
 (0)