import { describe, expect, it } from 'vitest'; import { extractUdpPort } from '../../src/lib/server/integrations/komodo.js'; describe('extractUdpPort', () => { it('returns the published port from docker-compose-style object entries', () => { const payload = { state: { container: { ports: [ { protocol: 'tcp', published: 3000, target: 3000 }, { protocol: 'udp', published: 4976, target: 28960 } ] } } }; expect(extractUdpPort(payload)).toBe(4976); }); it('parses docker-run-style "host:container/proto" strings', () => { const payload = { ports: ['3074:3074/tcp', '4977:28960/udp'] }; expect(extractUdpPort(payload)).toBe(4977); }); it('picks the UDP entry even when TCP appears first', () => { const payload = { deeply: { nested: { ports: [ { Protocol: 'tcp', PublishedPort: 80 }, { Protocol: 'udp', PublishedPort: 5555 } ] } } }; expect(extractUdpPort(payload)).toBe(5555); }); it('returns null when no UDP mapping exists', () => { const payload = { ports: [{ protocol: 'tcp', published: 3000 }] }; expect(extractUdpPort(payload)).toBeNull(); }); it('survives cyclic references', () => { const cyc: Record = {}; cyc.self = cyc; expect(extractUdpPort(cyc)).toBeNull(); }); });