@@ -21,6 +21,7 @@ vi.mock("../../../src/modules/auth/auth.service", () => ({
2121const mockCredentialsService = vi . hoisted ( ( ) => ( {
2222 register : vi . fn ( ) ,
2323 login : vi . fn ( ) ,
24+ findById : vi . fn ( ) , // ← fix: adicionado
2425} ) ) ;
2526
2627vi . mock ( "../../../src/modules/auth/credentials.service" , ( ) => ( {
@@ -109,6 +110,8 @@ describe("Integration - Auth Routes", () => {
109110 session : { userId : fixtureUser . id } ,
110111 } ) ;
111112
113+ mockCredentialsService . findById . mockResolvedValue ( fixtureUser ) ;
114+
112115 app = createJobsApiApp ( ) ;
113116 } ) ;
114117
@@ -252,10 +255,7 @@ describe("Integration - Auth Routes", () => {
252255 . get ( `${ BASE } /twitter/callback?code=abc&state=valid-state-abc123` )
253256 . expect ( 400 ) ;
254257
255- expect ( res . body ) . toHaveProperty (
256- "error" ,
257- "Parâmetros de callback inválidos" ,
258- ) ;
258+ expect ( res . body ) . toHaveProperty ( "error" , "Parâmetros de callback inválidos" ) ;
259259 } ) ;
260260
261261 it ( "retorna 400 quando code esta ausente (ZodError)" , async ( ) => {
@@ -288,10 +288,7 @@ describe("Integration - Auth Routes", () => {
288288
289289 describe ( "POST /register" , ( ) => {
290290 it ( "cria usuario e retorna 201" , async ( ) => {
291- // CredentialsController usa req.session — injetado pelo withSession mock
292- vi . mocked ( getIronSession ) . mockResolvedValue (
293- fixtureCredentialsSession as any ,
294- ) ;
291+ vi . mocked ( getIronSession ) . mockResolvedValue ( fixtureCredentialsSession as any ) ;
295292
296293 const res = await request ( app )
297294 . post ( `${ BASE } /register` )
@@ -303,9 +300,7 @@ describe("Integration - Auth Routes", () => {
303300 } ) ;
304301
305302 it ( "chama register com email, password e name" , async ( ) => {
306- vi . mocked ( getIronSession ) . mockResolvedValue (
307- fixtureCredentialsSession as any ,
308- ) ;
303+ vi . mocked ( getIronSession ) . mockResolvedValue ( fixtureCredentialsSession as any ) ;
309304
310305 await request ( app ) . post ( `${ BASE } /register` ) . send ( registerPayload ) ;
311306
@@ -319,9 +314,7 @@ describe("Integration - Auth Routes", () => {
319314 } ) ;
320315
321316 it ( "retorna 400 para email invalido (ZodError)" , async ( ) => {
322- vi . mocked ( getIronSession ) . mockResolvedValue (
323- fixtureCredentialsSession as any ,
324- ) ;
317+ vi . mocked ( getIronSession ) . mockResolvedValue ( fixtureCredentialsSession as any ) ;
325318
326319 const res = await request ( app )
327320 . post ( `${ BASE } /register` )
@@ -332,9 +325,7 @@ describe("Integration - Auth Routes", () => {
332325 } ) ;
333326
334327 it ( "retorna 400 para senha curta (ZodError)" , async ( ) => {
335- vi . mocked ( getIronSession ) . mockResolvedValue (
336- fixtureCredentialsSession as any ,
337- ) ;
328+ vi . mocked ( getIronSession ) . mockResolvedValue ( fixtureCredentialsSession as any ) ;
338329
339330 await request ( app )
340331 . post ( `${ BASE } /register` )
@@ -343,9 +334,7 @@ describe("Integration - Auth Routes", () => {
343334 } ) ;
344335
345336 it ( "retorna 409 quando email ja esta cadastrado" , async ( ) => {
346- vi . mocked ( getIronSession ) . mockResolvedValue (
347- fixtureCredentialsSession as any ,
348- ) ;
337+ vi . mocked ( getIronSession ) . mockResolvedValue ( fixtureCredentialsSession as any ) ;
349338 mockCredentialsService . register . mockRejectedValueOnce (
350339 new Error ( "Email já cadastrado" ) ,
351340 ) ;
@@ -359,9 +348,7 @@ describe("Integration - Auth Routes", () => {
359348 } ) ;
360349
361350 it ( "retorna 500 para erro inesperado no register" , async ( ) => {
362- vi . mocked ( getIronSession ) . mockResolvedValue (
363- fixtureCredentialsSession as any ,
364- ) ;
351+ vi . mocked ( getIronSession ) . mockResolvedValue ( fixtureCredentialsSession as any ) ;
365352 mockCredentialsService . register . mockRejectedValueOnce (
366353 new Error ( "db connection failed" ) ,
367354 ) ;
@@ -377,9 +364,7 @@ describe("Integration - Auth Routes", () => {
377364
378365 describe ( "POST /login" , ( ) => {
379366 it ( "autentica e retorna 200 com user e session" , async ( ) => {
380- vi . mocked ( getIronSession ) . mockResolvedValue (
381- fixtureCredentialsSession as any ,
382- ) ;
367+ vi . mocked ( getIronSession ) . mockResolvedValue ( fixtureCredentialsSession as any ) ;
383368
384369 const res = await request ( app )
385370 . post ( `${ BASE } /login` )
@@ -391,9 +376,7 @@ describe("Integration - Auth Routes", () => {
391376 } ) ;
392377
393378 it ( "chama login com email e password corretos" , async ( ) => {
394- vi . mocked ( getIronSession ) . mockResolvedValue (
395- fixtureCredentialsSession as any ,
396- ) ;
379+ vi . mocked ( getIronSession ) . mockResolvedValue ( fixtureCredentialsSession as any ) ;
397380
398381 await request ( app ) . post ( `${ BASE } /login` ) . send ( loginPayload ) ;
399382
@@ -403,9 +386,7 @@ describe("Integration - Auth Routes", () => {
403386 } ) ;
404387
405388 it ( "retorna 400 para email invalido (ZodError)" , async ( ) => {
406- vi . mocked ( getIronSession ) . mockResolvedValue (
407- fixtureCredentialsSession as any ,
408- ) ;
389+ vi . mocked ( getIronSession ) . mockResolvedValue ( fixtureCredentialsSession as any ) ;
409390
410391 await request ( app )
411392 . post ( `${ BASE } /login` )
@@ -414,9 +395,7 @@ describe("Integration - Auth Routes", () => {
414395 } ) ;
415396
416397 it ( "retorna 400 para senha ausente (ZodError)" , async ( ) => {
417- vi . mocked ( getIronSession ) . mockResolvedValue (
418- fixtureCredentialsSession as any ,
419- ) ;
398+ vi . mocked ( getIronSession ) . mockResolvedValue ( fixtureCredentialsSession as any ) ;
420399
421400 await request ( app )
422401 . post ( `${ BASE } /login` )
@@ -425,9 +404,7 @@ describe("Integration - Auth Routes", () => {
425404 } ) ;
426405
427406 it ( "retorna 401 para credenciais invalidas" , async ( ) => {
428- vi . mocked ( getIronSession ) . mockResolvedValue (
429- fixtureCredentialsSession as any ,
430- ) ;
407+ vi . mocked ( getIronSession ) . mockResolvedValue ( fixtureCredentialsSession as any ) ;
431408 mockCredentialsService . login . mockRejectedValueOnce (
432409 new Error ( "Credenciais inválidas" ) ,
433410 ) ;
@@ -441,9 +418,7 @@ describe("Integration - Auth Routes", () => {
441418 } ) ;
442419
443420 it ( "retorna 500 para erro inesperado no login" , async ( ) => {
444- vi . mocked ( getIronSession ) . mockResolvedValue (
445- fixtureCredentialsSession as any ,
446- ) ;
421+ vi . mocked ( getIronSession ) . mockResolvedValue ( fixtureCredentialsSession as any ) ;
447422 mockCredentialsService . login . mockRejectedValueOnce (
448423 new Error ( "db timeout" ) ,
449424 ) ;
@@ -486,15 +461,18 @@ describe("Integration - Auth Routes", () => {
486461 // ── GET /me ───────────────────────────────────────────────────────────────
487462
488463 describe ( "GET /me" , ( ) => {
489- it ( "retorna userId quando autenticado" , async ( ) => {
464+ it ( "retorna user completo quando autenticado" , async ( ) => {
490465 vi . mocked ( getIronSession ) . mockResolvedValue ( {
491466 userId : "user-1" ,
492467 save : vi . fn ( ) ,
468+ destroy : vi . fn ( ) ,
493469 } as any ) ;
494470
495471 const res = await request ( app ) . get ( `${ BASE } /me` ) . expect ( 200 ) ;
496472
497- expect ( res . body ) . toEqual ( { userId : "user-1" } ) ;
473+ expect ( res . body ) . toHaveProperty ( "user" ) ;
474+ expect ( res . body . user ) . toHaveProperty ( "id" , fixtureUser . id ) ;
475+ expect ( res . body . user ) . toHaveProperty ( "email" , fixtureUser . email ) ;
498476 } ) ;
499477
500478 it ( "retorna 401 quando nao autenticado" , async ( ) => {
0 commit comments