import { describe, expect, it } from 'vitest';

import { buildJoinSlug, extractSlugFromHostname } from './slug';

describe('buildJoinSlug', () => {
  it('sanitizes server names', () => {
    const slug = buildJoinSlug('My Cool Server!', '00000000-0000-4000-8000-000000000099');
    expect(slug).toMatch(/^my-cool-server-000000$/);
  });
});

describe('extractSlugFromHostname', () => {
  it('extracts slug from play domain hostname', () => {
    expect(extractSlugFromHostname('abc.play.example.net', 'play.example.net')).toBe('abc');
  });

  it('rejects unknown domains', () => {
    expect(extractSlugFromHostname('abc.other.net', 'play.example.net')).toBeNull();
  });
});
