35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import { randomUUID } from 'node:crypto';
|
|
import { blogCreateSchema, blogPatchSchema } from '../src/blog/blog.schemas';
|
|
import { nextBlogVersion } from '../src/blog/blog-lookup';
|
|
|
|
it('accepts multiline plain text, validates editorial commands and bounds revisions', () => {
|
|
const input = {
|
|
slug: 'candle-care',
|
|
title: 'Candle care',
|
|
summary: 'Simple care.',
|
|
body: 'First line.\nSecond line.',
|
|
idempotencyKey: randomUUID(),
|
|
};
|
|
expect(blogCreateSchema.safeParse(input).success).toBe(true);
|
|
for (const fields of [
|
|
{ body: '<img src=x>' },
|
|
{ body: '\u0000' },
|
|
{ body: ' ' },
|
|
{ title: ' ' },
|
|
{ summary: ' ' },
|
|
{ slug: '../private' },
|
|
{ body: 'x'.repeat(20001) },
|
|
{ state: 'PUBLISHED' },
|
|
])
|
|
expect(blogCreateSchema.safeParse({ ...input, ...fields }).success).toBe(
|
|
false,
|
|
);
|
|
expect(blogPatchSchema.safeParse({ version: 0 }).success).toBe(false);
|
|
expect(
|
|
blogPatchSchema.safeParse({ version: 0, body: input.body }).success,
|
|
).toBe(true);
|
|
expect(nextBlogVersion(0)).toBe(1);
|
|
expect(nextBlogVersion(2147483646)).toBe(2147483647);
|
|
expect(() => nextBlogVersion(2147483647)).toThrow();
|
|
});
|