fix: Add valid version with valid exception use case (#5368)
This commit is contained in:
parent
31ed940426
commit
16347b0bb6
|
@ -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({
|
||||
|
|
|
@ -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({
|
||||
|
|
|
@ -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()) {
|
||||
|
|
Loading…
Reference in New Issue