From e517a9e05489c3a37a3daba01e4dfd01e01f47b1 Mon Sep 17 00:00:00 2001 From: Mateusz Baginski Date: Mon, 4 Nov 2024 13:13:51 +0100 Subject: [PATCH] Fix tests --- src/cdn/ck/isCKCdnVersion.ts | 27 +++++++++++-------- ...SupportedLicenseVersionInstallationInfo.ts | 8 ++++++ tests/cdn/ck/isCKCdnVersion.test.ts | 7 +++-- tests/cdn/loadCKEditorCloud.test.ts | 2 +- ...rtedLicenseVersionInstallationInfo.test.ts | 7 +++++ 5 files changed, 37 insertions(+), 14 deletions(-) diff --git a/src/cdn/ck/isCKCdnVersion.ts b/src/cdn/ck/isCKCdnVersion.ts index 79ea5f4..537723c 100644 --- a/src/cdn/ck/isCKCdnVersion.ts +++ b/src/cdn/ck/isCKCdnVersion.ts @@ -3,15 +3,15 @@ * For licensing, see LICENSE.md. */ -import { isSemanticVersion, type SemanticVersion } from '../../utils/isSemanticVersion.js'; +import { isSemanticVersion, type SemanticVersion } from '../../utils/version/isSemanticVersion.js'; /** - * A version of a file on the CKEditor CDN that is used for testing purposes. + * A version of the CKEditor that is used for testing purposes. */ export type CKCdnTestingVersion = + | 'nightly' | 'alpha' - | `${ SemanticVersion }-nightly-${ string }` - | `rc-${ string }`; + | 'internal'; /** * A version of a file on the CKEditor CDN. @@ -27,14 +27,19 @@ export type CKCdnVersion = * @returns `true` if the string is a version of a file on the CKEditor CDN, `false` otherwise. * @example * ```ts - * isCKCdnVersion( 'nightly' ); // -> true - * isCKCdnVersion( 'alpha' ); // -> true - * isCKCdnVersion( 'rc-1.2.3' ); // -> true - * isCKCdnVersion( '1.2.3' ); // -> false + * isCKCdnTestingVersion( '1.2.3-nightly-abc' ); // -> true + * isCKCdnTestingVersion( '1.2.3-internal-abc' ); // -> true + * isCKCdnTestingVersion( '1.2.3-alpha.1' ); // -> true + * isCKCdnTestingVersion( '1.2.3' ); // -> false + * isCKCdnTestingVersion( 'nightly' ); // -> true * ``` */ -export function isCKCdnTestingVersion( version: string ): version is CKCdnTestingVersion { - return version === 'alpha' || version === 'nightly' || version.startsWith( 'rc-' ); +export function isCKCdnTestingVersion( version: string | undefined ): version is CKCdnTestingVersion { + if ( !version ) { + return false; + } + + return [ 'nightly', 'alpha', 'internal' ].some( testVersion => version.includes( testVersion ) ); } /** @@ -50,6 +55,6 @@ export function isCKCdnTestingVersion( version: string ): version is CKCdnTestin * isCKCdnVersion( '1.2.3' ); // -> true * ``` */ -export function isCKCdnVersion( version: string ): version is CKCdnVersion { +export function isCKCdnVersion( version: string | undefined ): version is CKCdnVersion { return isSemanticVersion( version ) || isCKCdnTestingVersion( version ); } diff --git a/src/installation-info/getSupportedLicenseVersionInstallationInfo.ts b/src/installation-info/getSupportedLicenseVersionInstallationInfo.ts index 9d7482d..e050a94 100644 --- a/src/installation-info/getSupportedLicenseVersionInstallationInfo.ts +++ b/src/installation-info/getSupportedLicenseVersionInstallationInfo.ts @@ -3,6 +3,7 @@ * For licensing, see LICENSE.md. */ +import { isCKCdnTestingVersion } from 'cdn/ck/isCKCdnVersion.js'; import type { LicenseKeyVersion } from '../license/LicenseKey.js'; import { destructureSemanticVersion } from '../utils/version/destructureSemanticVersion.js'; @@ -22,6 +23,13 @@ export function getSupportedLicenseVersionInstallationInfo(): LicenseKeyVersion } const { version } = installationInfo; + + // Assume that the testing version is always the newest one + // so we can return the highest supported license version. + if ( isCKCdnTestingVersion( version ) ) { + return 3; + } + const { major } = destructureSemanticVersion( version ); // License V3 was released in CKEditor 44.0.0. diff --git a/tests/cdn/ck/isCKCdnVersion.test.ts b/tests/cdn/ck/isCKCdnVersion.test.ts index c48194b..29c457b 100644 --- a/tests/cdn/ck/isCKCdnVersion.test.ts +++ b/tests/cdn/ck/isCKCdnVersion.test.ts @@ -9,10 +9,13 @@ import { isCKCdnVersion, isCKCdnTestingVersion } from '@/cdn/ck/isCKCdnVersion.j const testCases = [ { version: 'alpha', isTesting: true, isVersion: true }, { version: 'nightly', isTesting: true, isVersion: true }, - { version: 'rc-1.2.3', isTesting: true, isVersion: true }, + { version: 'rc-1.2.3', isTesting: false, isVersion: false }, { version: '1.2.3', isTesting: false, isVersion: true }, { version: 'beta', isTesting: false, isVersion: false }, - { version: '1.2', isTesting: false, isVersion: false } + { version: '1.2', isTesting: false, isVersion: false }, + { version: '0.0.0-nightly-20241104.0', isTesting: true, isVersion: true }, + { version: '0.0.0-internal-20241104.0', isTesting: true, isVersion: true }, + { version: '43.3.0-alpha.12 ', isTesting: true, isVersion: true } ]; describe( 'isCKCdnTestingVersion', () => { diff --git a/tests/cdn/loadCKEditorCloud.test.ts b/tests/cdn/loadCKEditorCloud.test.ts index bfa9240..04d6f63 100644 --- a/tests/cdn/loadCKEditorCloud.test.ts +++ b/tests/cdn/loadCKEditorCloud.test.ts @@ -36,7 +36,7 @@ describe( 'loadCKEditorCloud', () => { vi.restoreAllMocks(); } ); - for ( const version of [ 'alpha', 'nightly' ] as const ) { + for ( const version of [ 'alpha', 'internal' ] as const ) { it( `should raise warning if ${ version } version is used`, async () => { const { CKEditor } = await loadCKEditorCloud( { version diff --git a/tests/installation-info/getSupportedLicenseVersionInstallationInfo.test.ts b/tests/installation-info/getSupportedLicenseVersionInstallationInfo.test.ts index 158f5a1..4046f26 100644 --- a/tests/installation-info/getSupportedLicenseVersionInstallationInfo.test.ts +++ b/tests/installation-info/getSupportedLicenseVersionInstallationInfo.test.ts @@ -51,6 +51,13 @@ describe( 'getSupportedLicenseVersionInstallationInfo', () => { mockEditorVersion( '37.0.0' ); expect( getSupportedLicenseVersionInstallationInfo() ).toEqual( 1 ); } ); + + it( 'should return license V3 for test versions', () => { + for ( const version of [ 'alpha', 'nightly', 'internal' ] ) { + mockEditorVersion( version ); + expect( getSupportedLicenseVersionInstallationInfo() ).toEqual( 3 ); + } + } ); } ); function mockEditorVersion( version: string ): void {