UNPKG

@spoolcms/nextjs

Version:

The beautiful headless CMS for Next.js developers

48 lines (47 loc) 2.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const seo_1 = require("../utils/seo"); describe('seo utils', () => { const env = process.env; beforeEach(() => { jest.resetModules(); process.env = { ...env }; delete process.env.NEXT_PUBLIC_SITE_URL; delete process.env.VERCEL_URL; }); afterAll(() => { process.env = env; }); test('detectSiteUrl prefers NEXT_PUBLIC_SITE_URL', () => { process.env.NEXT_PUBLIC_SITE_URL = 'https://example.com'; expect((0, seo_1.detectSiteUrl)()).toBe('https://example.com'); }); test('detectSiteUrl falls back to VERCEL_URL', () => { process.env.VERCEL_URL = 'my-app.vercel.app'; expect((0, seo_1.detectSiteUrl)()).toBe('https://my-app.vercel.app'); }); test('detectSiteUrl defaults to localhost', () => { expect((0, seo_1.detectSiteUrl)()).toBe('http://localhost:3000'); }); test('buildOgImageUrl handles string input', () => { const url = (0, seo_1.buildOgImageUrl)('https://img/og.jpg', 'Title', 'https://site'); expect(url).toBe('https://img/og.jpg'); }); test('buildOgImageUrl handles object input', () => { const url = (0, seo_1.buildOgImageUrl)({ original: 'o', small: 's', thumb: 't' }, 'Title', 'https://site'); expect(url).toBe('o'); }); test('buildOgImageUrl falls back to generated url', () => { const url = (0, seo_1.buildOgImageUrl)(undefined, 'Hello World', 'https://site'); expect(url).toBe('https://site/api/og?title=Hello%20World'); }); test('buildRobots maps noIndex', () => { expect((0, seo_1.buildRobots)(true)).toBe('noindex,nofollow'); expect((0, seo_1.buildRobots)(false)).toBe('index,follow'); expect((0, seo_1.buildRobots)()).toBe('index,follow'); }); test('canonicalFromPath joins url and path', () => { expect((0, seo_1.canonicalFromPath)('/blog/slug', 'https://site')).toBe('https://site/blog/slug'); expect((0, seo_1.canonicalFromPath)('blog/slug', 'https://site')).toBe('https://site/blog/slug'); }); });