fix: default page content format to json (#2596)
This commit is contained in:
parent
611452112d
commit
9250ca8305
4 changed files with 35 additions and 2 deletions
16
apps/server/src/core/page/dto/create-page.dto.spec.ts
Normal file
16
apps/server/src/core/page/dto/create-page.dto.spec.ts
Normal 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');
|
||||
});
|
||||
});
|
||||
|
|
@ -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';
|
||||
}
|
||||
|
|
|
|||
17
apps/server/src/core/page/dto/update-page.dto.spec.ts
Normal file
17
apps/server/src/core/page/dto/update-page.dto.spec.ts
Normal 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');
|
||||
});
|
||||
});
|
||||
|
|
@ -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';
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue