feat(contracts): UniversalRow 契约 v1 冻结 + 守卫 + 测试
Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { UNIVERSAL_ROW_VERSION, isUniversalRow, type UniversalRow } from '../src/index.js'
|
||||
|
||||
const valid: UniversalRow = {
|
||||
sourceType: 'wp:post', sourceId: '101', status: 'publish', locale: 'en',
|
||||
sourceUrl: 'https://fixture.example/news/fixture-news-a.html',
|
||||
slug: 'fixture-news-a', title: 'Fixture News A', excerpt: 'Fixture excerpt A',
|
||||
bodyHtml: '<p>Body</p>', publishedAt: '2026-10-05T09:00:00Z', modifiedAt: '2026-10-06T10:00:00Z',
|
||||
taxonomyRefs: [{ taxonomy: 'category', sourceTermId: '31' }],
|
||||
attachmentRefs: [{ role: 'featured', sourceId: '201' }],
|
||||
seo: { title: 'Fixture SEO Title A' },
|
||||
knownFields: {}, extras: { custom_meta: 'x' },
|
||||
rawLocation: 'wxr://item/3',
|
||||
}
|
||||
|
||||
describe('UniversalRow 契约', () => {
|
||||
it('版本号为 1(冻结,变更须升版并保留转换测试)', () => {
|
||||
expect(UNIVERSAL_ROW_VERSION).toBe(1)
|
||||
})
|
||||
it('合法对象通过守卫', () => {
|
||||
expect(isUniversalRow(valid)).toBe(true)
|
||||
})
|
||||
it('缺必填字段拒绝', () => {
|
||||
const { sourceId: _omit, ...bad } = valid
|
||||
expect(isUniversalRow(bad)).toBe(false)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user