import { describe, expect, it } from 'vitest'; import { checkApiVersion, HOST_API_VERSION, isApiVersionSupported } from './api-version'; describe('checkApiVersion', () => { it('accepts a supported major', () => { const result = checkApiVersion('1'); expect(result).toEqual({ compatible: true, version: 1 }); }); it('rejects a non-numeric version with a reason', () => { const result = checkApiVersion('1.0'); expect(result.compatible).toBe(false); expect(result.version).toBeNull(); expect(result.reason).toMatch(/whole-number major/i); }); it('rejects a version above the host range', () => { const result = checkApiVersion('2', { min: 1, max: 1 }); expect(result.compatible).toBe(false); expect(result.version).toBe(2); expect(result.reason).toMatch(/outside the supported range 1–1/); }); it('rejects a version below the host range', () => { const result = checkApiVersion('1', { min: 2, max: 3 }); expect(result.compatible).toBe(false); expect(result.reason).toMatch(/outside the supported range 2–3/); }); it('accepts any major inside a wider host range', () => { expect(checkApiVersion('2', { min: 1, max: 3 }).compatible).toBe(true); }); }); describe('isApiVersionSupported', () => { it('mirrors checkApiVersion as a boolean', () => { expect(isApiVersionSupported(String(HOST_API_VERSION))).toBe(true); expect(isApiVersionSupported('99')).toBe(false); }); });