From 779cb086ac9ece23d7a4b56a747f91bdbab176a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Victor?= Date: Thu, 16 Nov 2023 12:13:37 -0300 Subject: [PATCH] Atualiza testes --- .../update-role/update-role.component.spec.ts | 73 ++++++++++++++----- 1 file changed, 53 insertions(+), 20 deletions(-) diff --git a/src/app/pages/update-role/update-role.component.spec.ts b/src/app/pages/update-role/update-role.component.spec.ts index 43a365e0..e6e4a514 100644 --- a/src/app/pages/update-role/update-role.component.spec.ts +++ b/src/app/pages/update-role/update-role.component.spec.ts @@ -12,28 +12,28 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; const mockData = [ { - "connection": "PROFESSOR", - "id": 1, - "name": "Luisa", - "email": "email1@email.com", - "role": "USER", - "is_active": null, + "connection": "PROFESSOR", + "id": 1, + "name": "Luisa", + "email": "email1@email.com", + "role": "USER", + "is_active": null, }, { - "connection": "ESTUDANTE", - "id": 2, - "name": "Renato", - "email": "email2@email.com", - "role": "ADMIN", - "is_active": true, + "connection": "ESTUDANTE", + "id": 2, + "name": "Renato", + "email": "email2@email.com", + "role": "ADMIN", + "is_active": true, }, { - "connection": "SERVIDOR", - "id": 3, - "name": "Paolla", - "email": "email3@email.com", - "role": "USER", - "is_active": true, + "connection": "SERVIDOR", + "id": 3, + "name": "Paolla", + "email": "email3@email.com", + "role": "USER", + "is_active": true, } ] @@ -42,6 +42,9 @@ class UserServiceMock { getAllUsers() { return of(mockData); } + updateUserRole() { + return of({}); + } } describe('UpdateRoleComponent', () => { @@ -67,7 +70,7 @@ describe('UpdateRoleComponent', () => { it('should create', () => { let adminToken: string = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiZW1haWwiOiJsdWNhc2NhbmRyYWRleDFAZ21haWwuY29tIiwicm9sZSI6IkFETUlOIiwiZXhwIjoxNzAwMTAwMDQxfQ.aDhw1xkK55bhUQCm6tSxX4LYxq8hP_b3T8gYUS449F8" localStorage.setItem("token", adminToken) - + component.users = mockData; fixture.detectChanges(); expect(component).toBeTruthy(); @@ -77,7 +80,23 @@ describe('UpdateRoleComponent', () => { const mySpy = spyOn(userService, 'getAllUsers').and.callThrough(); component.getAllUsers(); expect(mySpy).toHaveBeenCalled(); - }); + }); + + + it('should get all users and data headers is null', () => { + const mySpy = spyOn(userService, 'getAllUsers').and.returnValue(of({ headers: null, body: [] })); + component.getAllUsers(); + expect(mySpy).toHaveBeenCalled(); + expect(component.users).toEqual([]); + }); + + + + it('should get all users and return error', () => { + const mySpy = spyOn(userService, 'getAllUsers').and.returnValue(throwError(() => new Error('Erro'))); + component.getAllUsers(); + expect(mySpy).toHaveBeenCalled(); + }); it('should update pageSize and pageIndex onPaginateChange', () => { const event: PageEvent = { @@ -98,4 +117,18 @@ describe('UpdateRoleComponent', () => { component.filterUser(); expect(mySpy).toHaveBeenCalled(); }); + + it('should update user role', () => { + const mySpy = spyOn(userService, 'updateUserRole').and.callThrough(); + component.updateUserRole(1); + expect(mySpy).toHaveBeenCalled(); + }); + + it('should update user role and return error', () => { + const mySpy = spyOn(userService, 'updateUserRole').and.returnValue(throwError(() => new Error('Erro'))); + component.updateUserRole(1); + expect(mySpy).toHaveBeenCalled(); + }); + + });