fix: default page content format to json (#2596)

This commit is contained in:
Philip Okugbe 2026-10-21 20:48:49 +01:00 committed by GitHub
parent 611452112d
commit 9250ca8305
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 35 additions and 2 deletions

View file

@ -0,0 +1,16 @@
import { plainToInstance } from 'class-transformer';
import { validate } from 'class-validator';
import { CreatePageDto } from './create-page.dto';
describe('CreatePageDto', () => {
it('defaults format to json when content is sent without one', async () => {
const dto = plainToInstance(CreatePageDto, {
spaceId: '0199f2a4-8c1e-7b3a-9d4e-2f6a8b1c3d5e',
content: { type: 'doc', content: [] },
});
const errors = await validate(dto);
expect(errors.flatMap((e) => Object.keys(e.constraints ?? {}))).toEqual([]);
expect(dto.format).toBe('json');
});
});

View file

@ -32,5 +32,5 @@ export class CreatePageDto {
@ValidateIf((o) => o.content !== undefined)
@Transform(({ value }) => value?.toLowerCase() ?? 'json')
@IsIn(['json', 'markdown', 'html'])
format?: ContentFormat;
format?: ContentFormat = 'json';
}

View file

@ -0,0 +1,17 @@
import { plainToInstance } from 'class-transformer';
import { validate } from 'class-validator';
import { UpdatePageDto } from './update-page.dto';
describe('UpdatePageDto', () => {
it('defaults format to json when content is sent without one', async () => {
const dto = plainToInstance(UpdatePageDto, {
pageId: '0199f2a4-8c1e-7b3a-9d4e-2f6a8b1c3d5e',
content: { type: 'doc', content: [] },
operation: 'replace',
});
const errors = await validate(dto);
expect(errors.flatMap((e) => Object.keys(e.constraints ?? {}))).toEqual([]);
expect(dto.format).toBe('json');
});
});

View file

@ -20,5 +20,5 @@ export class UpdatePageDto extends PartialType(CreatePageDto) {
@ValidateIf((o) => o.content !== undefined)
@Transform(({ value }) => value?.toLowerCase() ?? 'json')
@IsIn(['json', 'markdown', 'html'])
format?: ContentFormat;
format?: ContentFormat = 'json';
}