Skip to content

Commit

Permalink
Atualiza testes
Browse files Browse the repository at this point in the history
  • Loading branch information
joao15victor08 committed Nov 16, 2023
1 parent aea27fc commit 779cb08
Showing 1 changed file with 53 additions and 20 deletions.
73 changes: 53 additions & 20 deletions src/app/pages/update-role/update-role.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

const mockData = [
{
"connection": "PROFESSOR",
"id": 1,
"name": "Luisa",
"email": "[email protected]",
"role": "USER",
"is_active": null,
"connection": "PROFESSOR",
"id": 1,
"name": "Luisa",
"email": "[email protected]",
"role": "USER",
"is_active": null,
},
{
"connection": "ESTUDANTE",
"id": 2,
"name": "Renato",
"email": "[email protected]",
"role": "ADMIN",
"is_active": true,
"connection": "ESTUDANTE",
"id": 2,
"name": "Renato",
"email": "[email protected]",
"role": "ADMIN",
"is_active": true,
},
{
"connection": "SERVIDOR",
"id": 3,
"name": "Paolla",
"email": "[email protected]",
"role": "USER",
"is_active": true,
"connection": "SERVIDOR",
"id": 3,
"name": "Paolla",
"email": "[email protected]",
"role": "USER",
"is_active": true,
}
]

Expand All @@ -42,6 +42,9 @@ class UserServiceMock {
getAllUsers() {
return of(mockData);
}
updateUserRole() {
return of({});
}
}

describe('UpdateRoleComponent', () => {
Expand All @@ -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();
Expand All @@ -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 = {
Expand All @@ -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();
});


});

0 comments on commit 779cb08

Please sign in to comment.