diff --git a/lib/sdm.js b/lib/sdm.js index 10dffde..e0b8d65 100644 --- a/lib/sdm.js +++ b/lib/sdm.js @@ -175,7 +175,7 @@ let subdomain = cds.context?.user?.authInfo?.token?.payload?.ext_attr?.zdn; for (const [elementName, element] of Object.entries(entityDef.elements)) { if (element.type === 'cds.Composition' && element.target) { const targetDef = cds.model.definitions[element.target]; - if (targetDef && targetDef.includes && targetDef.includes.includes('sap.attachments.Attachments')) { + if (targetDef && targetDef.includes && (targetDef.includes.includes('sap.attachments.Attachments') || targetDef.includes.includes('Attachments'))) { attachmentCompositions.push(elementName); } } diff --git a/test/lib/sdm.test.js b/test/lib/sdm.test.js index 0a38e2f..170238a 100644 --- a/test/lib/sdm.test.js +++ b/test/lib/sdm.test.js @@ -5102,6 +5102,57 @@ describe("SDMAttachmentsService", () => { expect(result).toEqual([compositionName]); }); }); + + it('should recognize Attachments without namespace prefix', () => { + const targetEntity = { name: 'Test.EntityWithShortAttachments' }; + + cds.model.definitions['Test.EntityWithShortAttachments'] = { + elements: { + attachments: { + type: 'cds.Composition', + target: 'Test.ShortAttachments' + } + } + }; + + cds.model.definitions['Test.ShortAttachments'] = { + includes: ['Attachments'] // Without 'sap.attachments.' prefix + }; + + const result = service.getAttachmentCompositions(targetEntity); + + expect(result).toEqual(['attachments']); + }); + + it('should recognize both full and short Attachments includes', () => { + const targetEntity = { name: 'Test.EntityWithMixedIncludes' }; + + cds.model.definitions['Test.EntityWithMixedIncludes'] = { + elements: { + fullAttachments: { + type: 'cds.Composition', + target: 'Test.FullAttachments' + }, + shortAttachments: { + type: 'cds.Composition', + target: 'Test.ShortAttachments' + } + } + }; + + cds.model.definitions['Test.FullAttachments'] = { + includes: ['sap.attachments.Attachments'] + }; + cds.model.definitions['Test.ShortAttachments'] = { + includes: ['Attachments'] + }; + + const result = service.getAttachmentCompositions(targetEntity); + + expect(result).toContain('fullAttachments'); + expect(result).toContain('shortAttachments'); + expect(result.length).toBe(2); + }); }); describe('replacePropertiesInAttachment', () => {