/**
 * Unit tests for version bump / compare used by the release + update subsystem.
 */
import { describe, expect, it } from 'vitest';
import { bumpVersion, compareVersions, parseVersion } from '../src/server/update';

describe('version bump', () => {
  it('hundredths bump drops letter: V1.10b → V1.11', () => {
    expect(bumpVersion('V1.10b', 'hundredths')).toBe('V1.11');
  });
  it('letter bump advances letter: V1.10b → V1.10c', () => {
    expect(bumpVersion('V1.10b', 'letter')).toBe('V1.10c');
  });
  it('letter bump from bare minor adds a', () => {
    expect(bumpVersion('V1.11', 'letter')).toBe('V1.11a');
  });
  it('letter bump rolls z → next minor', () => {
    expect(bumpVersion('V1.10z', 'letter')).toBe('V1.11');
  });
});

describe('version compare', () => {
  it('orders letter under same minor', () => {
    expect(compareVersions('V1.10b', 'V1.10c')).toBeLessThan(0);
    expect(compareVersions('V1.10c', 'V1.10b')).toBeGreaterThan(0);
  });
  it('orders minor above lettered prior', () => {
    expect(compareVersions('V1.11', 'V1.10c')).toBeGreaterThan(0);
  });
  it('parses versions', () => {
    expect(parseVersion('V1.10b')).toEqual({ major: 1, minor: 10, letter: 'b', raw: 'V1.10b' });
  });
});
