From f42475edfde8506b1e894313b9016ee666ca897c Mon Sep 17 00:00:00 2001 From: Paul D'Ambra Date: Mon, 16 Dec 2024 18:10:14 +0000 Subject: [PATCH] fix --- .../versionCheckerLogic.test.ts | 41 +++++++++++-------- .../VersionChecker/versionCheckerLogic.ts | 5 ++- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/frontend/src/lib/components/VersionChecker/versionCheckerLogic.test.ts b/frontend/src/lib/components/VersionChecker/versionCheckerLogic.test.ts index 103e89b2bfed9..77e7e0e9eb52e 100644 --- a/frontend/src/lib/components/VersionChecker/versionCheckerLogic.test.ts +++ b/frontend/src/lib/components/VersionChecker/versionCheckerLogic.test.ts @@ -73,35 +73,41 @@ describe('versionCheckerLogic', () => { { versionCount: 1, expectation: null }, { versionCount: 11, + expectation: null, + }, + { + versionCount: 51, expectation: { latestUsedVersion: '1.0.0', - latestAvailableVersion: '1.0.10', - numVersionsBehind: 10, - level: 'info', + latestAvailableVersion: '1.0.50', + numVersionsBehind: 50, + level: 'error', }, }, { - versionCount: 15, + minorUsedVersion: 40, + versionCount: 1, expectation: { latestUsedVersion: '1.0.0', - latestAvailableVersion: '1.0.14', - numVersionsBehind: 14, - level: 'info', + latestAvailableVersion: '1.40.0', + numVersionsBehind: 40, + level: 'warning', }, }, { - versionCount: 25, + majorUsedVersion: 2, + versionCount: 1, expectation: { latestUsedVersion: '1.0.0', - latestAvailableVersion: '1.0.24', - numVersionsBehind: 24, - level: 'error', + latestAvailableVersion: '2.0.0', + numVersionsBehind: 1, + level: 'info', }, }, ])('return a version warning if diff is great enough', async (options) => { // TODO: How do we clear the persisted value? const versionsList = Array.from({ length: options.versionCount }, (_, i) => ({ - version: `1.0.${i}`, + version: `${options.majorUsedVersion || 1}.${options.minorUsedVersion || 0}.${i}`, })).reverse() useMockedVersions( @@ -143,13 +149,14 @@ describe('versionCheckerLogic', () => { }, { usedVersions: [ - { version: '1.80.0', timestamp: '2023-01-01T12:00:00Z' }, - { version: '1.83.1-beta', timestamp: '2023-01-01T10:00:00Z' }, - { version: '1.84.0-delta', timestamp: '2023-01-01T08:00:00Z' }, + { version: '1.40.0', timestamp: '2023-01-01T12:00:00Z' }, + { version: '1.41.1-beta', timestamp: '2023-01-01T10:00:00Z' }, + { version: '1.42.0', timestamp: '2023-01-01T08:00:00Z' }, + { version: '1.42.0-delta', timestamp: '2023-01-01T08:00:00Z' }, ], expectation: { - latestUsedVersion: '1.84.0-delta', - numVersionsBehind: 1, + latestUsedVersion: '1.42.0', + numVersionsBehind: 42, latestAvailableVersion: '1.84.0', level: 'warning', }, diff --git a/frontend/src/lib/components/VersionChecker/versionCheckerLogic.ts b/frontend/src/lib/components/VersionChecker/versionCheckerLogic.ts index fd929a0dea46c..4c6067adf4afc 100644 --- a/frontend/src/lib/components/VersionChecker/versionCheckerLogic.ts +++ b/frontend/src/lib/components/VersionChecker/versionCheckerLogic.ts @@ -174,6 +174,7 @@ export const versionCheckerLogic = kea([ if (!warning && sdkVersions && latestAvailableVersion) { const diff = diffVersions(latestAvailableVersion, latestUsedVersion) + if (diff && diff.diff > 0) { // there's a difference between the latest used version and the latest available version @@ -194,8 +195,8 @@ export const versionCheckerLogic = kea([ level = numVersionsBehind >= 40 ? 'warning' : undefined } - if (level === undefined && numVersionsBehind > 50) { - level = 'warning' + if (level === undefined && numVersionsBehind >= 50) { + level = 'error' } // we check if there is a "latest user version string" to avoid returning odd data in unexpected cases