import { expect, tap } from '@git.zone/tstest/tapbundle';
import { createCastDiscoveryDescriptor } from '../../ts/integrations/cast/index.js';

tap.test('matches Google Cast mDNS records', async () => {
  const descriptor = createCastDiscoveryDescriptor();
  const matcher = descriptor.getMatchers()[0];
  const result = await matcher.matches({
    type: '_googlecast._tcp.local.',
    name: 'Living Room TV._googlecast._tcp.local.',
    host: 'living-room-tv.local',
    port: 8009,
    txt: {
      id: '1234567890abcdef1234567890abcdef',
      fn: 'Living Room TV',
      md: 'Chromecast',
    },
  }, {});
  expect(result.matched).toBeTrue();
  expect(result.candidate?.host).toEqual('living-room-tv.local');
  expect(result.candidate?.port).toEqual(8009);
  expect(result.normalizedDeviceId).toEqual('1234567890abcdef1234567890abcdef');
});

export default tap.start();
