From ea597e5a40c82f8a021dbaf10830774fb9eaeabe Mon Sep 17 00:00:00 2001 From: Shazron Abdullah <36107+shazron@users.noreply.github.com> Date: Tue, 17 Dec 2024 19:41:26 +0800 Subject: [PATCH] fix: processing and assigning an action's annotations when there are none (#198) --- src/utils.js | 4 +++- test/utils.test.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/utils.js b/src/utils.js index c45305f..1b96256 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1102,7 +1102,9 @@ function rewriteActionsWithAdobeAuthAnnotation (packages, deploymentPackages) { if (newPackages[key].actions) { Object.keys(newPackages[key].actions).forEach((actionName) => { const thisAction = newPackages[key].actions[actionName] - Object.assign(thisAction.annotations, processAnnotationsForWebAction(thisAction)) + if (thisAction.annotations) { + Object.assign(thisAction.annotations, processAnnotationsForWebAction(thisAction)) + } const isWeb = thisAction.annotations?.[ANNOTATION_WEB_EXPORT] const isRaw = thisAction.annotations?.[ANNOTATION_RAW_HTTP] diff --git a/test/utils.test.js b/test/utils.test.js index 492be5c..cbd0ed5 100644 --- a/test/utils.test.js +++ b/test/utils.test.js @@ -1118,6 +1118,36 @@ describe('processPackage', () => { spy.mockRestore() }) + test('1 action with no annotations', () => { + const spy = jest.spyOn(fs, 'readFileSync') + const fakeCode = 'fake action code' + spy.mockImplementation(() => fakeCode) + const deploymentPackages = { pkg1: { actions: { theaction: { inputs: { a: 34 } } } } } + + const basicPackageNoAnnotations = structuredClone(basicPackage) + delete basicPackageNoAnnotations.pkg1.actions.theaction.annotations + + const res = utils.processPackage(basicPackageNoAnnotations, deploymentPackages, {}, {}, false, { apihost: 'https://adobeioruntime.net' }) + expect(res).toEqual({ + actions: [ + { + name: 'pkg1/theaction', + action: fakeCode, + params: { a: 34 }, + annotations: { + 'web-export': true, + 'raw-http': false + } + } + ], + apis: [], + pkgAndDeps: [{ name: 'pkg1' }], + rules: [], + triggers: [] + }) + spy.mockRestore() + }) + test('action using the annotation + rewrite deployment package => action has empty imputs', () => { const spy = jest.spyOn(fs, 'readFileSync') const fakeCode = 'fake action code'