Skip to content

Commit

Permalink
chore(util/Engines): expose getLatestStable utility
Browse files Browse the repository at this point in the history
  • Loading branch information
nikku authored and marstamm committed Nov 9, 2022
1 parent e90a5f6 commit 962976e
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 25 deletions.
11 changes: 3 additions & 8 deletions client/src/app/TabsProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import cloudForm from './tabs/form/initial-cloud.form';

import {
ENGINES,
ENGINE_PROFILES
getLatestStable as getLatestStablePlatformVersion
} from '../util/Engines';

import EmptyTab from './EmptyTab';
Expand Down Expand Up @@ -692,13 +692,8 @@ function sortByPriority(providers) {

function replaceVersions(contents) {

const latestPlatformVersion = ENGINE_PROFILES.find(
p => p.executionPlatform === ENGINES.PLATFORM
).latestStable;

const latestCloudVersion = ENGINE_PROFILES.find(
p => p.executionPlatform === ENGINES.CLOUD
).latestStable;
const latestPlatformVersion = getLatestStablePlatformVersion(ENGINES.PLATFORM);
const latestCloudVersion = getLatestStablePlatformVersion(ENGINES.CLOUD);

return (
contents
Expand Down
26 changes: 9 additions & 17 deletions client/src/app/__tests__/TabsProviderSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import TabsProvider from '../TabsProvider';
import Flags, { DISABLE_DMN, DISABLE_ZEEBE, DISABLE_PLATFORM, DISABLE_CMMN } from '../../util/Flags';

import {
ENGINE_PROFILES,
getLatestStable as getLatestStablePlatformVersion,
ENGINES
} from '../../util/Engines';

Expand Down Expand Up @@ -181,15 +181,13 @@ describe('TabsProvider', function() {
// given
const tabsProvider = new TabsProvider();

const latestPlatformVersion = ENGINE_PROFILES.find(
p => p.executionPlatform === ENGINES.PLATFORM
).latestStable;
const expectedPlatformVersion = getLatestStablePlatformVersion(ENGINES.PLATFORM);

// when
const { file: { contents } } = tabsProvider.createTab('bpmn');

// then
expect(contents).to.include(`modeler:executionPlatformVersion="${ latestPlatformVersion }"`);
expect(contents).to.include(`modeler:executionPlatformVersion="${ expectedPlatformVersion }"`);
});


Expand All @@ -198,15 +196,13 @@ describe('TabsProvider', function() {
// given
const tabsProvider = new TabsProvider();

const latestCloudVersion = ENGINE_PROFILES.find(
p => p.executionPlatform === ENGINES.CLOUD
).latestStable;
const expectedPlatformVersion = getLatestStablePlatformVersion(ENGINES.CLOUD);

// when
const { file: { contents } } = tabsProvider.createTab('cloud-bpmn');

// then
expect(contents).to.include(`modeler:executionPlatformVersion="${ latestCloudVersion }"`);
expect(contents).to.include(`modeler:executionPlatformVersion="${ expectedPlatformVersion }"`);
});


Expand All @@ -215,15 +211,13 @@ describe('TabsProvider', function() {
// given
const tabsProvider = new TabsProvider();

const latestPlatformVersion = ENGINE_PROFILES.find(
p => p.executionPlatform === ENGINES.PLATFORM
).executionPlatformVersions[0];
const expectedPlatformVersion = getLatestStablePlatformVersion(ENGINES.PLATFORM);

// when
const { file: { contents } } = tabsProvider.createTab('dmn');

// then
expect(contents).to.include(`modeler:executionPlatformVersion="${ latestPlatformVersion }"`);
expect(contents).to.include(`modeler:executionPlatformVersion="${ expectedPlatformVersion }"`);
});


Expand All @@ -232,15 +226,13 @@ describe('TabsProvider', function() {
// given
const tabsProvider = new TabsProvider();

const latestCloudVersion = ENGINE_PROFILES.find(
p => p.executionPlatform === ENGINES.CLOUD
).latestStable;
const expectedPlatformVersion = getLatestStablePlatformVersion(ENGINES.CLOUD);

// when
const { file: { contents } } = tabsProvider.createTab('cloud-dmn');

// then
expect(contents).to.include(`modeler:executionPlatformVersion="${ latestCloudVersion }"`);
expect(contents).to.include(`modeler:executionPlatformVersion="${ expectedPlatformVersion }"`);
});


Expand Down
12 changes: 12 additions & 0 deletions client/src/util/Engines.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,15 @@ export const ENGINE_LABELS = {
[ ENGINES.PLATFORM ]: 'Camunda Platform 7',
[ ENGINES.CLOUD ]: 'Camunda Platform 8'
};

export function getLatestStable(platform) {
const profile = ENGINE_PROFILES.find(
p => p.executionPlatform === platform
);

if (!profile) {
throw new Error(`no profile for platform <${platform}>`);
}

return profile.latestStable;
}
36 changes: 36 additions & 0 deletions client/src/util/__tests__/EnginesSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership.
*
* Camunda licenses this file to you under the MIT; you may not use this file
* except in compliance with the MIT License.
*/

import {
getLatestStable,
ENGINES
} from '../Engines';


describe('util/Engines', function() {

describe('should provide latestStable', function() {

function verifyLatestStable(platform, expected) {

return function() {

// then
expect(getLatestStable(platform)).to.eql(expected);
};
}

it('Platform', verifyLatestStable(ENGINES.PLATFORM, '7.18.0'));

it('Cloud', verifyLatestStable(ENGINES.CLOUD, '8.1.0'));

});

});

0 comments on commit 962976e

Please sign in to comment.