import { describe, expect, it } from 'vitest';
import { applyStructuredDataFieldsToData, resolveEffectiveSchemaType, syncSchemaTypeFields, } from '../../seo/schema-sync.js';
const pagesCol = { slug: 'pages', type: 'page', fields: {} };
const faqCol = {
    slug: 'faq',
    type: 'page',
    fields: {},
    seo: { defaultSchemaType: 'FAQPage' },
};
describe('seo/schema-sync', () => {
    it('defaults pages collection to WebPage when no explicit type is set', () => {
        expect(resolveEffectiveSchemaType({
            collection: 'pages',
            data: { title: 'Home' },
            collectionDef: pagesCol,
        })).toBe('WebPage');
    });
    it('respects collection seo.defaultSchemaType', () => {
        expect(resolveEffectiveSchemaType({
            collection: 'faq',
            data: {},
            collectionDef: faqCol,
        })).toBe('FAQPage');
    });
    it('prefers explicit structuredDataType on the document', () => {
        expect(resolveEffectiveSchemaType({
            collection: 'pages',
            data: { structuredDataType: 'Article' },
            collectionDef: pagesCol,
        })).toBe('Article');
    });
    it('reads schema type from stored JSON-LD @graph', () => {
        expect(resolveEffectiveSchemaType({
            collection: 'pages',
            data: {},
            structuredData: {
                '@context': 'https://schema.org',
                '@graph': [{ '@type': 'WebSite' }, { '@type': 'FAQPage' }],
            },
            collectionDef: pagesCol,
        })).toBe('FAQPage');
    });
    it('stamps structuredDataType on save when missing', () => {
        const next = applyStructuredDataFieldsToData('pages', { title: 'About' }, pagesCol);
        expect(next.structuredDataType).toBe('WebPage');
        expect(next.schemaType).toBe('WebPage');
    });
    it('syncSchemaTypeFields mirrors structuredDataType to schemaType', () => {
        expect(syncSchemaTypeFields({ structuredDataType: 'FAQPage' })).toEqual({
            structuredDataType: 'FAQPage',
            schemaType: 'FAQPage',
        });
        expect(syncSchemaTypeFields({ schemaType: 'BlogPosting' })).toEqual({
            structuredDataType: 'BlogPosting',
            schemaType: 'BlogPosting',
        });
    });
});
//# sourceMappingURL=schema-sync.test.js.map