Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Unmanaged entity case for composition of many. #142

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/change-log.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ const _formatCompositionValue = function (
childNodeChange,
childNodeChanges
) {
if (curChange.modification === "delete") {
if (curChange.modification === undefined) {
return
} else if (curChange.modification === "delete") {
curChange.valueChangedFrom = objId
curChange.valueChangedTo = ""
} else if (curChange.modification === "update") {
Expand Down
9 changes: 9 additions & 0 deletions tests/bookshop/db/_i18n/i18n.properties
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,12 @@ Level2Entity.objectTitle=Level2 Entity
## Level3Entity
#XTIT
Level3Entity.objectTitle=Level3 Entity

## Schools
#XTIT
Schools.name=Name

## Classes
#XTIT
Classes.name=Name
Classes.teacher=Teacher
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ID;up__ID;name;teacher
9d703c23-54a8-4eff-81c1-cdce6b0528c4;5ab2a87b-3a56-4d97-a697-7af72333c123;History 400;Ms. Davis
9d703c23-54a8-4eff-81c1-cdec5a0422c3;5ab2a87b-3a56-4d97-a697-7af72333c123;Physics 500;Mrs. Johnson
4 changes: 4 additions & 0 deletions tests/bookshop/db/data/sap.capire.bookshop-Schools.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ID;name;location
64625905-c234-4d0d-9bc1-283ee8958331;Sunshine Elementary School;San Francisco
5ab2a87b-3a56-4d97-a697-7af72333c123;Blue Sky High School;Los Angeles
8aaed432-8336-4b0d-be7e-3ef1ce7f23ea;Starlight Middle School;San Diego
14 changes: 14 additions & 0 deletions tests/bookshop/db/schema.cds
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,17 @@ entity Children : managed {
@changelog
key two : Association to one SecondEntity;
}

// Test for Unmanaged entity
entity Schools : managed, cuid {
@title: '{i18n>Schools.name}'
name : String;
location : String;
classes : Composition of many {
key ID : UUID;
@title: '{i18n>Classes.name}'
name : String;
@title: '{i18n>Classes.teacher}'
teacher : String;
};
}
7 changes: 7 additions & 0 deletions tests/bookshop/srv/admin-service.cds
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ service AdminService {
@odata.draft.enabled
entity RootEntity @(cds.autoexpose) as projection on my.RootEntity;

@odata.draft.enabled
entity Schools @(cds.autoexpose) as projection on my.Schools;

entity RootObject as projection on my.RootObject;
entity Level1Object as projection on my.Level1Object;
entity Level2Object as projection on my.Level2Object;
Expand Down Expand Up @@ -171,3 +174,7 @@ annotate AdminService.Customers with {
country @changelog;
age @changelog;
}

annotate AdminService.Schools with {
classes @changelog : [classes.name, classes.teacher]
};
72 changes: 72 additions & 0 deletions tests/integration/fiori-draft-enabled.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,33 @@ describe("change log integration test", () => {
expect(isUsedChange.entity).to.equal("Book");
expect(isUsedChange.valueChangedFrom).to.equal("");
expect(isUsedChange.valueChangedTo).to.equal("true");

// Test for Unmanaged entity(Create)
const unmanagedAction = POST.bind(
{},
`/odata/v4/admin/Schools(ID=5ab2a87b-3a56-4d97-a697-7af72333c123,IsActiveEntity=false)/classes`,
{
ID: "9d703c23-54a8-4eff-81c1-cdec5c4267c5",
name: "Biology 101",
teacher: "Mr. Smith",
up__ID: "9d703c23-54a8-4eff-81c1-cdce6b0528c4"
}
);
await utils.apiAction("admin", "Schools", "5ab2a87b-3a56-4d97-a697-7af72333c123", "AdminService", unmanagedAction);
const schoolChanges = await adminService.run(
SELECT.from(ChangeView).where({
entity: "sap.capire.bookshop.Schools",
attribute: "classes",
})
);

expect(schoolChanges.length).to.equal(1);
const schoolChange = schoolChanges[0];
expect(schoolChange.entityKey).to.equal("5ab2a87b-3a56-4d97-a697-7af72333c123");
expect(schoolChange.attribute).to.equal("classes");
expect(schoolChange.modification).to.equal("Create");
expect(schoolChange.valueChangedFrom).to.equal("");
expect(schoolChange.valueChangedTo).to.equal("Biology 101, Mr. Smith");
});

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

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

// Test for Unmanaged entity(Create)
const unmanagedAction = POST.bind(
{},
`/odata/v4/admin/Schools(ID=5ab2a87b-3a56-4d97-a697-7af72333c123,IsActiveEntity=false)/classes`,
{
ID: "9d703c23-54a8-4eff-81c1-cdec5c4267c5",
name: "Biology 101",
teacher: "Mr. Smith",
up__ID: "9d703c23-54a8-4eff-81c1-cdce6b0528c4"
}
);
await utils.apiAction("admin", "Schools", "5ab2a87b-3a56-4d97-a697-7af72333c123", "AdminService", unmanagedAction);
const schoolChanges = await adminService.run(
SELECT.from(ChangeView).where({
entity: "sap.capire.bookshop.Schools",
attribute: "classes",
})
);

expect(schoolChanges.length).to.equal(1);
const schoolChange = schoolChanges[0];
expect(schoolChange.entityKey).to.equal("5ab2a87b-3a56-4d97-a697-7af72333c123");
expect(schoolChange.attribute).to.equal("classes");
expect(schoolChange.modification).to.equal("Create");
expect(schoolChange.valueChangedFrom).to.equal("");
expect(schoolChange.valueChangedTo).to.equal("Biology 101, Mr. Smith");

delete cds.services.AdminService.entities.Books.elements.price["@changelog"];
});

Expand Down Expand Up @@ -431,6 +485,24 @@ describe("change log integration test", () => {
expect(volumnTitleChange.entity).to.equal("Volumn");
expect(volumnTitleChange.valueChangedFrom).to.equal("Wuthering Heights I");
expect(volumnTitleChange.valueChangedTo).to.equal("");

// Test for Unmanaged entity(Delete)
const unmanagedAction = DELETE.bind({},`/odata/v4/admin/Schools_classes(up__ID=5ab2a87b-3a56-4d97-a697-7af72333c123,ID=9d703c23-54a8-4eff-81c1-cdec5a0422c3,IsActiveEntity=false)`);
await utils.apiAction("admin", "Schools", "5ab2a87b-3a56-4d97-a697-7af72333c123", "AdminService", unmanagedAction);
const schoolChanges = await adminService.run(
SELECT.from(ChangeView).where({
entity: "sap.capire.bookshop.Schools",
attribute: "classes",
})
);

expect(schoolChanges.length).to.equal(1);
const schoolChange = schoolChanges[0];
expect(schoolChange.entityKey).to.equal("5ab2a87b-3a56-4d97-a697-7af72333c123");
expect(schoolChange.attribute).to.equal("classes");
expect(schoolChange.modification).to.equal("Delete");
expect(schoolChange.valueChangedFrom).to.equal("Physics 500, Mrs. Johnson");
expect(schoolChange.valueChangedTo).to.equal("");
});

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