@@ -253,6 +253,66 @@ describe("user controller test", () => {
253253 } ) ;
254254 } ) ;
255255 } ) ;
256+ describe ( "getUser" , ( ) => {
257+ const getUserMock = vi . spyOn ( UserDal , "getUser" ) ;
258+ const updateEmailMock = vi . spyOn ( UserDal , "updateEmail" ) ;
259+ beforeEach ( ( ) => {
260+ getUserMock . mockReset ( ) ;
261+ updateEmailMock . mockReset ( ) ;
262+ } ) ;
263+ it ( "should update emailVerified if undefined" , async ( ) => {
264+ //GIVEN
265+ getUserMock . mockResolvedValue ( {
266+ uid,
267+ email : "old" ,
268+ } as any ) ;
269+ mockAuth . modifyToken ( { email_verified : false , email : "old" } ) ;
270+
271+ //WHEN
272+ await mockApp
273+ . get ( "/users" )
274+ . set ( "Authorization" , `Bearer ${ uid } ` )
275+ . expect ( 200 ) ;
276+
277+ //THEN
278+ expect ( updateEmailMock ) . toHaveBeenCalledWith ( uid , "old" , false ) ;
279+ } ) ;
280+ it ( "should update emailVerified if changed" , async ( ) => {
281+ //GIVEN
282+ getUserMock . mockResolvedValue ( {
283+ uid,
284+ emailVerified : false ,
285+ email : "old" ,
286+ } as any ) ;
287+ mockAuth . modifyToken ( { email_verified : true , email : "next" } ) ;
288+
289+ //WHEN
290+ await mockApp
291+ . get ( "/users" )
292+ . set ( "Authorization" , `Bearer ${ uid } ` )
293+ . expect ( 200 ) ;
294+
295+ //THEN
296+ expect ( updateEmailMock ) . toHaveBeenCalledWith ( uid , "next" , true ) ;
297+ } ) ;
298+ it ( "should not update emailVerified if not changed" , async ( ) => {
299+ //GIVEN
300+ getUserMock . mockResolvedValue ( {
301+ uid,
302+ emailVerified : false ,
303+ } as any ) ;
304+ mockAuth . modifyToken ( { email_verified : false } ) ;
305+
306+ //WHEN
307+ await mockApp
308+ . get ( "/users" )
309+ . set ( "Authorization" , `Bearer ${ uid } ` )
310+ . expect ( 200 ) ;
311+
312+ //THEN
313+ expect ( updateEmailMock ) . not . toHaveBeenCalled ( ) ;
314+ } ) ;
315+ } ) ;
256316 describe ( "sendVerificationEmail" , ( ) => {
257317 const adminGetUserMock = vi . fn ( ) ;
258318 const adminGenerateVerificationLinkMock = vi . fn ( ) ;
0 commit comments