import { afterEach, describe, expect, it, vi } from 'vitest';
import { GET } from './+server';

describe('sitemap endpoint', () => {
  afterEach(() => {
    vi.useRealTimers();
  });

  it('returns a sitemap covering the published routes', async () => {
    vi.useFakeTimers();
    vi.setSystemTime(new Date('2026-05-01T09:15:00Z'));

    const response = await GET({} as never);
    const body = await response.text();

    expect(response.headers.get('content-type')).toBe('application/xml; charset=utf-8');
    expect(body).toContain('<loc>https://www.goodwalk.co.nz/</loc>');
    expect(body).toContain('<loc>https://www.goodwalk.co.nz/contact-us</loc>');
    expect(body).toContain('<loc>https://www.goodwalk.co.nz/privacy-policy</loc>');
    expect(body).toContain('<lastmod>2026-05-01</lastmod>');
    expect(body).not.toContain('/locations/');
    expect(body.match(/<url>/g)).toHaveLength(9);
  });
});
