import type { MetadataRoute } from '../../../../lib/metadata/types/metadata-interface' import { resolveRobots, resolveSitemap } from './resolve-route-data' describe('resolveRouteData', () => { describe('resolveRobots', () => { it('should resolve robots.txt', () => { const data = { host: 'https://example.com', sitemap: 'https://example.com/sitemap.xml', rules: [ { userAgent: 'Googlebot', allow: '/', disallow: '/admin', crawlDelay: 2, }, ], } const content = resolveRobots(data) expect(content).toMatchInlineSnapshot(` "User-Agent: Googlebot Allow: / Disallow: /admin Crawl-delay: 2 Host: https://example.com Sitemap: https://example.com/sitemap.xml " `) }) it('should error with ts when specify both wildcard userAgent and specific userAgent', () => { const data1: MetadataRoute.Robots = { rules: [ // @ts-expect-error userAgent is required for Array { allow: '/', }, { userAgent: 'Googlebot', allow: ['/bot', '/bot2'], }, ], } const data2: MetadataRoute.Robots = { rules: { // Can skip userAgent for single Robots allow: '/', }, } const data3: MetadataRoute.Robots = { rules: { allow: '/' }, } expect(resolveRobots(data1)).toMatchInlineSnapshot(` "User-Agent: * Allow: / User-Agent: Googlebot Allow: /bot Allow: /bot2 " `) resolveRobots(data2) expect(resolveRobots(data3)).toMatchInlineSnapshot(` "User-Agent: * Allow: / " `) }) }) describe('resolveSitemap', () => { it('should resolve sitemap.xml', () => { expect( resolveSitemap([ { url: 'https://example.com', lastModified: '2021-01-01', changeFrequency: 'weekly', priority: 0.5, }, ]) ).toMatchInlineSnapshot(` " https://example.com 2021-01-01 weekly 0.5 " `) }) it('should resolve sitemap.xml with alternates', () => { expect( resolveSitemap([ { url: 'https://example.com', lastModified: '2021-01-01', alternates: { languages: { es: 'https://example.com/es', de: 'https://example.com/de', }, }, }, ]) ).toMatchInlineSnapshot(` " https://example.com 2021-01-01 " `) }) it('should resolve sitemap.xml with images', () => { expect( resolveSitemap([ { url: 'https://example.com', lastModified: '2021-01-01', changeFrequency: 'weekly', priority: 0.5, images: ['https://example.com/image.jpg'], }, ]) ).toMatchInlineSnapshot(` " https://example.com https://example.com/image.jpg 2021-01-01 weekly 0.5 " `) }) it('should resolve sitemap.xml with videos', () => { expect( resolveSitemap([ { url: 'https://example.com', lastModified: '2021-01-01', changeFrequency: 'weekly', priority: 0.5, videos: [ { title: 'example', thumbnail_loc: 'https://example.com/image.jpg', description: 'this is the description', content_loc: 'http://streamserver.example.com/video123.mp4', player_loc: 'https://www.example.com/videoplayer.php?video=123', duration: 2, view_count: 50, tag: 'summer', rating: 4, expiration_date: '2025-09-16', publication_date: '2024-09-16', family_friendly: 'yes', requires_subscription: 'no', live: 'no', restriction: { relationship: 'allow', content: 'IE GB US CA', }, platform: { relationship: 'allow', content: 'web', }, uploader: { info: 'https://www.example.com/users/grillymcgrillerson', content: 'GrillyMcGrillerson', }, }, ], }, ]) ).toMatchInlineSnapshot(` " https://example.com example https://example.com/image.jpg this is the description http://streamserver.example.com/video123.mp4 https://www.example.com/videoplayer.php?video=123 2 50 summer 4 2025-09-16 2024-09-16 yes no no IE GB US CA web GrillyMcGrillerson 2021-01-01 weekly 0.5 " `) }) }) })