File tree Expand file tree Collapse file tree 2 files changed +5
-2
lines changed
Expand file tree Collapse file tree 2 files changed +5
-2
lines changed Original file line number Diff line number Diff line change @@ -101,10 +101,13 @@ await test('find', async (t) => {
101101
102102await test ( 'create' , async ( ) => {
103103 const post = { title : 'new post' }
104- const res = await service . create ( POSTS , post )
104+ let res = await service . create ( POSTS , post )
105105 assert . equal ( res ?. [ 'title' ] , post . title )
106106 assert . equal ( typeof res ?. [ 'id' ] , 'string' , 'id should be a string' )
107107
108+ res = await service . create ( POSTS , { ...post , id : 'foo' } )
109+ assert . notEqual ( res ?. [ 'id' ] , 'foo' , 'user should not be able to set id' )
110+
108111 assert . equal ( await service . create ( UNKNOWN_RESOURCE , post ) , undefined )
109112} )
110113
Original file line number Diff line number Diff line change @@ -146,7 +146,7 @@ export class Service {
146146 const items = this . #get( name )
147147 if ( items === undefined || ! Array . isArray ( items ) ) return
148148
149- const item = { id : randomId ( ) , ... data }
149+ const item = { ... data , id : randomId ( ) }
150150 items . push ( item )
151151
152152 await this . #db. write ( )
You can’t perform that action at this time.
0 commit comments