Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mati365 committed Nov 4, 2024
1 parent 6198313 commit e517a9e
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 14 deletions.
27 changes: 16 additions & 11 deletions src/cdn/ck/isCKCdnVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 ) );
}

/**
Expand All @@ -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 );
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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.
Expand Down
7 changes: 5 additions & 2 deletions tests/cdn/ck/isCKCdnVersion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/cdn/loadCKEditorCloud.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e517a9e

Please sign in to comment.