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

For DateTime and Timestamp, support for input via Date objects in JavaScript. #132

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
2 changes: 1 addition & 1 deletion lib/change-log.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ const _formatCompositionContext = async function (changes, reqData) {
const childNodeChanges = []

for (const change of changes) {
if (typeof change.valueChangedTo === "object") {
if (typeof change.valueChangedTo === "object" && change.valueChangedTo instanceof Date !== true) {
if (!Array.isArray(change.valueChangedTo)) {
change.valueChangedTo = [change.valueChangedTo]
}
Expand Down
2 changes: 2 additions & 0 deletions tests/bookshop/db/schema.cds
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ namespace sap.capire.bookshop;
@title: '{i18n>RootEntity.objectTitle}'
entity RootEntity @(cds.autoexpose) : managed, cuid {
name : String;
dateTime : DateTime;
timestamp : Timestamp;
lifecycleStatus : LifecycleStatusCode;
child : Composition of many Level1Entity
on child.parent = $self;
Expand Down
34 changes: 33 additions & 1 deletion tests/integration/service-api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,39 @@ describe("change log integration test", () => {

delete cds.services.AdminService.entities.Order.elements.netAmount["@changelog"];
delete cds.services.AdminService.entities.Order.elements.isUsed["@changelog"];
});
});

it("1.9 For DateTime and Timestamp, support for input via Date objects.", async () => {
cds.env.requires["change-tracking"].preserveDeletes = true;
cds.services.AdminService.entities.RootEntity.elements.dateTime["@changelog"] = true;
cds.services.AdminService.entities.RootEntity.elements.timestamp["@changelog"] = true;
const rootEntityData = [
{
ID: "64625905-c234-4d0d-9bc1-283ee8940717",
dateTime: new Date("2024-10-16T08:53:48Z"),
timestamp: new Date("2024-10-23T08:53:54.000Z")
}
]
await INSERT.into(adminService.entities.RootEntity).entries(rootEntityData);
let changes = await adminService.run(SELECT.from(ChangeView).where({
entity: "sap.capire.bookshop.RootEntity",
attribute: "dateTime",
}));
expect(changes.length).to.equal(1);
let change = changes[0];
expect(change.entityKey).to.equal("64625905-c234-4d0d-9bc1-283ee8940717");
expect(change.attribute).to.equal("dateTime");
expect(change.modification).to.equal("Create");
expect(change.valueChangedFrom).to.equal("");
/**
* REVISIT: Currently, when using '@cap-js/sqlite' or '@cap-js/hana' and inputting values of type Date in javascript,
* there is an issue with inconsistent formats before and after, which requires a fix from cds-dbs (Issue-873).
*/
expect(change.valueChangedTo).to.equal(`${new Date("2024-10-16T08:53:48Z")}`);
delete cds.services.AdminService.entities.RootEntity.elements.dateTime["@changelog"];
delete cds.services.AdminService.entities.RootEntity.elements.timestamp["@changelog"];
cds.env.requires["change-tracking"].preserveDeletes = false;
});

it("2.5 Root entity deep creation by service API - should log changes on root entity (ERP4SMEPREPWORKAPPPLAT-32 ERP4SMEPREPWORKAPPPLAT-613)", async () => {
const bookStoreData = {
Expand Down
Loading