@@ -10,7 +10,7 @@ describe('Relation Splitting Generation', () => {
1010 beforeAll ( async ( ) => {
1111 // Build the generator first
1212 await execAsync ( 'npm run build' ) ;
13-
13+
1414 // Generate models for full-features schema
1515 const schemaPath = path . resolve ( __dirname , 'schemas/full-features.prisma' ) ;
1616 await execAsync ( `npx prisma generate --schema="${ schemaPath } "` ) ;
@@ -19,50 +19,66 @@ describe('Relation Splitting Generation', () => {
1919 it ( 'should generate separate base and relation classes' , ( ) => {
2020 const outputPath = path . resolve ( __dirname , 'generated/full-features' ) ;
2121 const modelsDir = path . join ( outputPath , 'models' ) ;
22-
22+
2323 // Check that all expected files are generated
24- expect ( ( ) => readFileSync ( path . join ( modelsDir , 'UserBase.model.ts' ) ) ) . not . toThrow ( ) ;
25- expect ( ( ) => readFileSync ( path . join ( modelsDir , 'UserRelations.model.ts' ) ) ) . not . toThrow ( ) ;
26- expect ( ( ) => readFileSync ( path . join ( modelsDir , 'User.model.ts' ) ) ) . not . toThrow ( ) ;
27-
28- expect ( ( ) => readFileSync ( path . join ( modelsDir , 'PostBase.model.ts' ) ) ) . not . toThrow ( ) ;
29- expect ( ( ) => readFileSync ( path . join ( modelsDir , 'PostRelations.model.ts' ) ) ) . not . toThrow ( ) ;
30- expect ( ( ) => readFileSync ( path . join ( modelsDir , 'Post.model.ts' ) ) ) . not . toThrow ( ) ;
24+ expect ( ( ) =>
25+ readFileSync ( path . join ( modelsDir , 'UserBase.model.ts' ) ) ,
26+ ) . not . toThrow ( ) ;
27+ expect ( ( ) =>
28+ readFileSync ( path . join ( modelsDir , 'UserRelations.model.ts' ) ) ,
29+ ) . not . toThrow ( ) ;
30+ expect ( ( ) =>
31+ readFileSync ( path . join ( modelsDir , 'User.model.ts' ) ) ,
32+ ) . not . toThrow ( ) ;
33+
34+ expect ( ( ) =>
35+ readFileSync ( path . join ( modelsDir , 'PostBase.model.ts' ) ) ,
36+ ) . not . toThrow ( ) ;
37+ expect ( ( ) =>
38+ readFileSync ( path . join ( modelsDir , 'PostRelations.model.ts' ) ) ,
39+ ) . not . toThrow ( ) ;
40+ expect ( ( ) =>
41+ readFileSync ( path . join ( modelsDir , 'Post.model.ts' ) ) ,
42+ ) . not . toThrow ( ) ;
3143 } ) ;
3244
3345 it ( 'should generate UserBase with only non-relation fields' , ( ) => {
3446 const outputPath = path . resolve ( __dirname , 'generated/full-features' ) ;
3547 const userBasePath = path . join ( outputPath , 'models' , 'UserBase.model.ts' ) ;
3648 const userBase = readFileSync ( userBasePath , 'utf-8' ) ;
37-
49+
3850 // Should contain scalar fields
3951 expect ( userBase ) . toContain ( 'id!: number' ) ;
4052 expect ( userBase ) . toContain ( 'email!: string' ) ;
4153 expect ( userBase ) . toContain ( 'name?: string | null' ) ;
42-
54+
4355 // Should NOT contain relation fields
4456 expect ( userBase ) . not . toContain ( 'posts' ) ;
45-
57+
4658 // Should have both class-validator and Swagger decorators
4759 expect ( userBase ) . toContain ( '@IsInt()' ) ;
4860 expect ( userBase ) . toContain ( '@ApiProperty({' ) ;
4961 } ) ;
5062
5163 it ( 'should generate UserRelations with only relation fields' , ( ) => {
5264 const outputPath = path . resolve ( __dirname , 'generated/full-features' ) ;
53- const userRelationsPath = path . join ( outputPath , 'models' , 'UserRelations.model.ts' ) ;
65+ const userRelationsPath = path . join (
66+ outputPath ,
67+ 'models' ,
68+ 'UserRelations.model.ts' ,
69+ ) ;
5470 const userRelations = readFileSync ( userRelationsPath , 'utf-8' ) ;
55-
71+
5672 // Should contain relation fields
5773 expect ( userRelations ) . toContain ( 'posts!: Post[]' ) ;
58-
74+
5975 // Should NOT contain scalar fields
6076 expect ( userRelations ) . not . toContain ( 'id!: number' ) ;
6177 expect ( userRelations ) . not . toContain ( 'email!: string' ) ;
62-
78+
6379 // Should import related models
6480 expect ( userRelations ) . toContain ( 'import { Post } from "./"' ) ;
65-
81+
6682 // Should have decorators for relations
6783 expect ( userRelations ) . toContain ( '@ApiProperty({ isArray: true })' ) ;
6884 } ) ;
@@ -71,16 +87,16 @@ describe('Relation Splitting Generation', () => {
7187 const outputPath = path . resolve ( __dirname , 'generated/full-features' ) ;
7288 const userPath = path . join ( outputPath , 'models' , 'User.model.ts' ) ;
7389 const user = readFileSync ( userPath , 'utf-8' ) ;
74-
90+
7591 // Should extend base class
7692 expect ( user ) . toContain ( 'extends UserBase' ) ;
77-
93+
7894 // Should import base class
7995 expect ( user ) . toContain ( 'import { UserBase } from "./UserBase.model"' ) ;
80-
96+
8197 // Should import relation types
8298 expect ( user ) . toContain ( 'import { Post } from "./"' ) ;
83-
99+
84100 // Should include relation properties
85101 expect ( user ) . toContain ( 'posts!: Post[]' ) ;
86102 } ) ;
@@ -89,13 +105,13 @@ describe('Relation Splitting Generation', () => {
89105 const outputPath = path . resolve ( __dirname , 'generated/full-features' ) ;
90106 const postBasePath = path . join ( outputPath , 'models' , 'PostBase.model.ts' ) ;
91107 const postBase = readFileSync ( postBasePath , 'utf-8' ) ;
92-
108+
93109 // Should contain all scalar fields including foreign key
94110 expect ( postBase ) . toContain ( 'id!: number' ) ;
95111 expect ( postBase ) . toContain ( 'title!: string' ) ;
96112 expect ( postBase ) . toContain ( 'authorId?: number | null' ) ;
97113 expect ( postBase ) . toContain ( 'rating!: number' ) ;
98-
114+
99115 // Should NOT contain relation fields (but should contain foreign key)
100116 expect ( postBase ) . not . toContain ( 'author?: User' ) ;
101117 expect ( postBase ) . not . toContain ( 'import { User } from "./"' ) ;
@@ -106,8 +122,8 @@ describe('Relation Splitting Generation', () => {
106122 const outputPath = path . resolve ( __dirname , 'generated/full-features' ) ;
107123 const userPath = path . join ( outputPath , 'models' , 'User.model.ts' ) ;
108124 const user = readFileSync ( userPath , 'utf-8' ) ;
109-
125+
110126 // Should be valid TypeScript
111127 expect ( user ) . toContain ( 'export class User extends UserBase' ) ;
112128 } ) ;
113- } ) ;
129+ } ) ;
0 commit comments