import { describe, it, expect } from 'vitest'; import { compareVersions, fetchLatestKuttRelease, createLink } from '../../lib/links/kutt.js'; describe('kutt helpers', () => { it('compareVersions flags an available update (tolerates v-prefix)', () => { expect(compareVersions('v3.2.5', 'v3.2.6')).toEqual({ running: 'v3.2.5', latest: 'v3.2.6', updateAvailable: true }); expect(compareVersions('3.2.6', 'v3.2.6')).toMatchObject({ updateAvailable: false }); }); it('fetchLatestKuttRelease returns tag + url from the GitHub API (injected fetch)', async () => { const fakeFetch = async () => ({ ok: true, json: async () => ({ tag_name: 'v3.2.6', html_url: 'https://x/releases/v3.2.6' }) }); expect(await fetchLatestKuttRelease({ fetch: fakeFetch })).toEqual({ latest: 'v3.2.6', url: 'https://x/releases/v3.2.6' }); }); it('createLink POSTs to the Kutt API with the key and returns the short link', async () => { let seen; const fakeFetch = async (url, opts) => { seen = { url, opts }; return { ok: true, json: async () => ({ link: 'https://link.hynesy.com/abc', address: 'abc' }) }; }; const r = await createLink({ target: 'https://example.com' }, { base: 'http://10.0.0.1:3000', key: 'K', fetch: fakeFetch }); expect(seen.url).toBe('http://10.0.0.1:3000/api/v2/links'); expect(seen.opts.headers['X-API-KEY']).toBe('K'); expect(r.link).toBe('https://link.hynesy.com/abc'); }); });