Skip to content

Commit

Permalink
fix: Store default parameters in event meta (#630)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkyi authored Sep 30, 2024
1 parent 1863449 commit 8ec630c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 26 deletions.
4 changes: 2 additions & 2 deletions lib/eventFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ function validateAndMergeParameters(defaultParameters, eventParameters) {
}
}

allowedParameters[name] = { value: defaultParameterValue };
allowedParameters[name] = { value: defaultParameterValue, default: defaultParameterValue };
if (eventParameters) {
let actualParameterValue = eventParameters[name];

Expand All @@ -549,7 +549,7 @@ function validateAndMergeParameters(defaultParameters, eventParameters) {
}

if (actualParameterValue !== undefined) {
allowedParameters[name] = { value: actualParameterValue };
allowedParameters[name] = { value: actualParameterValue, default: defaultParameterValue };
}
}
});
Expand Down
66 changes: 42 additions & 24 deletions test/lib/eventFactory.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
});
});

Expand All @@ -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' });
});
});

Expand All @@ -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');
});
});
Expand All @@ -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');
});
});
Expand All @@ -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');
});
});
Expand All @@ -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');
});
});
Expand Down Expand Up @@ -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'
}
});
});
Expand All @@ -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'
}
});
});
Expand Down

0 comments on commit 8ec630c

Please sign in to comment.