From 8ec630ce23ea4d4041e0f78ef1dc022b5df49d8c Mon Sep 17 00:00:00 2001 From: Tiffany K Date: Sun, 29 Sep 2024 22:00:08 -0700 Subject: [PATCH] fix: Store default parameters in event meta (#630) --- lib/eventFactory.js | 4 +-- test/lib/eventFactory.test.js | 66 ++++++++++++++++++++++------------- 2 files changed, 44 insertions(+), 26 deletions(-) diff --git a/lib/eventFactory.js b/lib/eventFactory.js index f71f7420..491ddc73 100644 --- a/lib/eventFactory.js +++ b/lib/eventFactory.js @@ -540,7 +540,7 @@ function validateAndMergeParameters(defaultParameters, eventParameters) { } } - allowedParameters[name] = { value: defaultParameterValue }; + allowedParameters[name] = { value: defaultParameterValue, default: defaultParameterValue }; if (eventParameters) { let actualParameterValue = eventParameters[name]; @@ -549,7 +549,7 @@ function validateAndMergeParameters(defaultParameters, eventParameters) { } if (actualParameterValue !== undefined) { - allowedParameters[name] = { value: actualParameterValue }; + allowedParameters[name] = { value: actualParameterValue, default: defaultParameterValue }; } } }); diff --git a/test/lib/eventFactory.test.js b/test/lib/eventFactory.test.js index b5ac911c..8d488038 100644 --- a/test/lib/eventFactory.test.js +++ b/test/lib/eventFactory.test.js @@ -2621,7 +2621,7 @@ describe('Event Factory', () => { pipelineMock.sync = sinon.stub().resolves(pipelineWithParameter); return eventFactory.create(config).then(model => { - assert.equal(model.meta.parameters.user.value, 'batman'); + assert.deepEqual(model.meta.parameters.user, { value: 'batman', default: 'adong' }); }); }); @@ -2642,7 +2642,7 @@ describe('Event Factory', () => { pipelineMock.sync = sinon.stub().resolves(pipelineWithParameter); return eventFactory.create(config).then(model => { - assert.equal(model.meta.parameters.user.value, 'adong'); + assert.deepEqual(model.meta.parameters.user, { value: 'adong', default: 'adong' }); }); }); @@ -2658,7 +2658,7 @@ describe('Event Factory', () => { config.startFrom = 'main'; return eventFactory.create(config).then(model => { - assert.equal(model.meta.parameters.user.value, 'adong'); + assert.deepEqual(model.meta.parameters.user, { value: 'adong', default: 'adong' }); assert.equal(config.meta.parameters.user.value, 'adong'); }); }); @@ -2678,7 +2678,7 @@ describe('Event Factory', () => { config.startFrom = 'main'; return eventFactory.create(config).then(model => { - assert.equal(model.meta.parameters.user.value, 'adong'); + assert.deepEqual(model.meta.parameters.user, { value: 'adong', default: 'adong' }); assert.equal(config.meta.parameters.user.value, 'adong'); }); }); @@ -2695,7 +2695,7 @@ describe('Event Factory', () => { config.startFrom = 'main'; return eventFactory.create(config).then(model => { - assert.equal(model.meta.parameters.user.value, 'adong'); + assert.deepEqual(model.meta.parameters.user, { value: 'adong', default: 'adong' }); assert.equal(config.meta.parameters.user.value, 'adong'); }); }); @@ -2715,7 +2715,7 @@ describe('Event Factory', () => { config.startFrom = 'main'; return eventFactory.create(config).then(model => { - assert.equal(model.meta.parameters.user.value, 'adong'); + assert.deepEqual(model.meta.parameters.user, { value: 'adong', default: 'adong' }); assert.equal(config.meta.parameters.user.value, 'adong'); }); }); @@ -2813,34 +2813,43 @@ describe('Event Factory', () => { assert.deepEqual(model.meta.parameters, { component: { car: { - value: 'Audi' + value: 'Audi', + default: 'Audi' }, color: { - value: 'white' + value: 'white', + default: 'white' }, cuisine: { - value: 'Italian' + value: 'Italian', + default: 'Italian' }, music: { - value: 'jazz' + value: 'jazz', + default: 'jazz' } }, publish: { car: { - value: 'Ferrari' + value: 'Ferrari', + default: 'Ferrari' }, color: { - value: 'red' + value: 'red', + default: 'red' }, cuisine: { - value: 'Japanese' + value: 'Japanese', + default: 'Japanese' }, sports: { - value: 'cricket' + value: 'cricket', + default: 'cricket' } }, user: { - value: 'ironman' + value: 'ironman', + default: 'ironman' } }); }); @@ -2865,34 +2874,43 @@ describe('Event Factory', () => { assert.deepEqual(model.meta.parameters, { component: { car: { - value: 'Audi' + value: 'Audi', + default: 'Audi' }, color: { - value: 'blue' + value: 'blue', + default: 'white' }, cuisine: { - value: 'Indian' + value: 'Indian', + default: 'Italian' }, music: { - value: 'jazz' + value: 'jazz', + default: 'jazz' } }, publish: { car: { - value: 'McLaren' + value: 'McLaren', + default: 'Ferrari' }, color: { - value: 'red' + value: 'red', + default: 'red' }, cuisine: { - value: 'Japanese' + value: 'Japanese', + default: 'Japanese' }, sports: { - value: 'baseball' + value: 'baseball', + default: 'cricket' } }, user: { - value: 'batman' + value: 'batman', + default: 'ironman' } }); });