Open History to see the last commit
1import { describe, expect, it } from 'vitest'
2import { env } from 'cloudflare:test'
3
4import { getDb } from '../db/index.ts'
5import { changes, providers } from '../db/schema.ts'
6import { CANONICAL_PATHS, robotsTxt, sitemapXml } from './seo.ts'
7
8const ORIGIN = 'https://modelschemas.com'
9
10describe('sitemap + robots (task 10.1)', () => {
11 it('renders a sitemaps.org urlset covering every canonical path', async () => {
12 const db = getDb(env)
13 await db.insert(providers).values({
14 id: 'seo-prov',
15 displayName: 'SEO Prov',
16 specSourceUrl: 'https://example.com/spec.json',
17 })
18 await db.insert(changes).values({
19 id: 'seo-change',
20 type: 'model.added',
21 providerId: 'seo-prov',
22 subjectId: 'm',
23 summary: 's',
24 createdAt: 1_781_150_000,
25 })
26
27 const xml = await sitemapXml(db, ORIGIN)
28 expect(xml).toContain('<?xml version="1.0" encoding="UTF-8"?>')
29 expect(xml).toContain(
30 '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
31 )
32 for (const path of CANONICAL_PATHS) {
33 const loc = path === '/' ? `${ORIGIN}/` : `${ORIGIN}${path}`
34 expect(xml).toContain(`<loc>${loc}</loc>`)
35 }
36 expect(xml).toContain('<lastmod>')
37 // Well-formed-ish: matching url tags.
38 expect(xml.match(/<url>/g)?.length).toBe(CANONICAL_PATHS.length)
39 expect(xml.match(/<\/url>/g)?.length).toBe(CANONICAL_PATHS.length)
40 })
41
42 it('robots.txt allows all and references the sitemap', () => {
43 const txt = robotsTxt(ORIGIN)
44 expect(txt).toContain('User-agent: *')
45 expect(txt).toContain('Allow: /')
46 expect(txt).toContain(`Sitemap: ${ORIGIN}/sitemap.xml`)
47 })
48})