Files
blog/tests/integration/articles-schema.test.ts
T
davide 847edc7397 Cap articles.content at 10000 characters, with coverage
PocketBase silently enforced its own default max on unbounded text
fields, which broke saving a real production article longer than that.
Make the limit explicit and generous enough for the content this blog
actually publishes, and add a test asserting the exact boundary.
2026-09-11 13:53:17 +02:00

38 lines
1.2 KiB
TypeScript

import { afterAll, describe, expect, it } from 'vitest'
import { startTestPocketbase } from '../support/pocketbase'
// Exercises the PocketBase collection schema directly (pb_migrations), not the
// Nitro /content/* endpoints — this is about what the CMS itself accepts.
const pb = await startTestPocketbase()
afterAll(async () => {
await pb.stop()
})
async function createArticle(content: string) {
return fetch(`${pb.url}/api/collections/articles/records`, {
method: 'POST',
headers: { Authorization: pb.token, 'Content-Type': 'application/json' },
body: JSON.stringify({
title: 'Vincolo lunghezza contenuto',
slug: 'vincolo-lunghezza-contenuto',
content,
publishedAt: '2025-01-01 00:00:00',
}),
})
}
describe('articles.content max length', () => {
it('accepts content up to 10000 characters', async () => {
const response = await createArticle('a'.repeat(10000))
expect(response.status).toBe(200)
})
it('rejects content over 10000 characters', async () => {
const response = await createArticle('a'.repeat(10001))
expect(response.status).toBe(400)
const body = await response.json()
expect(body.data.content.code).toBe('validation_max_text_constraint')
})
})