1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/src/lib/services/client-spec-service.test.ts

30 lines
1.2 KiB
TypeScript
Raw Normal View History

import { ClientSpecService } from './client-spec-service';
import getLogger from '../../test/fixtures/no-logger';
test('ClientSpecService validation', async () => {
const service = new ClientSpecService({ getLogger });
const fn = service.versionSupportsSpec.bind(service);
expect(fn('segments', undefined)).toEqual(false);
expect(fn('segments', '')).toEqual(false);
expect(() => fn('segments', 'a')).toThrow('Invalid prefix');
expect(() => fn('segments', '1.2')).toThrow('Invalid SemVer');
expect(() => fn('segments', 'v1.2.3')).toThrow('Invalid prefix');
expect(() => fn('segments', '=1.2.3')).toThrow('Invalid prefix');
expect(() => fn('segments', '1.2.3.4')).toThrow('Invalid SemVer');
});
test('ClientSpecService segments', async () => {
const service = new ClientSpecService({ getLogger });
const fn = service.versionSupportsSpec.bind(service);
expect(fn('segments', '0.0.0')).toEqual(false);
expect(fn('segments', '1.0.0')).toEqual(false);
expect(fn('segments', '4.1.9')).toEqual(false);
expect(fn('segments', '4.2.0')).toEqual(true);
expect(fn('segments', '4.2.1')).toEqual(true);
expect(fn('segments', '5.0.0')).toEqual(true);
});