-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nsc-events-nestjs_16_608_search_users_api_update (#168)
* users api update (searching/filtering/pagination) * comment out getAllUsers testing because refactoring broke it * try again * fix tests with new search function (getAllUsers) * refactor query for 3 search inputs * refactor controller and service to follow best practices * add sorting (by first name, then role) * fix pagination bug + tests * bugfix didn't go through?
- Loading branch information
Showing
3 changed files
with
162 additions
and
5 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 |
---|---|---|
|
@@ -10,7 +10,29 @@ describe('UserController', () => { | |
|
||
const mockUserService = { | ||
newUser: jest.fn(), | ||
getAllUsers: jest.fn(), | ||
getAllUsers: jest.fn().mockResolvedValue([ | ||
// Mocking the return value of getAllUsers | ||
{ | ||
id: 'testId', | ||
firstName: 'Test', | ||
lastName: 'User', | ||
pronouns: 'they/them', | ||
email: '[email protected]', | ||
role: Role.admin, | ||
}, | ||
]), | ||
searchUsers: jest.fn().mockReturnValue({ | ||
exec: jest.fn().mockResolvedValue([ | ||
{ | ||
id: 'testId', | ||
firstName: 'Test', | ||
lastName: 'User', | ||
pronouns: 'they/them', | ||
email: '[email protected]', | ||
role: Role.admin, | ||
}, | ||
]), | ||
}), | ||
getUserById: jest.fn(), | ||
getUserByEmail: jest.fn(), | ||
updateUser: jest.fn(), | ||
|
@@ -58,10 +80,23 @@ describe('UserController', () => { | |
|
||
describe('getAllUsers', () => { | ||
it('should call getAllUsers on the service and return a result', async () => { | ||
jest.spyOn(service, 'getAllUsers').mockResolvedValue([mockUser]); | ||
// Call the controller's getAllUsers method | ||
const result = await controller.getAllUsers(); | ||
|
||
// Ensure the service's getAllUsers method was called | ||
expect(service.getAllUsers).toHaveBeenCalled(); | ||
expect(result).toEqual([mockUser]); | ||
|
||
// Ensure the result is the mocked response | ||
expect(result).toEqual([ | ||
{ | ||
id: 'testId', | ||
firstName: 'Test', | ||
lastName: 'User', | ||
pronouns: 'they/them', | ||
email: '[email protected]', | ||
role: Role.admin, | ||
}, | ||
]); | ||
}); | ||
}); | ||
|
||
|
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
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