@@ -202,6 +202,37 @@ describe('User crud (e2e)', () => {
202202 . expect ( 400 ) ;
203203 } ) ;
204204
205+ it ( 'Update password for user without password' , async ( ) => {
206+ const userDoc = mockUser ( ) ;
207+ await namespaceService . upsertByKey ( userDoc . ns , {
208+ name : faker . company . name ( ) ,
209+ } ) ;
210+
211+ const user = await userService . create ( { ...userDoc , password : undefined } ) ;
212+
213+ // should set password successfully when no old password exists
214+ await request ( app . getHttpServer ( ) )
215+ . post ( `/users/${ user . id } /@updatePassword` )
216+ . send ( { newPassword : '^tR123456' } )
217+ . set ( 'Content-Type' , 'application/json' )
218+ . set ( 'x-api-key' , auth . apiKey )
219+ . set ( 'Accept' , 'application/json' )
220+ . expect ( 204 ) ;
221+
222+ // should skip old password verification when user has no password
223+ const noPasswordUser = await userService . create ( {
224+ ...mockUser ( ) ,
225+ password : undefined ,
226+ } ) ;
227+ await request ( app . getHttpServer ( ) )
228+ . post ( `/users/${ noPasswordUser . id } /@updatePassword` )
229+ . send ( { oldPassword : 'anything1@Aa' , newPassword : '^tR123456' } )
230+ . set ( 'Content-Type' , 'application/json' )
231+ . set ( 'x-api-key' , auth . apiKey )
232+ . set ( 'Accept' , 'application/json' )
233+ . expect ( 204 ) ;
234+ } ) ;
235+
205236 it ( 'Upsert user by id' , async ( ) => {
206237 const userId = `import-${ nanoid ( 10 ) } ` ;
207238 const userDoc = mockUser ( ) ;
0 commit comments