Skip to content

Commit

Permalink
Add extra test
Browse files Browse the repository at this point in the history
  • Loading branch information
mnkiefer committed Nov 3, 2023
1 parent 4c1142b commit c9c53a6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/entity-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ async function getObjectId (entityName, fields, curObj) {
if (IDval) try {
// REVISIT: This always reads all elements -> should read required ones only!
let ID = assoc.keys?.[0]?.ref[0] || 'ID'
// When parent/child nodes are created simultaneously, data is taken from draft table
_db_data = await SELECT.one.from(assoc._target).where({[ID]: IDval}) ||
// When parent/child nodes are created simulateously, data is taken from draft table
await SELECT.one.from(`${assoc._target}.drafts`).where({[ID]: IDval}) || {}
} catch (e) {
LOG.error("Failed to generate object Id for an association entity.", e)
Expand Down
37 changes: 37 additions & 0 deletions tests/integration/fiori-draft-enabled.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,43 @@ describe("change log integration test", () => {
const deleteTitleChange = deleteTitleChanges[0];
expect(deleteTitleChange.objectID).to.equal("new title, In Preparation, France");

// Check object ID "bookStore.city.country.countryName.code" when creating BookStores/Books
// (parent/child) at the same time.
cds.services.AdminService.entities.Books["@changelog"] = [
{ "=": "bookStore.city.country.countryName.code" },
];

const createBooksAndBookStoresAction = POST.bind({}, `/odata/v4/admin/BookStores`, {
ID: "48268451-8552-42a6-a3d7-67564be86634",
city_ID: "60b4c55d-ec87-4edc-84cb-2e4ecd60de48",
books: [
{
ID: "12ed5dd8-d45b-11ed-afa1-1942bd119007",
title: "New title",
},
],
});

await utils.apiAction(
"admin",
"BookStores",
"48268451-8552-42a6-a3d7-67564be86634",
"AdminService",
createBooksAndBookStoresAction,
true,
);

const createBooksAndBookStoresChanges = await adminService.run(
SELECT.from(ChangeView).where({
entity: "sap.capire.bookshop.Books",
attribute: "title",
modification: "create",
}),
);
expect(createBooksAndBookStoresChanges.length).to.equal(1);
const createBooksAndBookStoresChange = createBooksAndBookStoresChanges[0];
expect(createBooksAndBookStoresChange.objectID).to.equal("USA");

cds.services.AdminService.entities.Books["@changelog"] = [
{ "=": "title" },
{ "=": "author.name.firstName" },
Expand Down

0 comments on commit c9c53a6

Please sign in to comment.