Skip to content

Commit

Permalink
feat: add elementTemplates#getIncompatibleEngines API
Browse files Browse the repository at this point in the history
Can be used to test an element template for compatibility,
returning current and expected engine versions.
  • Loading branch information
nikku authored and jarekdanielak committed Dec 12, 2024
1 parent 009772a commit f9b46bc
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/element-templates/ElementTemplates.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,24 +196,35 @@ export default class ElementTemplates {
* @return {boolean} - true if compatible or no engine is set for elementTemplates or template.
*/
isCompatible(template) {
return !Object.keys(this.getIncompatibleEngines(template)).length;
}

/**
* Get engines that are incompatible with the template.
*
* @param {any} template
*
* @return { Record<string, { required: string, found: string } } - incompatible engines along with their template and local versions
*/
getIncompatibleEngines(template) {
const localEngines = this._engines;
const templateEngines = template.engines;

for (const engine in templateEngines) {

// we check compatibility against all locally provided
// engines, hence computing the overlap here.
return reduce(templateEngines, (result, _, engine) => {

if (!has(localEngines, engine)) {
continue;
return result;
}

if (!isSemverCompatible(localEngines[engine], templateEngines[engine])) {
return false;
result[engine] = {
actual: localEngines[engine],
required: templateEngines[engine]
};
}
}

return true;
return result;
}, {});
}

/**
Expand Down
82 changes: 82 additions & 0 deletions test/spec/cloud-element-templates/ElementTemplates.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1491,6 +1491,86 @@ describe('provider/cloud-element-templates - ElementTemplates', function() {
}));
});


describe('getIncompatibleEngines', function() {

it('should return incompatible engine', inject(function(elementTemplates) {

// given
elementTemplates.setEngines({
camunda: '8.5'
});

const template = {
engines: {
camunda: '>= 8.6'
}
};

// then
const result = elementTemplates.getIncompatibleEngines(template);

expect(result).to.eql({
camunda: {
actual: '8.5.0',
required: '>= 8.6'
}
});
}));


it('should return multiple', inject(function(elementTemplates) {

// given
elementTemplates.setEngines({
camunda: '8.5',
desktopModeler: '5.30'
});

const template = {
engines: {
camunda: '>= 8.6',
desktopModeler: '^4.0'
}
};

// then
const result = elementTemplates.getIncompatibleEngines(template);

expect(result).to.eql({
camunda: {
actual: '8.5.0',
required: '>= 8.6'
},
desktopModeler: {
actual: '5.30.0',
required: '^4.0'
}
});
}));


it('should return empty object if compatible', inject(function(elementTemplates) {

// given
elementTemplates.setEngines({
nonMatchingEngine: '8.5'
});

const template = {
engines: {
camunda: '8.5',
}
};

// then
const result = elementTemplates.getIncompatibleEngines(template);

expect(result).to.eql({});
}));

});

});


Expand Down Expand Up @@ -1531,6 +1611,8 @@ describe('provider/cloud-element-templates - ElementTemplates - error handling o
});




describe('provider/cloud-element-templates - ElementTemplates - integration', function() {

let container;
Expand Down

0 comments on commit f9b46bc

Please sign in to comment.