fix: Add valid version with valid exception use case (#5368)

This commit is contained in:
Diego Mello 2023-11-27 15:28:19 -03:00 committed by GitHub
parent 31ed940426
commit 16347b0bb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 15 deletions

View File

@ -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({

View File

@ -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({

View File

@ -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()) {