From 32af0d4b0f49ab03fb7ad00b06b1f2b8a49f6544 Mon Sep 17 00:00:00 2001 From: deepiksSingh2711 Date: Tue, 30 Jun 2026 07:14:10 +0530 Subject: [PATCH] Integration tests for Map Note field to CMIS description --- package.json | 5 + .../attachments-sdm-multifacet.test.js | 227 +++++++++++++++++- test/integration/attachments-sdm.test.js | 214 +++++++++++++++++ 3 files changed, 443 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index f7608866..f08c589c 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,11 @@ "lint": "npx eslint --fix . --no-cache" }, "cds": { + "server": { + "body_parser": { + "limit": "2gb" + } + }, "requires": { "sdm": { "vcap": { diff --git a/test/integration/attachments-sdm-multifacet.test.js b/test/integration/attachments-sdm-multifacet.test.js index 466447e2..0aa79ce8 100644 --- a/test/integration/attachments-sdm-multifacet.test.js +++ b/test/integration/attachments-sdm-multifacet.test.js @@ -1891,9 +1891,11 @@ const config = { } expect(response.data.createdBy).toBeTruthy(); expect(response.data.modifiedBy).toBeTruthy(); - // When using named user token, createdBy should match the authenticated username - if (credentials.username) { + + if (tokenFlow === 'namedUser' && credentials.username) { expect(response.data.createdBy).toBe(credentials.username); + } else if (tokenFlow === 'technicalUser' && credentials.username) { + expect(response.data.createdBy).not.toBe(credentials.username); } // Cleanup @@ -2101,7 +2103,12 @@ describe('Attachments Integration Tests --CMIS METADATA', () => { const { getCmisProperty } = require('./utills/cmis-document-helper'); const createdBy = await getCmisProperty(metadataEntityID, "metadata-test.pdf", "cmis:createdBy"); expect(createdBy).toBeTruthy(); - expect(createdBy).toBe(credentials.username); + + if (tokenFlow === 'namedUser') { + expect(createdBy).toBe(credentials.username); + } else if (tokenFlow === 'technicalUser') { + expect(createdBy).not.toBe(credentials.username); + } console.log(`SDM createdBy field verified: ${createdBy}`); // Cleanup @@ -2110,6 +2117,220 @@ describe('Attachments Integration Tests --CMIS METADATA', () => { console.warn("Cleanup failed:", response.message); } }); + + itForAllFacets('should map attachment note to cmis:description on create', async () => { + const noteText = `note-create-${Date.now()}`; + let response = await api.createEntityDraft(appUrl, serviceName, entityName); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + const noteCreateEntityID = response.incidentID; + + const file = { + filename: "note-create-file.pdf", + filepath: "./test/integration/sample.pdf" + }; + + const postData = { + up__ID: noteCreateEntityID, + mimeType: "application/pdf", + createdAt: new Date().toISOString(), + createdBy: "test@test.com", + modifiedBy: "test@test.com", + note: noteText + }; + + response = await api.createAttachment(appUrl, serviceName, entityName, noteCreateEntityID, postData, file); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + + response = await api.saveEntityDraft(appUrl, serviceName, entityName, srvpath, noteCreateEntityID); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + + const { getCmisProperty } = require('./utills/cmis-document-helper'); + const cmisDescription = await getCmisProperty(noteCreateEntityID, "note-create-file.pdf", "cmis:description"); + expect(cmisDescription).toBe(noteText); + + response = await api.deleteEntity(appUrl, serviceName, entityName, noteCreateEntityID); + if (response.status !== "OK") { + console.warn("Cleanup failed for noteCreateEntityID:", response.message); + } + }); + + itForAllFacets('should map updated attachment note to cmis:description on update', async () => { + const initialNote = `note-initial-${Date.now()}`; + const updatedNote = `note-updated-${Date.now()}`; + + let response = await api.createEntityDraft(appUrl, serviceName, entityName); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + const noteUpdateEntityID = response.incidentID; + + const file = { + filename: "note-update-file.pdf", + filepath: "./test/integration/sample.pdf" + }; + + const postData = { + up__ID: noteUpdateEntityID, + mimeType: "application/pdf", + createdAt: new Date().toISOString(), + createdBy: "test@test.com", + modifiedBy: "test@test.com", + note: initialNote + }; + + response = await api.createAttachment(appUrl, serviceName, entityName, noteUpdateEntityID, postData, file); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + const noteUpdateAttachmentID = response.ID; + + response = await api.saveEntityDraft(appUrl, serviceName, entityName, srvpath, noteUpdateEntityID); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + + response = await api.editEntity(appUrl, serviceName, entityName, noteUpdateEntityID, srvpath); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + + response = await api.updateAttachment(appUrl, serviceName, entityName, noteUpdateEntityID, { note: updatedNote }, noteUpdateAttachmentID); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + + response = await api.saveEntityDraft(appUrl, serviceName, entityName, srvpath, noteUpdateEntityID); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + + const { getCmisProperty } = require('./utills/cmis-document-helper'); + const cmisDescription = await getCmisProperty(noteUpdateEntityID, "note-update-file.pdf", "cmis:description"); + expect(cmisDescription).toBe(updatedNote); + + response = await api.deleteEntity(appUrl, serviceName, entityName, noteUpdateEntityID); + if (response.status !== "OK") { + console.warn("Cleanup failed for noteUpdateEntityID:", response.message); + } + }); + + itForAllFacets('should map link note to cmis:description on create', async () => { + const noteText = `link-note-create-${Date.now()}`; + const linkName = `note-link-create-${Date.now()}`; + const linkUrl = 'https://example.com/create-note-link'; + + let response = await api.createEntityDraft(appUrl, serviceName, entityName); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + const linkNoteCreateEntityID = response.incidentID; + + response = await api.createLink(appUrl, serviceName, entityName, linkNoteCreateEntityID, srvpath, linkName, linkUrl); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + + response = await api.getAttachmentsList(appUrl, serviceName, entityName, linkNoteCreateEntityID); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + + const linkAttachment = response.attachments.find(att => + att.filename === linkName && att.linkUrl === linkUrl + ); + if (!linkAttachment) { + throw new Error("Error : Created link not found in attachments list"); + } + + response = await api.updateAttachment(appUrl, serviceName, entityName, linkNoteCreateEntityID, { note: noteText }, linkAttachment.ID); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + + response = await api.saveEntityDraft(appUrl, serviceName, entityName, srvpath, linkNoteCreateEntityID); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + + const { getCmisProperty } = require('./utills/cmis-document-helper'); + const cmisDescription = await getCmisProperty(linkNoteCreateEntityID, linkName, "cmis:description"); + expect(cmisDescription).toBe(noteText); + + response = await api.deleteEntity(appUrl, serviceName, entityName, linkNoteCreateEntityID); + if (response.status !== "OK") { + console.warn("Cleanup failed for linkNoteCreateEntityID:", response.message); + } + }); + + itForAllFacets('should map updated link note to cmis:description on update', async () => { + const initialNote = `link-note-initial-${Date.now()}`; + const updatedNote = `link-note-updated-${Date.now()}`; + const linkName = `note-link-update-${Date.now()}`; + const linkUrl = 'https://example.com/update-note-link'; + + let response = await api.createEntityDraft(appUrl, serviceName, entityName); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + const linkNoteUpdateEntityID = response.incidentID; + + response = await api.createLink(appUrl, serviceName, entityName, linkNoteUpdateEntityID, srvpath, linkName, linkUrl); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + + response = await api.getAttachmentsList(appUrl, serviceName, entityName, linkNoteUpdateEntityID); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + + const linkAttachment = response.attachments.find(att => + att.filename === linkName && att.linkUrl === linkUrl + ); + if (!linkAttachment) { + throw new Error("Error : Created link not found in attachments list"); + } + + response = await api.updateAttachment(appUrl, serviceName, entityName, linkNoteUpdateEntityID, { note: initialNote }, linkAttachment.ID); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + + response = await api.saveEntityDraft(appUrl, serviceName, entityName, srvpath, linkNoteUpdateEntityID); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + + response = await api.editEntity(appUrl, serviceName, entityName, linkNoteUpdateEntityID, srvpath); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + + response = await api.updateAttachment(appUrl, serviceName, entityName, linkNoteUpdateEntityID, { note: updatedNote }, linkAttachment.ID); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + + response = await api.saveEntityDraft(appUrl, serviceName, entityName, srvpath, linkNoteUpdateEntityID); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + + const { getCmisProperty } = require('./utills/cmis-document-helper'); + const cmisDescription = await getCmisProperty(linkNoteUpdateEntityID, linkName, "cmis:description"); + expect(cmisDescription).toBe(updatedNote); + + response = await api.deleteEntity(appUrl, serviceName, entityName, linkNoteUpdateEntityID); + if (response.status !== "OK") { + console.warn("Cleanup failed for linkNoteUpdateEntityID:", response.message); + } + }); }); describe('Attachments Integration Tests --DELETE', () => { diff --git a/test/integration/attachments-sdm.test.js b/test/integration/attachments-sdm.test.js index 5c1e23f6..eef6e4a8 100644 --- a/test/integration/attachments-sdm.test.js +++ b/test/integration/attachments-sdm.test.js @@ -2051,6 +2051,220 @@ describe.only('Attachments Integration Tests --CMIS METADATA', () => { console.warn("Cleanup failed:", response.message); } }); + + it('should map attachment note to cmis:description on create', async () => { + const noteText = `note-create-${Date.now()}`; + let response = await api.createEntityDraft(appUrl, serviceName, entityName); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + const noteCreateEntityID = response.incidentID; + + const file = { + filename: "note-create-file.pdf", + filepath: "./test/integration/sample.pdf" + }; + + const postData = { + up__ID: noteCreateEntityID, + mimeType: "application/pdf", + createdAt: new Date().toISOString(), + createdBy: "test@test.com", + modifiedBy: "test@test.com", + note: noteText + }; + + response = await api.createAttachment(appUrl, serviceName, entityName, noteCreateEntityID, postData, file); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + + response = await api.saveEntityDraft(appUrl, serviceName, entityName, srvpath, noteCreateEntityID); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + + const { getCmisProperty } = require('./utills/cmis-document-helper'); + const cmisDescription = await getCmisProperty(noteCreateEntityID, "note-create-file.pdf", "cmis:description"); + expect(cmisDescription).toBe(noteText); + + response = await api.deleteEntity(appUrl, serviceName, entityName, noteCreateEntityID); + if (response.status !== "OK") { + console.warn("Cleanup failed for noteCreateEntityID:", response.message); + } + }); + + it('should map updated attachment note to cmis:description on update', async () => { + const initialNote = `note-initial-${Date.now()}`; + const updatedNote = `note-updated-${Date.now()}`; + + let response = await api.createEntityDraft(appUrl, serviceName, entityName); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + const noteUpdateEntityID = response.incidentID; + + const file = { + filename: "note-update-file.pdf", + filepath: "./test/integration/sample.pdf" + }; + + const postData = { + up__ID: noteUpdateEntityID, + mimeType: "application/pdf", + createdAt: new Date().toISOString(), + createdBy: "test@test.com", + modifiedBy: "test@test.com", + note: initialNote + }; + + response = await api.createAttachment(appUrl, serviceName, entityName, noteUpdateEntityID, postData, file); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + const noteUpdateAttachmentID = response.ID; + + response = await api.saveEntityDraft(appUrl, serviceName, entityName, srvpath, noteUpdateEntityID); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + + response = await api.editEntity(appUrl, serviceName, entityName, noteUpdateEntityID, srvpath); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + + response = await api.updateAttachment(appUrl, serviceName, entityName, noteUpdateEntityID, { note: updatedNote }, noteUpdateAttachmentID); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + + response = await api.saveEntityDraft(appUrl, serviceName, entityName, srvpath, noteUpdateEntityID); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + + const { getCmisProperty } = require('./utills/cmis-document-helper'); + const cmisDescription = await getCmisProperty(noteUpdateEntityID, "note-update-file.pdf", "cmis:description"); + expect(cmisDescription).toBe(updatedNote); + + response = await api.deleteEntity(appUrl, serviceName, entityName, noteUpdateEntityID); + if (response.status !== "OK") { + console.warn("Cleanup failed for noteUpdateEntityID:", response.message); + } + }); + + it('should map link note to cmis:description on create', async () => { + const noteText = `link-note-create-${Date.now()}`; + const linkName = `note-link-create-${Date.now()}`; + const linkUrl = 'https://example.com/create-note-link'; + + let response = await api.createEntityDraft(appUrl, serviceName, entityName); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + const linkNoteCreateEntityID = response.incidentID; + + response = await api.createLink(appUrl, serviceName, entityName, linkNoteCreateEntityID, srvpath, linkName, linkUrl); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + + response = await api.getAttachmentsList(appUrl, serviceName, entityName, linkNoteCreateEntityID); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + + const linkAttachment = response.attachments.find(att => + att.filename === linkName && att.linkUrl === linkUrl + ); + if (!linkAttachment) { + throw new Error("Error : Created link not found in attachments list"); + } + + response = await api.updateAttachment(appUrl, serviceName, entityName, linkNoteCreateEntityID, { note: noteText }, linkAttachment.ID); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + + response = await api.saveEntityDraft(appUrl, serviceName, entityName, srvpath, linkNoteCreateEntityID); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + + const { getCmisProperty } = require('./utills/cmis-document-helper'); + const cmisDescription = await getCmisProperty(linkNoteCreateEntityID, linkName, "cmis:description"); + expect(cmisDescription).toBe(noteText); + + response = await api.deleteEntity(appUrl, serviceName, entityName, linkNoteCreateEntityID); + if (response.status !== "OK") { + console.warn("Cleanup failed for linkNoteCreateEntityID:", response.message); + } + }); + + it('should map updated link note to cmis:description on update', async () => { + const initialNote = `link-note-initial-${Date.now()}`; + const updatedNote = `link-note-updated-${Date.now()}`; + const linkName = `note-link-update-${Date.now()}`; + const linkUrl = 'https://example.com/update-note-link'; + + let response = await api.createEntityDraft(appUrl, serviceName, entityName); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + const linkNoteUpdateEntityID = response.incidentID; + + response = await api.createLink(appUrl, serviceName, entityName, linkNoteUpdateEntityID, srvpath, linkName, linkUrl); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + + response = await api.getAttachmentsList(appUrl, serviceName, entityName, linkNoteUpdateEntityID); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + + const linkAttachment = response.attachments.find(att => + att.filename === linkName && att.linkUrl === linkUrl + ); + if (!linkAttachment) { + throw new Error("Error : Created link not found in attachments list"); + } + + response = await api.updateAttachment(appUrl, serviceName, entityName, linkNoteUpdateEntityID, { note: initialNote }, linkAttachment.ID); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + + response = await api.saveEntityDraft(appUrl, serviceName, entityName, srvpath, linkNoteUpdateEntityID); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + + response = await api.editEntity(appUrl, serviceName, entityName, linkNoteUpdateEntityID, srvpath); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + + response = await api.updateAttachment(appUrl, serviceName, entityName, linkNoteUpdateEntityID, { note: updatedNote }, linkAttachment.ID); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + + response = await api.saveEntityDraft(appUrl, serviceName, entityName, srvpath, linkNoteUpdateEntityID); + if (response.status !== "OK") { + throw new Error("Error : " + response.message); + } + + const { getCmisProperty } = require('./utills/cmis-document-helper'); + const cmisDescription = await getCmisProperty(linkNoteUpdateEntityID, linkName, "cmis:description"); + expect(cmisDescription).toBe(updatedNote); + + response = await api.deleteEntity(appUrl, serviceName, entityName, linkNoteUpdateEntityID); + if (response.status !== "OK") { + console.warn("Cleanup failed for linkNoteUpdateEntityID:", response.message); + } + }); }); describe.only('Attachments Integration Tests --DELETE', () => {