1+ import { afterEach , beforeEach , describe , expect , it } from 'vitest' ;
2+ import { ZenStackValidationTester , createTestDir , expectValidationSuccess , expectValidationFailure , baseSchema } from './test-utils' ;
3+
4+ describe ( 'Basic Models Validation' , ( ) => {
5+ let tester : ZenStackValidationTester ;
6+ let tempDir : string ;
7+
8+ beforeEach ( ( ) => {
9+ tempDir = createTestDir ( ) ;
10+ tester = new ZenStackValidationTester ( tempDir ) ;
11+ } ) ;
12+
13+ afterEach ( ( ) => {
14+ tester . cleanup ( ) ;
15+ } ) ;
16+
17+ it ( 'should accept valid basic model with id field' , ( ) => {
18+ const result = tester . runValidation ( `
19+ ${ baseSchema }
20+
21+ model User {
22+ id Int @id @default(autoincrement())
23+ email String @unique
24+ name String?
25+ }
26+ ` ) ;
27+
28+ expectValidationSuccess ( result ) ;
29+ } ) ;
30+
31+ it ( 'should reject model without any unique criterion' , ( ) => {
32+ const result = tester . runValidation ( `
33+ ${ baseSchema }
34+
35+ model User {
36+ email String
37+ name String?
38+ }
39+ ` ) ;
40+
41+ expectValidationFailure ( result ) ;
42+ } ) ;
43+
44+ it ( 'should reject model with multiple @id fields' , ( ) => {
45+ const result = tester . runValidation ( `
46+ ${ baseSchema }
47+
48+ model User {
49+ id Int @id @default(autoincrement())
50+ email String @id
51+ name String?
52+ }
53+ ` ) ;
54+
55+ expectValidationFailure ( result ) ;
56+ } ) ;
57+
58+ it ( 'should reject model with both @id field and @@id' , ( ) => {
59+ const result = tester . runValidation ( `
60+ ${ baseSchema }
61+
62+ model User {
63+ id Int @id @default(autoincrement())
64+ firstName String
65+ lastName String
66+
67+ @@id([firstName, lastName])
68+ }
69+ ` ) ;
70+
71+ expectValidationFailure ( result ) ;
72+ } ) ;
73+
74+ it ( 'should reject optional ID field' , ( ) => {
75+ const result = tester . runValidation ( `
76+ ${ baseSchema }
77+
78+ model User {
79+ id Int? @id @default(autoincrement())
80+ email String @unique
81+ }
82+ ` ) ;
83+
84+ expectValidationFailure ( result ) ;
85+ } ) ;
86+
87+ it ( 'should reject array ID field' , ( ) => {
88+ const result = tester . runValidation ( `
89+ ${ baseSchema }
90+
91+ model User {
92+ id Int[] @id
93+ email String @unique
94+ }
95+ ` ) ;
96+
97+ expectValidationFailure ( result ) ;
98+ } ) ;
99+ } ) ;
0 commit comments