Skip to content

Commit

Permalink
fix: Add valid version with valid exception use case (#5368)
Browse files Browse the repository at this point in the history
  • Loading branch information
diegolmello authored Nov 27, 2023
1 parent 31ed940 commit 16347b0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 15 deletions.
19 changes: 19 additions & 0 deletions app/lib/methods/checkSupportedVersions-enforcement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand Down Expand Up @@ -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({
Expand Down
19 changes: 19 additions & 0 deletions app/lib/methods/checkSupportedVersions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand Down Expand Up @@ -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({
Expand Down
20 changes: 5 additions & 15 deletions app/lib/methods/checkSupportedVersions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down

0 comments on commit 16347b0

Please sign in to comment.