import { describe, expect, it } from 'vitest';
import { withActuateCMS } from '../next.js';
function createFullConfig() {
    return {
        platform: {
            database: { provider: 'postgres' },
            storage: { provider: 'local' },
        },
        auth: {
            providers: [],
            credentials: { enabled: true },
        },
        admin: {
            path: '/dashboard',
        },
        collections: {
            pages: {
                slug: 'pages',
                labels: { singular: 'Page', plural: 'Pages' },
                fields: {
                    title: { label: 'Title', type: 'text' },
                },
            },
        },
        globals: {
            'site-settings': {
                slug: 'site-settings',
                label: 'Site Settings',
                fields: {
                    siteName: { label: 'Site Name', type: 'text' },
                },
            },
        },
        plugins: [
            {
                name: 'server-only-plugin',
                init(config) {
                    return config;
                },
            },
        ],
    };
}
describe('withActuateCMS', () => {
    it('accepts a full ActuateCMSConfig and derives only safe env values', () => {
        const config = withActuateCMS(createFullConfig(), {
            env: { EXISTING: 'true' },
        });
        expect(config.env).toEqual({
            EXISTING: 'true',
            ACTUATE_ADMIN_PATH: '/dashboard',
            ACTUATE_COLLECTIONS: 'pages',
            ACTUATE_GLOBALS: 'site-settings',
        });
    });
    it('preserves existing Next.js externals and transpile package settings', () => {
        const config = withActuateCMS(createFullConfig(), {
            serverExternalPackages: ['custom-external'],
            transpilePackages: ['custom-transpile', '@actuate-media/cms-core'],
        });
        expect(config.serverExternalPackages).toContain('custom-external');
        expect(config.serverExternalPackages).toContain('@prisma/client');
        expect(config.transpilePackages).toContain('custom-transpile');
        expect(config.transpilePackages).not.toContain('@actuate-media/cms-core');
    });
    it('deep-merges existing server action settings', () => {
        const config = withActuateCMS(createFullConfig(), {
            experimental: {
                serverActions: {
                    bodySizeLimit: '4mb',
                    allowedOrigins: ['cms.example.com'],
                },
            },
        });
        expect(config.experimental).toEqual({
            serverActions: {
                bodySizeLimit: '4mb',
                allowedOrigins: ['cms.example.com'],
            },
        });
    });
    it('adds the Vercel Blob image remote pattern once', () => {
        const config = withActuateCMS(createFullConfig(), {
            images: {
                remotePatterns: [{ protocol: 'https', hostname: 'images.example.com' }],
            },
        });
        expect(config.images).toEqual({
            remotePatterns: [
                { protocol: 'https', hostname: 'images.example.com' },
                { protocol: 'https', hostname: '**.blob.vercel-storage.com' },
            ],
        });
        const secondPass = withActuateCMS(createFullConfig(), config);
        expect(secondPass.images.remotePatterns).toEqual([
            { protocol: 'https', hostname: 'images.example.com' },
            { protocol: 'https', hostname: '**.blob.vercel-storage.com' },
        ]);
    });
});
//# sourceMappingURL=next.test.js.map