/**
 * Tests for File Access
 * Phase 5: Sites Renderer & Bulk Generation
 */
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { getFileUrl, getImageUrl } from '../utils/fileAccess';

// Mock fetch
global.fetch = vi.fn();

describe('File Access', () => {
  beforeEach(() => {
    vi.clearAllMocks();
  });

  it('loads images correctly', async () => {
    // Test: File access works (images, documents, media)
    const mockImageUrl = 'https://example.com/images/test.jpg';
    
    (global.fetch as any).mockResolvedValueOnce({
      ok: true,
      url: mockImageUrl,
    });

    const url = await getImageUrl(1, 'test.jpg', 1);
    expect(url).toBeDefined();
  });

  it('loads documents correctly', async () => {
    // Test: File access works (images, documents, media)
    const mockDocUrl = 'https://example.com/documents/test.pdf';
    
    (global.fetch as any).mockResolvedValueOnce({
      ok: true,
      url: mockDocUrl,
    });

    const url = await getFileUrl(1, 'documents', 'test.pdf', 1);
    expect(url).toBeDefined();
  });

  it('loads media files correctly', async () => {
    // Test: File access works (images, documents, media)
    const mockMediaUrl = 'https://example.com/media/test.mp4';
    
    (global.fetch as any).mockResolvedValueOnce({
      ok: true,
      url: mockMediaUrl,
    });

    const url = await getFileUrl(1, 'media', 'test.mp4', 1);
    expect(url).toBeDefined();
  });
});

