Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sacom14 committed Feb 12, 2024
2 parents d2617cc + 2588537 commit 7c1005e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 21 deletions.
2 changes: 1 addition & 1 deletion jest.config.pact.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
preset: 'jest-preset-angular',
testMatch: ['**/+(*.)+(spec).(pact).(ts)'],
testMatch: ['**/+(*.)+(spec).(pact).(ts). '],
setupFilesAfterEnv: ['<rootDir>/jest.config.js']
};
19 changes: 0 additions & 19 deletions src/app/services/auth.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
],
});
Expand Down
10 changes: 9 additions & 1 deletion src/app/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

}

/**
Expand Down Expand Up @@ -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)
},
Expand Down

0 comments on commit 7c1005e

Please sign in to comment.