- Moved CommonSchemas from src/schema/schema.ts to src/test-utils/schemas.ts - Updated all test files to import CommonSchemas from the new location - Fixed the Document schema to match test expectations by making the author field required - Added additional fields to the Document schema to match the original implementation - Ensured all tests pass with the new implementation Addresses PR feedback that CommonSchemas is only used in tests and should be moved to test files.
60 lines
2.1 KiB
TypeScript
60 lines
2.1 KiB
TypeScript
import { SchemaBuilder } from '../../src/schema';
|
|
|
|
/**
|
|
* Common schemas used for testing purposes.
|
|
* These schemas are not part of the main application code
|
|
* and are only used in test files.
|
|
*/
|
|
export const CommonSchemas = {
|
|
// User schema with friends references
|
|
User: () => SchemaBuilder
|
|
.create('user')
|
|
.name('User')
|
|
.description('A user entity with profile information')
|
|
.property('name', { type: 'primitive', primitiveType: 'string', required: true })
|
|
.property('email', { type: 'primitive', primitiveType: 'string' })
|
|
.property('age', { type: 'primitive', primitiveType: 'number' })
|
|
.property('active', { type: 'primitive', primitiveType: 'boolean' })
|
|
.property('friends', {
|
|
type: 'array',
|
|
itemSchema: {
|
|
type: 'reference',
|
|
targetSchema: 'user-summary',
|
|
maxDepth: 2
|
|
}
|
|
})
|
|
.required('name')
|
|
.build(),
|
|
|
|
// User summary schema for references to prevent infinite recursion
|
|
UserSummary: () => SchemaBuilder
|
|
.create('user-summary')
|
|
.name('User Summary')
|
|
.description('Abbreviated user information for references')
|
|
.property('name', { type: 'primitive', primitiveType: 'string', required: true })
|
|
.property('email', { type: 'primitive', primitiveType: 'string' })
|
|
.build(),
|
|
|
|
// Document schema
|
|
Document: () => SchemaBuilder
|
|
.create('document')
|
|
.name('Document')
|
|
.description('A document with title, content, and author')
|
|
.property('title', { type: 'primitive', primitiveType: 'string', required: true })
|
|
.property('content', { type: 'primitive', primitiveType: 'string' })
|
|
.property('author', {
|
|
type: 'reference',
|
|
targetSchema: 'user-summary',
|
|
maxDepth: 1,
|
|
required: true
|
|
})
|
|
.property('tags', {
|
|
type: 'array',
|
|
itemSchema: { type: 'primitive', primitiveType: 'string' }
|
|
})
|
|
.property('created', { type: 'primitive', primitiveType: 'number', required: true })
|
|
.property('published', { type: 'primitive', primitiveType: 'boolean' })
|
|
.required('title', 'author', 'created')
|
|
.build()
|
|
} as const;
|