diff --git a/jest.config.pact.js b/jest.config.pact.js index 94e31107..c86e1fb4 100644 --- a/jest.config.pact.js +++ b/jest.config.pact.js @@ -1,5 +1,5 @@ module.exports = { preset: 'jest-preset-angular', - testMatch: ['**/+(*.)+(spec).(pact).(ts)'], + testMatch: ['**/+(*.)+(spec).(pact).(ts). '], setupFilesAfterEnv: ['/jest.config.js'] }; \ No newline at end of file diff --git a/src/app/services/auth.service.spec.ts b/src/app/services/auth.service.spec.ts index b8f6911e..f4c4aafe 100644 --- a/src/app/services/auth.service.spec.ts +++ b/src/app/services/auth.service.spec.ts @@ -38,28 +38,9 @@ describe("AuthService", () => { const currentUserMock = 'anonym'; - const authServiceStub = { - userSubject: { idUser: 'testId' }, - getUser: jasmine.createSpy('getUser').and.returnValue(of({ - authToken: 'mockedAuthToken', - refreshToken: 'mockedRefreshToken', - id: 'userId123', - })), - logout: jasmine.createSpy('logout').and.callFake(() => { - // Utilizar funciĆ³n de flecha para asegurar que 'this' se refiera al contexto de AuthService - cookieService.delete('authToken'); - cookieService.delete('refreshToken'); - cookieService.delete('expires_at'); - cookieService.delete('id_user'); - authService.currentUser = new User(currentUserMock); - routerMock.navigate(['/login']); - }), - }; - TestBed.configureTestingModule({ imports: [], providers: [ - { provide: AuthService, useValue: authServiceStub }, { provide: CookieService, useValue: cookieServiceMock }, ], }); diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index 9196bc99..71bb8e01 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -42,7 +42,6 @@ export class AuthService { private cookieService: CookieService) { this.userSubject = new BehaviorSubject(JSON.parse(this.cookieService.get('user'))); this.user$ = this.userSubject.asObservable(); - } /** @@ -144,6 +143,15 @@ export class AuthService { 'dni': res.dni, 'email': res.email, } + + const userCookie = this.cookieService.get('user'); + try { + if (userCookie) { + this.userSubject = new BehaviorSubject(JSON.parse(userCookie)); + } + } catch (error) { + console.error('Error parsing user cookie:', error); + } this.cookieService.set('user', JSON.stringify(user)) this.userSubject.next(user) },