feat(content): guid in resolve/componenti + GET /api/admin/content/[tag]

This commit is contained in:
2026-07-05 21:56:53 +02:00
parent c3267c9be2
commit 5ce10da9bd
6 changed files with 51 additions and 15 deletions
+13
View File
@@ -35,3 +35,16 @@ describe('applyContentUpdate', () => {
expect(applyContentUpdate(db, imgTag, { value: 'x' }, 'a')).toMatchObject({ ok: false, status: 400 });
});
});
describe('GET /api/admin/content/[tag]', () => {
it('GET /api/admin/content/[tag] ritorna tag, guid, type, value, styleOptions', async () => {
const { GET } = await import('../src/pages/api/admin/content/[tag]');
const res = await GET({ params: { tag: 'home.hero.cta' } } as any);
expect(res.status).toBe(200);
const body = await res.json();
expect(body.tag).toBe('home.hero.cta');
expect(typeof body.guid).toBe('string');
expect(body.type).toBeDefined();
expect(Array.isArray(body.styleOptions)).toBe(true);
});
});
+7 -1
View File
@@ -2,7 +2,7 @@ import { describe, it, expect, beforeEach } from 'vitest';
import type Database from 'better-sqlite3';
import { createDb } from '../src/lib/db';
import { contentSeed } from '../src/data/content-seed';
import { makeContentStore, syncSeed } from '../src/lib/content';
import { makeContentStore, syncSeed, resolveContent } from '../src/lib/content';
let db: Database.Database;
beforeEach(() => { db = createDb(':memory:'); });
@@ -58,4 +58,10 @@ describe('content store', () => {
store.invalidate();
expect(store.resolve(contentSeed[0].tag).classes).toBe('');
});
it('resolveContent restituisce il guid dal DB', () => {
const r = resolveContent('home.hero.cta');
expect(typeof r.guid).toBe('string');
expect(r.guid.length).toBeGreaterThan(10);
});
});