@@ -486,28 +486,30 @@ describe('Auth integration tests:', () => {
486486 avatar : '' ,
487487 providerData : { id : 'google-fake-id-999' } ,
488488 } ;
489- const mockRes = { status ( ) { return this ; } , json ( ) { } , cookie ( ) { return this ; } } ;
490- const result = await AuthController . checkOAuthUserProfile ( profil , 'id' , 'google' , mockRes ) ;
489+ const result = await AuthController . checkOAuthUserProfile ( profil , 'id' , 'google' ) ;
491490 expect ( result ) . toBeDefined ( ) ;
492491 expect ( result . id ) . toBeDefined ( ) ;
493492 expect ( result . email ) . toBe ( profil . email ) ;
494493 oauthUsers . push ( result ) ;
495494 } ) ;
496495
497- test ( 'should return 422 when checkOAuthUserProfile receives an invalid profile' , async ( ) => {
496+ test ( 'should throw validation AppError when checkOAuthUserProfile receives an invalid profile' , async ( ) => {
498497 const invalidProfil = {
499498 firstName : '' , // invalid — fails min(1)
500499 lastName : 'Test' ,
501500 email : 'invalid-oauth@test.com' ,
502501 avatar : '' ,
503502 providerData : { id : 'google-invalid-999' } ,
504503 } ;
505- const errors = [ ] ;
506- const mockRes = { status ( ) { return this ; } , json ( body ) { errors . push ( body ) ; } , cookie ( ) { return this ; } } ;
507- const result = await AuthController . checkOAuthUserProfile ( invalidProfil , 'id' , 'google' , mockRes ) ;
508- expect ( result ) . toBeDefined ( ) ;
509- expect ( result . type ) . toBe ( 'error' ) ;
510- expect ( errors [ 0 ] ?. message ) . toBe ( 'Schema validation error' ) ;
504+ await expect (
505+ AuthController . checkOAuthUserProfile ( invalidProfil , 'id' , 'google' ) ,
506+ ) . rejects . toMatchObject ( {
507+ message : 'Schema validation error' ,
508+ code : 'VALIDATION_ERROR' ,
509+ details : {
510+ message : expect . any ( String ) ,
511+ } ,
512+ } ) ;
511513 } ) ;
512514
513515 test ( 'should throw AppError when create fails inside checkOAuthUserProfile' , async ( ) => {
@@ -518,10 +520,9 @@ describe('Auth integration tests:', () => {
518520 avatar : '' ,
519521 providerData : { id : 'google-err-000' } ,
520522 } ;
521- const mockRes = { status ( ) { return this ; } , json ( ) { } , cookie ( ) { return this ; } } ;
522523 const createSpy = jest . spyOn ( UserService , 'create' ) . mockRejectedValueOnce ( new Error ( 'DB error' ) ) ;
523524 await expect (
524- AuthController . checkOAuthUserProfile ( profil , 'id' , 'google' , mockRes ) ,
525+ AuthController . checkOAuthUserProfile ( profil , 'id' , 'google' ) ,
525526 ) . rejects . toThrow ( 'oAuth' ) ;
526527 createSpy . mockRestore ( ) ;
527528 } ) ;
@@ -590,9 +591,8 @@ describe('Auth integration tests:', () => {
590591 avatar : '' ,
591592 providerData : { id : 'google-find-id-777' } ,
592593 } ;
593- const mockRes = { status ( ) { return this ; } , json ( ) { } , cookie ( ) { return this ; } } ;
594594 // Second call — should find the existing user (search.length === 1 branch)
595- const found = await AuthController . checkOAuthUserProfile ( profil , 'id' , 'google' , mockRes ) ;
595+ const found = await AuthController . checkOAuthUserProfile ( profil , 'id' , 'google' ) ;
596596 expect ( found ) . toBeDefined ( ) ;
597597
598598 // cleanup
0 commit comments