From 962976e390ab2b499e2241821430c4ce34ea70ff Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Wed, 9 Nov 2022 11:34:37 +0100 Subject: [PATCH] chore(util/Engines): expose getLatestStable utility --- client/src/app/TabsProvider.js | 11 ++---- client/src/app/__tests__/TabsProviderSpec.js | 26 +++++--------- client/src/util/Engines.js | 12 +++++++ client/src/util/__tests__/EnginesSpec.js | 36 ++++++++++++++++++++ 4 files changed, 60 insertions(+), 25 deletions(-) create mode 100644 client/src/util/__tests__/EnginesSpec.js diff --git a/client/src/app/TabsProvider.js b/client/src/app/TabsProvider.js index 64f95bcbf7..fda4a5bf8a 100644 --- a/client/src/app/TabsProvider.js +++ b/client/src/app/TabsProvider.js @@ -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'; @@ -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 diff --git a/client/src/app/__tests__/TabsProviderSpec.js b/client/src/app/__tests__/TabsProviderSpec.js index b8b371a24e..ca38210e3a 100644 --- a/client/src/app/__tests__/TabsProviderSpec.js +++ b/client/src/app/__tests__/TabsProviderSpec.js @@ -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'; @@ -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 }"`); }); @@ -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 }"`); }); @@ -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 }"`); }); @@ -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 }"`); }); diff --git a/client/src/util/Engines.js b/client/src/util/Engines.js index fd5347f92b..e2651dd0f3 100644 --- a/client/src/util/Engines.js +++ b/client/src/util/Engines.js @@ -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; +} diff --git a/client/src/util/__tests__/EnginesSpec.js b/client/src/util/__tests__/EnginesSpec.js new file mode 100644 index 0000000000..a59b8d39c4 --- /dev/null +++ b/client/src/util/__tests__/EnginesSpec.js @@ -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')); + + }); + +});