-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aea27fc
commit 779cb08
Showing
1 changed file
with
53 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
} | ||
] | ||
|
||
|
@@ -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(); | ||
}); | ||
|
||
|
||
}); |