From 16347b0bb67ce8f2ad04ecc03631c023d8f0ba93 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Mon, 27 Nov 2023 15:28:19 -0300 Subject: [PATCH] fix: Add valid version with valid exception use case (#5368) --- ...checkSupportedVersions-enforcement.test.ts | 19 ++++++++++++++++++ .../methods/checkSupportedVersions.test.ts | 19 ++++++++++++++++++ app/lib/methods/checkSupportedVersions.ts | 20 +++++-------------- 3 files changed, 43 insertions(+), 15 deletions(-) diff --git a/app/lib/methods/checkSupportedVersions-enforcement.test.ts b/app/lib/methods/checkSupportedVersions-enforcement.test.ts index a47fa50fa..528a6e2af 100644 --- a/app/lib/methods/checkSupportedVersions-enforcement.test.ts +++ b/app/lib/methods/checkSupportedVersions-enforcement.test.ts @@ -26,6 +26,10 @@ const MOCK: ISupportedVersionsData = { version: '1.5.0', expiration: '2023-05-10T00:00:00.000Z' }, + { + version: '2.4.0', + expiration: '2023-04-10T00:00:00.000Z' + }, { version: '1.4.0', expiration: '2023-04-10T00:00:00.000Z' @@ -47,6 +51,10 @@ const MOCK: ISupportedVersionsData = { domain: 'https://open.rocket.chat', uniqueId: '123', versions: [ + { + version: '2.4.0', + expiration: '2023-05-01T00:00:00.000Z' + }, { version: '1.3.0', expiration: '2023-05-01T00:00:00.000Z' @@ -217,6 +225,17 @@ describe('checkSupportedVersions', () => { }); }); + test('valid version and valid exception', () => { + expect( + checkSupportedVersions({ + supportedVersions: MOCK, + serverVersion: '2.4.0' + }) + ).toMatchObject({ + status: 'supported' + }); + }); + test('expired version and valid exception', () => { expect( checkSupportedVersions({ diff --git a/app/lib/methods/checkSupportedVersions.test.ts b/app/lib/methods/checkSupportedVersions.test.ts index fb0639adf..6d1352782 100644 --- a/app/lib/methods/checkSupportedVersions.test.ts +++ b/app/lib/methods/checkSupportedVersions.test.ts @@ -26,6 +26,10 @@ const MOCK: ISupportedVersionsData = { version: '1.5.0', expiration: '2023-05-10T00:00:00.000Z' }, + { + version: '2.4.0', + expiration: '2023-04-10T00:00:00.000Z' + }, { version: '1.4.0', expiration: '2023-04-10T00:00:00.000Z' @@ -47,6 +51,10 @@ const MOCK: ISupportedVersionsData = { domain: 'https://open.rocket.chat', uniqueId: '123', versions: [ + { + version: '2.4.0', + expiration: '2023-05-01T00:00:00.000Z' + }, { version: '1.3.0', expiration: '2023-05-01T00:00:00.000Z' @@ -223,6 +231,17 @@ describe('checkSupportedVersions', () => { }); }); + test('valid version and valid exception', () => { + expect( + checkSupportedVersions({ + supportedVersions: MOCK, + serverVersion: '2.4.0' + }) + ).toMatchObject({ + status: 'supported' + }); + }); + test('expired version and valid exception', () => { expect( checkSupportedVersions({ diff --git a/app/lib/methods/checkSupportedVersions.ts b/app/lib/methods/checkSupportedVersions.ts index bca4fd0a3..86c504afc 100644 --- a/app/lib/methods/checkSupportedVersions.ts +++ b/app/lib/methods/checkSupportedVersions.ts @@ -52,22 +52,12 @@ export const checkSupportedVersions = function ({ } const versionInfo = sv.versions.find(({ version }) => satisfies(coerce(version)?.version ?? '', serverVersionTilde)); - if (versionInfo && new Date(versionInfo.expiration) >= new Date()) { - const messages = versionInfo?.messages || sv?.messages; - const message = getMessage({ messages, expiration: versionInfo.expiration }); - return { - status: getStatus({ expiration: versionInfo?.expiration, message }), - message, - i18n: message ? sv?.i18n : undefined, - expiration: versionInfo?.expiration - }; - } - - // Exceptions const exception = sv.exceptions?.versions?.find(({ version }) => satisfies(coerce(version)?.version ?? '', serverVersionTilde)); - const messages = exception?.messages || sv.exceptions?.messages || versionInfo?.messages || sv.messages; - const message = getMessage({ messages, expiration: exception?.expiration }); - const status = getStatus({ expiration: exception?.expiration, message }); + const messages = + exception?.messages || (exception ? sv.exceptions?.messages : undefined) || versionInfo?.messages || sv.messages; + const expiration = exception?.expiration || versionInfo?.expiration; + const message = getMessage({ messages, expiration }); + const status = getStatus({ message, expiration }); // TODO: enforcement start date is temp only. Remove after a few releases. if (status === 'expired' && sv?.enforcementStartDate && new Date(sv.enforcementStartDate) > new Date()) {