import { describe, it } from 'node:test'; import assert from 'node:assert/strict'; import { previewContent } from '../src/site/content.js'; import { ensureStarterPages, STARTER_PAGES } from '../src/site/starter.js'; import { harness } from './support/harness.js'; describe('a new install\'s starter pages', () => { it('adds the fixed pages to a site with none, and the preview shows every homepage section', async () => { const { ctx, db } = await harness({ linked: false }); assert.deepEqual(await ensureStarterPages(ctx), STARTER_PAGES.map((p) => p.kind)); const c = await previewContent(ctx); assert.equal(c.mode, 'published'); if (c.mode !== 'published') return; const home = c.snapshot.pages.find((p) => p.kind === 'home')!; assert.deepEqual(home.sections.map((s) => s.type).sort(), ['events', 'hero', 'invitation', 'latestMessage', 'ministries', 'serviceTimes', 'team', 'welcome']); // Every starter block fits its schema (a broken one would be left out of the site). for (const p of STARTER_PAGES) assert.equal(c.snapshot.pages.find((x) => x.kind === p.kind)!.sections.length, p.sections.length, p.kind); // Terms and Safeguarding are footer links, not menu items. assert.equal(c.snapshot.pages.filter((p) => p.inNav).some((p) => p.kind === 'terms' || p.kind === 'safeguarding'), false); // Only once. assert.deepEqual(await ensureStarterPages(ctx), []); assert.equal(await db.page.count(), STARTER_PAGES.length); }); it('keeps the church\'s own pages, after the fixed ones, and skips an address they already use', async () => { const { ctx, db } = await harness({ linked: false }); await db.page.create({ data: { kind: 'custom', slug: 'test', title: 'Test', position: 1 } }); await db.page.create({ data: { kind: 'custom', slug: 'give', title: 'Giving', position: 2 } }); const kinds = await ensureStarterPages(ctx); assert.ok(kinds.includes('home') && !kinds.includes('give')); const pages = await db.page.findMany({ orderBy: { position: 'asc' } }); assert.equal(pages[0]!.kind, 'home'); assert.deepEqual(pages.slice(-2).map((p) => p.slug), ['test', 'give']); }); it('adds only a missing home page to a site that has its other fixed pages', async () => { const { ctx, db } = await harness({ linked: false }); await db.page.create({ data: { kind: 'about', slug: 'about', title: 'About', archivedAt: new Date() } }); assert.deepEqual(await ensureStarterPages(ctx), ['home']); assert.deepEqual(await ensureStarterPages(ctx), []); }); });