feat: 新增 news 内容集合与 Zod schema(含单测)
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { newsSchema } from '../src/content/schemas';
|
||||
|
||||
describe('newsSchema', () => {
|
||||
it('accepts valid frontmatter and coerces date', () => {
|
||||
const parsed = newsSchema.parse({
|
||||
title: '官网基座启动',
|
||||
date: '2026-07-23',
|
||||
category: '公告',
|
||||
});
|
||||
expect(parsed.title).toBe('官网基座启动');
|
||||
expect(parsed.date).toEqual(new Date('2026-07-23'));
|
||||
expect(parsed.category).toBe('公告');
|
||||
});
|
||||
|
||||
it('defaults category to 未分类', () => {
|
||||
const parsed = newsSchema.parse({ title: '测试', date: '2026-07-23' });
|
||||
expect(parsed.category).toBe('未分类');
|
||||
});
|
||||
|
||||
it('rejects missing title', () => {
|
||||
expect(() => newsSchema.parse({ date: '2026-07-23' })).toThrow();
|
||||
});
|
||||
|
||||
it('rejects missing date', () => {
|
||||
expect(() => newsSchema.parse({ title: '测试' })).toThrow();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user