shlink-web-client/test/utils/helpers/version.test.ts

26 lines
1.4 KiB
TypeScript
Raw Normal View History

2023-04-13 23:47:13 +03:00
import { fromPartial } from '@total-typescript/shoehorn';
2023-08-04 09:56:06 +03:00
import type { Empty, SemVer, Versions } from '../../../src/utils/helpers/version';
2023-02-18 12:40:37 +03:00
import { versionMatch } from '../../../src/utils/helpers/version';
describe('version', () => {
describe('versionMatch', () => {
it.each([
2023-04-13 23:47:13 +03:00
[undefined, fromPartial<Versions>({}), false],
[null, fromPartial<Versions>({}), false],
['' as Empty, fromPartial<Versions>({}), false],
[[], fromPartial<Versions>({}), false],
['2.8.3' as SemVer, fromPartial<Versions>({}), true],
['2.8.3' as SemVer, fromPartial<Versions>({ minVersion: '2.0.0' }), true],
['2.0.0' as SemVer, fromPartial<Versions>({ minVersion: '2.0.0' }), true],
['1.8.0' as SemVer, fromPartial<Versions>({ maxVersion: '1.8.0' }), true],
['1.7.1' as SemVer, fromPartial<Versions>({ maxVersion: '1.8.0' }), true],
['1.7.3' as SemVer, fromPartial<Versions>({ minVersion: '1.7.0', maxVersion: '1.8.0' }), true],
['1.8.3' as SemVer, fromPartial<Versions>({ minVersion: '2.0.0' }), false],
['1.8.3' as SemVer, fromPartial<Versions>({ maxVersion: '1.8.0' }), false],
['1.8.3' as SemVer, fromPartial<Versions>({ minVersion: '1.7.0', maxVersion: '1.8.0' }), false],
])('properly matches versions based on what is provided', (version, versionConstraints, expected) => {
expect(versionMatch(version, versionConstraints)).toEqual(expected);
});
});
});