Skip to content

Commit

Permalink
fix: only mark compatible templates as latest
Browse files Browse the repository at this point in the history
test: verify core element template concerns in core feature
  • Loading branch information
nikku committed Dec 9, 2024
1 parent 8b63a3b commit 2ab8f11
Show file tree
Hide file tree
Showing 4 changed files with 374 additions and 20 deletions.
25 changes: 10 additions & 15 deletions src/element-templates/ElementTemplates.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,26 +129,21 @@ export default class ElementTemplates {
this._templates = templates;

templates.forEach((template) => {
const id = template.id,
version = isUndefined(template.version) ? '_' : template.version;
const id = template.id;
const version = isUndefined(template.version) ? '_' : template.version;

if (!this._templatesById[ id ]) {
this._templatesById[ id ] = {
latest: template
};
this._templatesById[ id ] = { };
}

this._templatesById[ id ][ version ] = template;

const latest = this._templatesById[ id ].latest;

const isCompat = this.isCompatible(template);
if (!isCompat) {
return;
}

if (isUndefined(latest.version) || latest.version < version || !this.isCompatible(latest)) {
this._templatesById[ id ].latest = template;
if (this.isCompatible(template)) {
if (!latest || isUndefined(latest.version) || latest.version < version) {
this._templatesById[ id ].latest = template;
}
}
});

Expand Down Expand Up @@ -230,15 +225,15 @@ export default class ElementTemplates {
_getTemplateVerions(id, options = {}) {

const {
latest: latestOnly,
latest: includeLatestOnly,
deprecated: includeDeprecated
} = options;

const templatesById = this._templatesById;
const getVersions = (template) => {
const { latest, ...versions } = template;
return latestOnly ? (
!includeDeprecated && latest.deprecated ? [] : [ latest ]
return includeLatestOnly ? (
!includeDeprecated && (latest && latest.deprecated) ? [] : (latest ? [ latest ] : [])
) : values(versions) ;
};

Expand Down
12 changes: 7 additions & 5 deletions test/spec/cloud-element-templates/ElementTemplates.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,7 @@ describe('provider/cloud-element-templates - ElementTemplates', function() {
// expect all compatible templates to be returned
// example.engines.test.multiple v2
// example.engines.test.basic v2
// example.engines.test.broken v0
expect(templates).to.have.length(3);
expect(templates).to.have.length(2);
}));

});
Expand Down Expand Up @@ -535,9 +534,12 @@ describe('provider/cloud-element-templates - ElementTemplates', function() {
const templates = elementTemplates.getLatest('example.engines.test.broken');

// then
// assumption: we still regard such template as a valid template
expect(templates).to.have.length(1);
expect(templates[0].version).to.eql(1);
expect(templates).to.be.empty;

// and
// we still regard such template as a valid template
const template = elementTemplates.get('example.engines.test.broken', 1);
expect(template).to.exist;
}));

});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
[
{
"id": "example.engines.test.multiple",
"name": "<engines> Test - Multiple",
"description": "does not match if { desktopModeler: >=1 } is provided",
"version": 2,
"engines": {
"camunda": "^7.14",
"webModeler": "^4.1",
"desktopModeler": "^0"
},
"appliesTo": [
"bpmn:Task"
],
"properties": []
},
{
"id": "example.engines.test.multiple",
"name": "<engines> Test - Multiple",
"description": "matches if { camunda: ^7.14, webModeler: ^4.1 } engine is indicated, or properties are not provided",
"version": 1,
"engines": {
"camunda": "^7.14",
"webModeler": "^4.1"
},
"appliesTo": [
"bpmn:Task"
],
"properties": []
},

{
"id": "example.engines.test.basic",
"name": "<engines> Test - Basic",
"description": "matches if { camunda: ^7.14 }, or if no <camunda> engine is provided",
"version": 3,
"engines": {
"camunda": "^7.14"
},
"appliesTo": [
"bpmn:Task"
],
"properties": []
},
{
"id": "example.engines.test.basic",
"name": "<engines> Test - Basic",
"description": "matches if { camunda: ^7.13 }, or if no <camunda> engine is provided",
"version": 2,
"engines": {
"camunda": "^7.13"
},
"appliesTo": [
"bpmn:Task"
],
"properties": []
},
{
"id": "example.engines.test.basic",
"name": "<engines> Test - Basic",
"description": "always matches",
"version": 1,
"appliesTo": [
"bpmn:Task"
],
"properties": []
},

{
"id": "example.engines.test.broken",
"name": "<engines> Test - broken Semver range",
"description": "specifies broken semver range",
"version": 1,
"engines": {
"camunda": "invalid-version"
},
"appliesTo": [
"bpmn:Task"
],
"properties": []
}
]
Loading

0 comments on commit 2ab8f11

Please sign in to comment.