Skip to content

Commit

Permalink
Agregar pruebas unitarias para los métodos login y logout en UserService
Browse files Browse the repository at this point in the history
  • Loading branch information
Yul1b3th committed Jul 17, 2024
1 parent e9b5eea commit cd5ef8e
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions src/app/services/user.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,43 @@
import { TestBed } from '@angular/core/testing'

import { UserService } from './user.service'
import { AuthService } from './auth.service'
import { User } from '../models/user.model'

describe('UserService', () => {
let service: UserService
let userService: UserService
let authService: AuthService

beforeEach(() => {
TestBed.configureTestingModule({})
service = TestBed.inject(UserService)
const authServiceMock = {
login: jest.fn().mockResolvedValue({}),
logout: jest.fn()
}

TestBed.configureTestingModule({
providers: [
UserService,
{ provide: AuthService, useValue: authServiceMock }
]
})

userService = TestBed.inject(UserService)
authService = TestBed.inject(AuthService)
})

it('should be created', () => {
expect(service).toBeTruthy()
expect(userService).toBeTruthy()
})

it('should login user and set userLoggedIn to true', async () => {
const user: User = new User('1', '12345678', 'password', 'test@example.com', 'password')
await userService.login(user)
expect(authService.login).toHaveBeenCalledWith(user)
expect(userService.userLoggedIn).toBe(true)
})

it('should logout user and set userLoggedIn to false', () => {
userService.logout()
expect(authService.logout).toHaveBeenCalled()
expect(userService.userLoggedIn).toBe(false)
})
})

0 comments on commit cd5ef8e

Please sign in to comment.