import { beforeEach, describe, expect, it, vi } from 'vitest';
import { staticPages } from '$lib/content/static-pages';
import { sharedPageContent } from '../../test/fixtures';

const { getSharedPageContent } = vi.hoisted(() => ({
  getSharedPageContent: vi.fn()
}));

vi.mock('$lib/server/content', () => ({
  getSharedPageContent
}));

import { load } from './+page.server';

describe('static slug page server load', () => {
  beforeEach(() => {
    getSharedPageContent.mockReset();
  });

  it('redirects the legacy about-us slug to /about', async () => {
    await expect(load({ params: { slug: 'about-us' } } as never)).rejects.toMatchObject({
      status: 301,
      location: '/about'
    });
  });

  it('redirects the legacy booking slug to /contact-us', async () => {
    await expect(load({ params: { slug: 'booking' } } as never)).rejects.toMatchObject({
      status: 301,
      location: '/contact-us'
    });
  });

  it('throws a 404 for unknown slugs', async () => {
    await expect(load({ params: { slug: 'missing-page' } } as never)).rejects.toMatchObject({
      status: 404
    });
  });

  it('returns the shared content and page metadata for valid static routes', async () => {
    getSharedPageContent.mockResolvedValue(sharedPageContent);

    await expect(load({ params: { slug: 'pack-walks' } } as never)).resolves.toEqual({
      content: sharedPageContent,
      page: staticPages['pack-walks'],
      slug: 'pack-walks'
    });
  });
});
