mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix: unit tests
This commit is contained in:
@@ -92,10 +92,8 @@ describe('ModelController', () => {
|
||||
describe('find', () => {
|
||||
it('should find models', async () => {
|
||||
jest.spyOn(modelService, 'findAndPopulate');
|
||||
const result = await modelController.find([], {});
|
||||
expect(modelService.findAndPopulate).toHaveBeenCalledWith({}, [
|
||||
'permissions',
|
||||
]);
|
||||
const result = await modelController.find(['permissions'], {});
|
||||
expect(modelService.findAndPopulate).toHaveBeenCalledWith({});
|
||||
expect(result).toEqualPayload(
|
||||
modelFixtures.map((modelFixture) => ({
|
||||
...modelFixture,
|
||||
@@ -122,9 +120,7 @@ describe('ModelController', () => {
|
||||
return acc;
|
||||
}, []);
|
||||
|
||||
expect(modelService.findAndPopulate).toHaveBeenCalledWith({}, [
|
||||
'permissions',
|
||||
]);
|
||||
expect(modelService.findAndPopulate).toHaveBeenCalledWith({});
|
||||
expect(result).toEqualPayload(modelsWithPermissionsAndUsers);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -148,9 +148,7 @@ describe('UserController', () => {
|
||||
it('should find one user and populate its roles', async () => {
|
||||
jest.spyOn(userService, 'findOneAndPopulate');
|
||||
const result = await userController.findOne(user.id, ['roles']);
|
||||
expect(userService.findOneAndPopulate).toHaveBeenCalledWith(user.id, [
|
||||
'roles',
|
||||
]);
|
||||
expect(userService.findOneAndPopulate).toHaveBeenCalledWith(user.id);
|
||||
expect(result).toEqualPayload(
|
||||
{
|
||||
...userFixtures.find(({ username }) => username === 'admin'),
|
||||
@@ -166,9 +164,7 @@ describe('UserController', () => {
|
||||
|
||||
it('should find users, and for each user populate the corresponding roles', async () => {
|
||||
jest.spyOn(userService, 'findPageAndPopulate');
|
||||
const result = await userService.findPageAndPopulate({}, pageQuery, [
|
||||
'roles',
|
||||
]);
|
||||
const result = await userService.findPageAndPopulate({}, pageQuery);
|
||||
|
||||
const usersWithRoles = userFixtures.reduce((acc, currUser) => {
|
||||
acc.push({
|
||||
@@ -181,7 +177,6 @@ describe('UserController', () => {
|
||||
expect(userService.findPageAndPopulate).toHaveBeenCalledWith(
|
||||
{},
|
||||
pageQuery,
|
||||
['roles'],
|
||||
);
|
||||
expect(result).toEqualPayload(usersWithRoles, [
|
||||
...IGNORED_FIELDS,
|
||||
|
||||
Reference in New Issue
Block a user