@@ -3183,6 +3183,7 @@ describe('REST server tests', () => {
31833183 model Post {
31843184 id Int @id @default(autoincrement())
31853185 title String
3186+ short_title String @unique()
31863187 author User? @relation(fields: [authorId], references: [id])
31873188 authorId Int?
31883189 }
@@ -3195,16 +3196,22 @@ describe('REST server tests', () => {
31953196 endpoint : 'http://localhost/api' ,
31963197 externalIdMapping : {
31973198 User : 'name_source' ,
3199+ Post : 'short_title' ,
3200+ Image : 'image_short_title' ,
3201+ Comment : 'short_title_post' ,
31983202 } ,
31993203 } ) ;
32003204 handler = ( args ) => _handler . handleRequest ( { ...args , url : new URL ( `http://localhost/${ args . path } ` ) } ) ;
3201- } ) ;
32023205
3203- it ( 'works with id mapping' , async ( ) => {
32043206 await client . user . create ( {
32053207 data : { id : 1 , name : 'User1' , source : 'a' } ,
32063208 } ) ;
3209+ await client . post . create ( {
3210+ data : { id : 2 , title : 'Some title' , short_title : 'post-title-2' , authorId : 1 } ,
3211+ } ) ;
3212+ } ) ;
32073213
3214+ it ( 'works with id mapping' , async ( ) => {
32083215 // user is no longer exposed using the `id` field
32093216 let r = await handler ( {
32103217 method : 'get' ,
@@ -3229,13 +3236,13 @@ describe('REST server tests', () => {
32293236 expect ( r . body . data . attributes . name ) . toBe ( 'User1' ) ;
32303237
32313238 await client . post . create ( {
3232- data : { id : 1 , title : 'Title1' , authorId : 1 } ,
3239+ data : { id : 1 , title : 'Title1' , short_title : 'post-title-1' , authorId : 1 } ,
32333240 } ) ;
32343241
32353242 // post is exposed using the `id` field
32363243 r = await handler ( {
32373244 method : 'get' ,
3238- path : '/post/1' ,
3245+ path : '/post/post-title- 1' ,
32393246 query : { include : 'author' } ,
32403247 client,
32413248 } ) ;
0 commit comments