Skip to content

Commit

Permalink
@changelog.keys -> @changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
danjoa committed Oct 12, 2023
1 parent 92e496f commit 65d2a57
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 43 deletions.
2 changes: 1 addition & 1 deletion cds-plugin.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const cds = require('@sap/cds')

const isChangeTracked = (entity) => (
entity['@changelog'] || entity['@changelog.keys']
entity['@changelog']
|| entity.elements && Object.values(entity.elements).some(e => e['@changelog'])
)

Expand Down
2 changes: 1 addition & 1 deletion lib/entity-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const getCurObjFromReqData = function (reqData, nodePathVal, pathVal) {
async function getObjectId (entityName, fields, curObj) {
let all = [], { curObjFromReqData: req_data={}, curObjFromDbQuery: db_data={} } = curObj
let entity = cds.model.definitions[entityName]
if (!fields?.length) fields = entity["@changelog.keys"]?.map(k => k['='] || k) || []
if (!fields?.length) fields = entity["@changelog"]?.map?.(k => k['='] || k) || []
for (let field of fields) {
let path = field.split('.')
if (path.length > 1) {
Expand Down
4 changes: 2 additions & 2 deletions tests/bookshop/db/schema.cds
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ entity Authors : managed, cuid {
}

@title : '{i18n>volumns.objectTitle}'
@changelog.keys : [title]
@changelog : [title]
entity Volumns : managed, cuid {
@changelog
@title : '{i18n>volumns.title}'
Expand All @@ -80,7 +80,7 @@ entity Volumns : managed, cuid {
}

@title : '{i18n>bookStoreRegistry.objectTitle}'
@changelog.keys : [code]
@changelog : [code]
entity BookStoreRegistry : managed, cuid {
@title : '{i18n>bookStoreRegistry.code}'
code : String;
Expand Down
6 changes: 3 additions & 3 deletions tests/bookshop/srv/admin-service.cds
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ annotate AdminService.Authors with {
name @(Common.Label : '{i18n>serviceAuthors.name}');
};

annotate AdminService.BookStores with @changelog.keys : [name]{
annotate AdminService.BookStores with @changelog : [name]{
name @changelog;
location @changelog;
books @changelog : [books.title];
Expand All @@ -29,7 +29,7 @@ annotate AdminService.BookStores with @changelog.keys : [name]{
};


annotate AdminService.Books with @changelog.keys : [
annotate AdminService.Books with @changelog : [
title,
author.name.firstName,
author.name.lastName
Expand All @@ -47,7 +47,7 @@ annotate AdminService.Books with @changelog.keys : [
];
};

annotate AdminService.Authors with @changelog.keys : [
annotate AdminService.Authors with @changelog : [
name.firstName,
name.lastName
]{
Expand Down
24 changes: 12 additions & 12 deletions tests/integration/fiori-draft-disabled.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ describe("change log draft disabled test", () => {
});

it("4.1 Annotate multiple native and attributes comming from one or more associated table as the object ID (ERP4SMEPREPWORKAPPPLAT-913)", async () => {
cds.services.AdminService.entities.OrderItem["@changelog.keys"] = [
cds.services.AdminService.entities.OrderItem["@changelog"] = [
{ "=": "customer.city" },
{ "=": "order.status" },
{ "=": "price" },
Expand All @@ -194,11 +194,11 @@ describe("change log draft disabled test", () => {
const change = changes[0];
expect(change.objectID).to.equal("Ōsaka, Post, 5, 14");

delete cds.services.AdminService.entities.OrderItem["@changelog.keys"];
delete cds.services.AdminService.entities.OrderItem["@changelog"];
});

it("4.2 Annotate multiple native attributes as the object ID (ERP4SMEPREPWORKAPPPLAT-913)", async () => {
cds.services.AdminService.entities.Authors["@changelog.keys"] = [
cds.services.AdminService.entities.Authors["@changelog"] = [
{ "=": "placeOfBirth" },
{ "=": "name.firstName" },
{ "=": "name.lastName" },
Expand All @@ -216,14 +216,14 @@ describe("change log draft disabled test", () => {
const change = changes[0];
expect(change.objectID).to.equal("new placeOfBirth, Emily, Brontë, Haworth, Yorkshire, 1848-12-19, 1818-07-30");

cds.services.AdminService.entities.Authors["@changelog.keys"] = [
cds.services.AdminService.entities.Authors["@changelog"] = [
{ "=": "name.firstName" },
{ "=": "name.lastName" },
];
});

it("4.3 Annotate multiple attributes comming from one or more associated table as the object ID (ERP4SMEPREPWORKAPPPLAT-913)", async () => {
cds.services.AdminService.entities.OrderItem["@changelog.keys"] = [
cds.services.AdminService.entities.OrderItem["@changelog"] = [
{ "=": "customer.city" },
{ "=": "order.status" },
{ "=": "customer.country" },
Expand All @@ -238,7 +238,7 @@ describe("change log draft disabled test", () => {
const change = changes[0];
expect(change.objectID).to.equal("Ōsaka, Post, Japan, Honda");

delete cds.services.AdminService.entities.OrderItem["@changelog.keys"];
delete cds.services.AdminService.entities.OrderItem["@changelog"];
});

it("5.1 value data type records data type of native attributes of the entity or attributes from association table which are annotated as the displayed value(ERP4SMEPREPWORKAPPPLAT-873)", async () => {
Expand Down Expand Up @@ -282,7 +282,7 @@ describe("change log draft disabled test", () => {
});

it("7.2 Annotate fields from chained associated entities as objectID (ERP4SMEPREPWORKAPPPLAT-993)", async () => {
cds.services.AdminService.entities.OrderItem["@changelog.keys"] = [
cds.services.AdminService.entities.OrderItem["@changelog"] = [
{ "=": "order.report.comment" },
{ "=": "order.status" },
{ "=": "customer.name" },
Expand All @@ -296,7 +296,7 @@ describe("change log draft disabled test", () => {
const change = changes[0];
expect(change.objectID).to.equal("some comment, Post, Honda");

delete cds.services.AdminService.entities.OrderItem["@changelog.keys"];
delete cds.services.AdminService.entities.OrderItem["@changelog"];
});

it("8.2 Annotate fields from chained associated entities as displayed value (ERP4SMEPREPWORKAPPPLAT-1094)", async () => {
Expand Down Expand Up @@ -332,7 +332,7 @@ describe("change log draft disabled test", () => {
});

it("10.2 Composition of one update by odata request on draft disabled entity - should log changes for root entity (ERP4SMEPREPWORKAPPPLAT-2913 ERP4SMEPREPWORKAPPPLAT-3063)", async () => {
cds.services.AdminService.entities.Order["@changelog.keys"] = [{ "=": "status" }];
cds.services.AdminService.entities.Order["@changelog"] = [{ "=": "status" }];
await PATCH(`/admin/Order(ID=0a41a187-a2ff-4df6-bd12-fae8996e6e31)`, {
header: {
ID: "8567d0de-d44f-11ed-afa1-0242ac120002",
Expand All @@ -352,12 +352,12 @@ describe("change log draft disabled test", () => {
expect(headerChange.valueChangedTo).to.equal("Ordered");
expect(headerChange.parentKey).to.equal("0a41a187-a2ff-4df6-bd12-fae8996e6e31");
expect(headerChange.parentObjectID).to.equal("Post");
delete cds.services.AdminService.entities.Order["@changelog.keys"];
delete cds.services.AdminService.entities.Order["@changelog"];
});

it("10.3 Composition of one delete by odata request on draft disabled entity - should log changes for root entity (ERP4SMEPREPWORKAPPPLAT-2913 ERP4SMEPREPWORKAPPPLAT-3063)", async () => {
// Check if the object ID obtaining failed due to lacking parentKey would lead to dump
cds.services.AdminService.entities.Order["@changelog.keys"] = [{ "=": "status" }];
cds.services.AdminService.entities.Order["@changelog"] = [{ "=": "status" }];
await DELETE(`/admin/Order(ID=0a41a187-a2ff-4df6-bd12-fae8996e6e31)/header`);

const changes = await adminService.run(SELECT.from(ChangeView));
Expand All @@ -372,6 +372,6 @@ describe("change log draft disabled test", () => {
expect(headerChange.valueChangedTo).to.equal("");
expect(headerChange.parentKey).to.equal("0a41a187-a2ff-4df6-bd12-fae8996e6e31");
expect(headerChange.parentObjectID).to.equal("Post");
delete cds.services.AdminService.entities.Order["@changelog.keys"];
delete cds.services.AdminService.entities.Order["@changelog"];
});
});
44 changes: 22 additions & 22 deletions tests/integration/fiori-draft-enabled.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,10 @@ describe("change log integration test", () => {
});

it("2.4 Child entity update without objectID annotation - should log object type for object ID (ERP4SMEPREPWORKAPPPLAT-32 ERP4SMEPREPWORKAPPPLAT-613 ERP4SMEPREPWORKAPPPLAT-538)", async () => {
delete cds.services.AdminService.entities.Books["@changelog.keys"];
delete cds.services.AdminService.entities.BookStores["@changelog.keys"];
delete cds.db.entities.Books["@changelog.keys"];
delete cds.db.entities.BookStores["@changelog.keys"];
delete cds.services.AdminService.entities.Books["@changelog"];
delete cds.services.AdminService.entities.BookStores["@changelog"];
delete cds.db.entities.Books["@changelog"];
delete cds.db.entities.BookStores["@changelog"];

const action = PATCH.bind({}, `/admin/Books(ID=9d703c23-54a8-4eff-81c1-cdce6b8376b1,IsActiveEntity=false)`, {
title: "new title",
Expand All @@ -271,12 +271,12 @@ describe("change log integration test", () => {
expect(change.objectID).to.equal("Book");
expect(change.parentObjectID).to.equal("Book Store");

cds.services.AdminService.entities.Books["@changelog.keys"] = [
cds.services.AdminService.entities.Books["@changelog"] = [
{ "=": "title" },
{ "=": "author.name.firstName" },
{ "=": "author.name.lastName" },
];
cds.services.AdminService.entities.BookStores["@changelog.keys"] = [
cds.services.AdminService.entities.BookStores["@changelog"] = [
{
"=": "name",
},
Expand All @@ -286,7 +286,7 @@ describe("change log integration test", () => {
it("4.1 Annotate multiple native and attributes comming from one or more associated table as the object ID (ERP4SMEPREPWORKAPPPLAT-913)", async () => {
// After appending object id as below, the object ID sequence should be:
// title, author.name.firstName, author.name.lastName, stock, bookStore.name, bookStore.location
cds.services.AdminService.entities.Books["@changelog.keys"].push(
cds.services.AdminService.entities.Books["@changelog"].push(
{ "=": "stock" },
{ "=": "bookStore.name" },
{ "=": "bookStore.location" }
Expand Down Expand Up @@ -330,7 +330,7 @@ describe("change log integration test", () => {

// After adjusting object id as below, the object ID sequence should be:
// title, bookStore.name, bookStore.location, stock, author.name.firstName, author.name.lastName
cds.services.AdminService.entities.Books["@changelog.keys"] = [
cds.services.AdminService.entities.Books["@changelog"] = [
{ "=": "title" },
{ "=": "bookStore.name" },
{ "=": "bookStore.location" },
Expand Down Expand Up @@ -358,7 +358,7 @@ describe("change log integration test", () => {

// After adjusting object id as below, the object ID sequence should be:
// bookStore.name, title, bookStore.location, author.name.firstName, stock, author.name.lastName
cds.services.AdminService.entities.Books["@changelog.keys"] = [
cds.services.AdminService.entities.Books["@changelog"] = [
{ "=": "bookStore.name" },
{ "=": "title" },
{ "=": "bookStore.location" },
Expand All @@ -383,15 +383,15 @@ describe("change log integration test", () => {
expect(deleteTitleChange.objectID).to.equal("Shakespeare and Company, test title 1, Paris, Emily, 1, Brontë");

// Recover the object ID of entity Books as defined in admin-service
cds.services.AdminService.entities.Books["@changelog.keys"] = [
cds.services.AdminService.entities.Books["@changelog"] = [
{ "=": "title" },
{ "=": "author.name.firstName" },
{ "=": "author.name.lastName" },
];
});

it("4.2 Annotate multiple native attributes as the object ID (ERP4SMEPREPWORKAPPPLAT-913)", async () => {
cds.services.AdminService.entities.Books["@changelog.keys"] = [
cds.services.AdminService.entities.Books["@changelog"] = [
{ "=": "price" },
{ "=": "title" },
{ "=": "stock" },
Expand All @@ -415,15 +415,15 @@ describe("change log integration test", () => {
const titleChange = titleChanges[0];
expect(titleChange.objectID).to.equal("11.11, new title, 12");

cds.services.AdminService.entities.Books["@changelog.keys"] = [
cds.services.AdminService.entities.Books["@changelog"] = [
{ "=": "title" },
{ "=": "author.name.firstName" },
{ "=": "author.name.lastName" },
];
});

it("4.3 Annotate multiple attributes comming from one or more associated table as the object ID (ERP4SMEPREPWORKAPPPLAT-913)", async () => {
cds.services.AdminService.entities.Books["@changelog.keys"] = [
cds.services.AdminService.entities.Books["@changelog"] = [
{ "=": "bookStore.location" },
{ "=": "author.name.lastName" },
{ "=": "author.name.firstName" },
Expand All @@ -449,7 +449,7 @@ describe("change log integration test", () => {
const titleChange = titleChanges[0];
expect(titleChange.objectID).to.equal("Paris, Brontë, Charlotte, Shakespeare and Company, 16");

cds.services.AdminService.entities.Books["@changelog.keys"] = [
cds.services.AdminService.entities.Books["@changelog"] = [
{ "=": "title" },
{ "=": "author.name.firstName" },
{ "=": "author.name.lastName" },
Expand Down Expand Up @@ -694,7 +694,7 @@ describe("change log integration test", () => {
});

it("6.3 Attributes from the code list could be annotated as object ID (ERP4SMEPREPWORKAPPPLAT-1055)", async () => {
cds.services.AdminService.entities.BookStores["@changelog.keys"] = [
cds.services.AdminService.entities.BookStores["@changelog"] = [
{ "=": "name" },
{ "=": "lifecycleStatus.name" },
];
Expand Down Expand Up @@ -726,7 +726,7 @@ describe("change log integration test", () => {
expect(lifecycleStatusChange.modification).to.equal("Create");
expect(lifecycleStatusChange.objectID).to.equal("test name, In Preparation");

cds.services.AdminService.entities.BookStores["@changelog.keys"] = [
cds.services.AdminService.entities.BookStores["@changelog"] = [
{ "=": "lifecycleStatus.name" },
{ "=": "name" },
];
Expand Down Expand Up @@ -756,11 +756,11 @@ describe("change log integration test", () => {
expect(lifecycleStatusUpdateChange.modification).to.equal("Update");
expect(lifecycleStatusUpdateChange.objectID).to.equal("Closed, new test name");

cds.services.AdminService.entities.BookStores["@changelog.keys"] = [{ "=": "name" }];
cds.services.AdminService.entities.BookStores["@changelog"] = [{ "=": "name" }];
});

it("7.1 Annotate fields from chained associated entities as objectID (ERP4SMEPREPWORKAPPPLAT-993)", async () => {
cds.services.AdminService.entities.Books["@changelog.keys"] = [
cds.services.AdminService.entities.Books["@changelog"] = [
{ "=": "bookStore.lifecycleStatus.name" },
{ "=": "bookStore.location" },
{ "=": "bookStore.city.name" },
Expand All @@ -783,7 +783,7 @@ describe("change log integration test", () => {
const titleChange = titleChanges[0];
expect(titleChange.objectID).to.equal("In Preparation, Paris, Paris, FR");

cds.services.AdminService.entities.Books["@changelog.keys"] = [
cds.services.AdminService.entities.Books["@changelog"] = [
{ "=": "title" },
{ "=": "bookStore.lifecycleStatus.name" },
{ "=": "bookStore.city.country.countryName.name" },
Expand Down Expand Up @@ -812,7 +812,7 @@ describe("change log integration test", () => {
const deleteTitleChange = deleteTitleChanges[0];
expect(deleteTitleChange.objectID).to.equal("new title, In Preparation, France");

cds.services.AdminService.entities.Books["@changelog.keys"] = [
cds.services.AdminService.entities.Books["@changelog"] = [
{ "=": "title" },
{ "=": "author.name.firstName" },
{ "=": "author.name.lastName" },
Expand Down Expand Up @@ -877,7 +877,7 @@ describe("change log integration test", () => {
});

it("9.1 Localization should handle the cases that reading the change view without required parameters obtained (ERP4SMEPREPWORKAPPPLAT-1414)", async () => {
delete cds.services.AdminService.entities.BookStores["@changelog.keys"];
delete cds.services.AdminService.entities.BookStores["@changelog"];
const action = POST.bind(
{},
`/admin/BookStores(ID=64625905-c234-4d0d-9bc1-283ee8946770,IsActiveEntity=false)/books`,
Expand Down Expand Up @@ -923,7 +923,7 @@ describe("change log integration test", () => {
const bookChangeObjectId = bookElementChanges[3];
expect(bookChangeObjectId.objectID).to.equal("");

cds.services.AdminService.entities.BookStores["@changelog.keys"] = [
cds.services.AdminService.entities.BookStores["@changelog"] = [
{
"=": "name",
},
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/service-api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe("change log integration test", () => {
});

it("10.8 Composition of one node deep updated by QL API - should log changes on root entity (ERP4SMEPREPWORKAPPPLAT-2913 ERP4SMEPREPWORKAPPPLAT-3063)", async () => {
cds.services.AdminService.entities.BookStoreRegistry["@changelog.keys"] = [
cds.services.AdminService.entities.BookStoreRegistry["@changelog"] = [
{ "=": "code" },
{ "=": "validOn" },
];
Expand All @@ -127,7 +127,7 @@ describe("change log integration test", () => {
expect(changes[0].valueChangedTo).to.equal("2022-01-01");
expect(changes[0].parentKey).to.equal("64625905-c234-4d0d-9bc1-283ee8946770");
expect(changes[0].parentObjectID).to.equal("Shakespeare and Company");
cds.services.AdminService.entities.BookStoreRegistry["@changelog.keys"] = [{ "=": "code" }];
cds.services.AdminService.entities.BookStoreRegistry["@changelog"] = [{ "=": "code" }];
});

it("10.9 Child entity deep delete by QL API - should log changes on root entity (ERP4SMEPREPWORKAPPPLAT-3063)", async () => {
Expand Down

0 comments on commit 65d2a57

Please sign in to comment.