import { describe, it, expect, vi, afterEach, beforeEach } from 'vitest' import { useTextContent } from './useTextContent' /** * Pins the slug-free URL shape for runtime text-override fetches. * * The site is resolved server-side (request Host or the dedicated Container * App's DCS_SITE_SLUG), so VITE_SITE_SLUG must NOT appear in the request path. */ describe('useTextContent runtime URL (slug-free)', () => { beforeEach(() => { vi.stubEnv('VITE_API_BASE_URL', 'https://api.example.com') vi.stubEnv('VITE_TEXT_OVERRIDE_MODE', 'runtime') // Still set for source compatibility — must be ignored for routing. vi.stubEnv('VITE_SITE_SLUG', 'kept') }) afterEach(() => { vi.unstubAllEnvs() vi.restoreAllMocks() }) it('fetches /api/v1/pages/{pageSlug}/text without the site slug in the path', async () => { const fetchMock = vi.fn().mockResolvedValue({ ok: true, status: 200, json: async () => ({ overrides: { 'hero.title': 'Hi' } }), }) vi.stubGlobal('fetch', fetchMock) // fetchOnMount: false avoids registering onMounted outside a component // setup context; refresh() drives the same fetch path directly. const { refresh } = useTextContent({ pageSlug: 'home', defaults: {}, fetchOnMount: false, }) await refresh() expect(fetchMock).toHaveBeenCalledTimes(1) const [url] = fetchMock.mock.calls[0] expect(url).toBe('https://api.example.com/api/v1/pages/home/text') expect(url).not.toContain('/sites/') expect(url).not.toContain('kept') }) })