mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix: update unit tests
This commit is contained in:
parent
32f3dc8271
commit
6cbedcbc16
@ -68,7 +68,10 @@ describe('BlockRepository', () => {
|
|||||||
jest.spyOn(blockModel, 'findById');
|
jest.spyOn(blockModel, 'findById');
|
||||||
|
|
||||||
const result = await blockRepository.findOneAndPopulate(hasNextBlocks.id);
|
const result = await blockRepository.findOneAndPopulate(hasNextBlocks.id);
|
||||||
expect(blockModel.findById).toHaveBeenCalledWith(hasNextBlocks.id);
|
expect(blockModel.findById).toHaveBeenCalledWith(
|
||||||
|
hasNextBlocks.id,
|
||||||
|
undefined,
|
||||||
|
);
|
||||||
expect(result).toEqualPayload({
|
expect(result).toEqualPayload({
|
||||||
...blockFixtures.find(({ name }) => name === hasNextBlocks.name),
|
...blockFixtures.find(({ name }) => name === hasNextBlocks.name),
|
||||||
category,
|
category,
|
||||||
@ -92,7 +95,7 @@ describe('BlockRepository', () => {
|
|||||||
blockFixture.name === 'hasNextBlocks' ? [hasPreviousBlocks] : [],
|
blockFixture.name === 'hasNextBlocks' ? [hasPreviousBlocks] : [],
|
||||||
}));
|
}));
|
||||||
|
|
||||||
expect(blockModel.find).toHaveBeenCalledWith({});
|
expect(blockModel.find).toHaveBeenCalledWith({}, undefined);
|
||||||
expect(result).toEqualPayload(blocksWithCategory);
|
expect(result).toEqualPayload(blocksWithCategory);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -109,7 +112,7 @@ describe('BlockRepository', () => {
|
|||||||
blockFixture.name === 'hasNextBlocks' ? [hasPreviousBlocks] : [],
|
blockFixture.name === 'hasNextBlocks' ? [hasPreviousBlocks] : [],
|
||||||
}));
|
}));
|
||||||
|
|
||||||
expect(blockModel.find).toHaveBeenCalledWith({});
|
expect(blockModel.find).toHaveBeenCalledWith({}, undefined);
|
||||||
expect(result).toEqualPayload(blocksWithCategory);
|
expect(result).toEqualPayload(blocksWithCategory);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -21,8 +21,8 @@ import {
|
|||||||
rootMongooseTestModule,
|
rootMongooseTestModule,
|
||||||
} from '@/utils/test/test';
|
} from '@/utils/test/test';
|
||||||
|
|
||||||
import { LabelModel, Label } from '../schemas/label.schema';
|
import { Label, LabelModel } from '../schemas/label.schema';
|
||||||
import { SubscriberModel, Subscriber } from '../schemas/subscriber.schema';
|
import { Subscriber, SubscriberModel } from '../schemas/subscriber.schema';
|
||||||
|
|
||||||
import { LabelRepository } from './label.repository';
|
import { LabelRepository } from './label.repository';
|
||||||
import { SubscriberRepository } from './subscriber.repository';
|
import { SubscriberRepository } from './subscriber.repository';
|
||||||
@ -62,7 +62,7 @@ describe('LabelRepository', () => {
|
|||||||
const label = await labelRepository.findOne({ name: 'TEST_TITLE_2' });
|
const label = await labelRepository.findOne({ name: 'TEST_TITLE_2' });
|
||||||
const result = await labelRepository.findOneAndPopulate(label.id);
|
const result = await labelRepository.findOneAndPopulate(label.id);
|
||||||
|
|
||||||
expect(labelModel.findById).toHaveBeenCalledWith(label.id);
|
expect(labelModel.findById).toHaveBeenCalledWith(label.id, undefined);
|
||||||
expect(result).toEqualPayload({
|
expect(result).toEqualPayload({
|
||||||
...labelFixtures.find(({ name }) => name === label.name),
|
...labelFixtures.find(({ name }) => name === label.name),
|
||||||
users,
|
users,
|
||||||
@ -79,7 +79,7 @@ describe('LabelRepository', () => {
|
|||||||
users,
|
users,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
expect(labelModel.find).toHaveBeenCalledWith({});
|
expect(labelModel.find).toHaveBeenCalledWith({}, undefined);
|
||||||
expect(result).toEqualPayload(labelsWithUsers);
|
expect(result).toEqualPayload(labelsWithUsers);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -94,7 +94,7 @@ describe('LabelRepository', () => {
|
|||||||
users,
|
users,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
expect(labelModel.find).toHaveBeenCalledWith({});
|
expect(labelModel.find).toHaveBeenCalledWith({}, undefined);
|
||||||
expect(result).toEqualPayload(labelsWithUsers.sort(sortRowsBy));
|
expect(result).toEqualPayload(labelsWithUsers.sort(sortRowsBy));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -23,7 +23,7 @@ import {
|
|||||||
rootMongooseTestModule,
|
rootMongooseTestModule,
|
||||||
} from '@/utils/test/test';
|
} from '@/utils/test/test';
|
||||||
|
|
||||||
import { MessageModel, Message } from '../schemas/message.schema';
|
import { Message, MessageModel } from '../schemas/message.schema';
|
||||||
import { SubscriberModel } from '../schemas/subscriber.schema';
|
import { SubscriberModel } from '../schemas/subscriber.schema';
|
||||||
import { AnyMessage } from '../schemas/types/message';
|
import { AnyMessage } from '../schemas/types/message';
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ describe('MessageRepository', () => {
|
|||||||
const user = await userRepository.findOne(message['sentBy']);
|
const user = await userRepository.findOne(message['sentBy']);
|
||||||
const result = await messageRepository.findOneAndPopulate(message.id);
|
const result = await messageRepository.findOneAndPopulate(message.id);
|
||||||
|
|
||||||
expect(messageModel.findById).toHaveBeenCalledWith(message.id);
|
expect(messageModel.findById).toHaveBeenCalledWith(message.id, undefined);
|
||||||
expect(result).toEqualPayload({
|
expect(result).toEqualPayload({
|
||||||
...messageFixtures.find(({ mid }) => mid === message.mid),
|
...messageFixtures.find(({ mid }) => mid === message.mid),
|
||||||
sender,
|
sender,
|
||||||
@ -95,7 +95,7 @@ describe('MessageRepository', () => {
|
|||||||
sentBy: allUsers.find(({ id }) => id === message['sentBy']).id,
|
sentBy: allUsers.find(({ id }) => id === message['sentBy']).id,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
expect(messageModel.find).toHaveBeenCalledWith({});
|
expect(messageModel.find).toHaveBeenCalledWith({}, undefined);
|
||||||
expect(result).toEqualPayload(messages);
|
expect(result).toEqualPayload(messages);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -19,7 +19,7 @@ import {
|
|||||||
import { AttachmentService } from '@/attachment/services/attachment.service';
|
import { AttachmentService } from '@/attachment/services/attachment.service';
|
||||||
import { LoggerService } from '@/logger/logger.service';
|
import { LoggerService } from '@/logger/logger.service';
|
||||||
import { UserRepository } from '@/user/repositories/user.repository';
|
import { UserRepository } from '@/user/repositories/user.repository';
|
||||||
import { UserModel, User } from '@/user/schemas/user.schema';
|
import { User, UserModel } from '@/user/schemas/user.schema';
|
||||||
import {
|
import {
|
||||||
installSubscriberFixtures,
|
installSubscriberFixtures,
|
||||||
subscriberFixtures,
|
subscriberFixtures,
|
||||||
@ -31,11 +31,11 @@ import {
|
|||||||
rootMongooseTestModule,
|
rootMongooseTestModule,
|
||||||
} from '@/utils/test/test';
|
} from '@/utils/test/test';
|
||||||
|
|
||||||
import { LabelModel, Label } from '../schemas/label.schema';
|
import { Label, LabelModel } from '../schemas/label.schema';
|
||||||
import {
|
import {
|
||||||
SubscriberModel,
|
|
||||||
Subscriber,
|
Subscriber,
|
||||||
SubscriberFull,
|
SubscriberFull,
|
||||||
|
SubscriberModel,
|
||||||
} from '../schemas/subscriber.schema';
|
} from '../schemas/subscriber.schema';
|
||||||
|
|
||||||
import { LabelRepository } from './label.repository';
|
import { LabelRepository } from './label.repository';
|
||||||
@ -119,7 +119,10 @@ describe('SubscriberRepository', () => {
|
|||||||
assignedTo: allUsers.find(({ id }) => subscriber.assignedTo === id),
|
assignedTo: allUsers.find(({ id }) => subscriber.assignedTo === id),
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(subscriberModel.findById).toHaveBeenCalledWith(subscriber.id);
|
expect(subscriberModel.findById).toHaveBeenCalledWith(
|
||||||
|
subscriber.id,
|
||||||
|
undefined,
|
||||||
|
);
|
||||||
expect(result).toEqualPayload(subscriberWithLabels);
|
expect(result).toEqualPayload(subscriberWithLabels);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -133,7 +136,7 @@ describe('SubscriberRepository', () => {
|
|||||||
pageQuery,
|
pageQuery,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(subscriberModel.find).toHaveBeenCalledWith({});
|
expect(subscriberModel.find).toHaveBeenCalledWith({}, undefined);
|
||||||
expect(result).toEqualPayload(
|
expect(result).toEqualPayload(
|
||||||
subscribersWithPopulatedFields.sort(sortRowsBy),
|
subscribersWithPopulatedFields.sort(sortRowsBy),
|
||||||
);
|
);
|
||||||
@ -145,7 +148,7 @@ describe('SubscriberRepository', () => {
|
|||||||
jest.spyOn(subscriberModel, 'find');
|
jest.spyOn(subscriberModel, 'find');
|
||||||
const result = await subscriberRepository.findAllAndPopulate();
|
const result = await subscriberRepository.findAllAndPopulate();
|
||||||
|
|
||||||
expect(subscriberModel.find).toHaveBeenCalledWith({});
|
expect(subscriberModel.find).toHaveBeenCalledWith({}, undefined);
|
||||||
expect(result).toEqualPayload(
|
expect(result).toEqualPayload(
|
||||||
subscribersWithPopulatedFields.sort(sortRowsBy),
|
subscribersWithPopulatedFields.sort(sortRowsBy),
|
||||||
);
|
);
|
||||||
|
@ -170,7 +170,10 @@ describe('BlockService', () => {
|
|||||||
jest.spyOn(blockRepository, 'findOneAndPopulate');
|
jest.spyOn(blockRepository, 'findOneAndPopulate');
|
||||||
const result = await blockService.findOneAndPopulate(block.id);
|
const result = await blockService.findOneAndPopulate(block.id);
|
||||||
|
|
||||||
expect(blockRepository.findOneAndPopulate).toHaveBeenCalledWith(block.id);
|
expect(blockRepository.findOneAndPopulate).toHaveBeenCalledWith(
|
||||||
|
block.id,
|
||||||
|
undefined,
|
||||||
|
);
|
||||||
expect(result).toEqualPayload({
|
expect(result).toEqualPayload({
|
||||||
...blockFixtures.find(({ name }) => name === 'hasNextBlocks'),
|
...blockFixtures.find(({ name }) => name === 'hasNextBlocks'),
|
||||||
category,
|
category,
|
||||||
@ -196,6 +199,7 @@ describe('BlockService', () => {
|
|||||||
expect(blockRepository.findAndPopulate).toHaveBeenCalledWith(
|
expect(blockRepository.findAndPopulate).toHaveBeenCalledWith(
|
||||||
{},
|
{},
|
||||||
undefined,
|
undefined,
|
||||||
|
undefined,
|
||||||
);
|
);
|
||||||
expect(result).toEqualPayload(blocksWithCategory);
|
expect(result).toEqualPayload(blocksWithCategory);
|
||||||
});
|
});
|
||||||
|
@ -113,6 +113,7 @@ describe('MessageService', () => {
|
|||||||
|
|
||||||
expect(messageRepository.findOneAndPopulate).toHaveBeenCalledWith(
|
expect(messageRepository.findOneAndPopulate).toHaveBeenCalledWith(
|
||||||
message.id,
|
message.id,
|
||||||
|
undefined,
|
||||||
);
|
);
|
||||||
expect(result).toEqualPayload({
|
expect(result).toEqualPayload({
|
||||||
...messageFixtures.find(({ mid }) => mid === message.mid),
|
...messageFixtures.find(({ mid }) => mid === message.mid),
|
||||||
|
@ -26,8 +26,8 @@ import {
|
|||||||
import { Content, ContentModel } from '../schemas/content.schema';
|
import { Content, ContentModel } from '../schemas/content.schema';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
installContentFixtures,
|
|
||||||
contentFixtures,
|
contentFixtures,
|
||||||
|
installContentFixtures,
|
||||||
} from './../../utils/test/fixtures/content';
|
} from './../../utils/test/fixtures/content';
|
||||||
import { ContentRepository } from './content.repository';
|
import { ContentRepository } from './content.repository';
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ describe('ContentRepository', () => {
|
|||||||
const content = await contentModel.findOne({ title: 'Jean' });
|
const content = await contentModel.findOne({ title: 'Jean' });
|
||||||
const contentType = await contentTypeModel.findById(content.entity);
|
const contentType = await contentTypeModel.findById(content.entity);
|
||||||
const result = await contentRepository.findOneAndPopulate(content.id);
|
const result = await contentRepository.findOneAndPopulate(content.id);
|
||||||
expect(findSpy).toHaveBeenCalledWith(content.id);
|
expect(findSpy).toHaveBeenCalledWith(content.id, undefined);
|
||||||
expect(result).toEqualPayload({
|
expect(result).toEqualPayload({
|
||||||
...contentFixtures.find(({ title }) => title === 'Jean'),
|
...contentFixtures.find(({ title }) => title === 'Jean'),
|
||||||
entity: contentTypeFixtures.find(
|
entity: contentTypeFixtures.find(
|
||||||
|
@ -84,7 +84,7 @@ describe('ContentService', () => {
|
|||||||
const content = await contentService.findOne({ title: 'Jean' });
|
const content = await contentService.findOne({ title: 'Jean' });
|
||||||
const contentType = await contentTypeService.findOne(content.entity);
|
const contentType = await contentTypeService.findOne(content.entity);
|
||||||
const result = await contentService.findOneAndPopulate(content.id);
|
const result = await contentService.findOneAndPopulate(content.id);
|
||||||
expect(findSpy).toHaveBeenCalledWith(content.id);
|
expect(findSpy).toHaveBeenCalledWith(content.id, undefined);
|
||||||
expect(result).toEqualPayload({
|
expect(result).toEqualPayload({
|
||||||
...contentFixtures.find(({ title }) => title === 'Jean'),
|
...contentFixtures.find(({ title }) => title === 'Jean'),
|
||||||
entity: contentType,
|
entity: contentType,
|
||||||
|
@ -23,7 +23,7 @@ import {
|
|||||||
rootMongooseTestModule,
|
rootMongooseTestModule,
|
||||||
} from '@/utils/test/test';
|
} from '@/utils/test/test';
|
||||||
|
|
||||||
import { InvitationModel, Invitation } from '../schemas/invitation.schema';
|
import { Invitation, InvitationModel } from '../schemas/invitation.schema';
|
||||||
import { PermissionModel } from '../schemas/permission.schema';
|
import { PermissionModel } from '../schemas/permission.schema';
|
||||||
import { RoleModel } from '../schemas/role.schema';
|
import { RoleModel } from '../schemas/role.schema';
|
||||||
|
|
||||||
@ -81,7 +81,10 @@ describe('InvitationRepository', () => {
|
|||||||
const result = await invitationRepository.findOneAndPopulate(
|
const result = await invitationRepository.findOneAndPopulate(
|
||||||
invitation.id,
|
invitation.id,
|
||||||
);
|
);
|
||||||
expect(invitationModel.findById).toHaveBeenCalledWith(invitation.id);
|
expect(invitationModel.findById).toHaveBeenCalledWith(
|
||||||
|
invitation.id,
|
||||||
|
undefined,
|
||||||
|
);
|
||||||
expect(result).toEqualPayload({
|
expect(result).toEqualPayload({
|
||||||
...toTestAgainst,
|
...toTestAgainst,
|
||||||
roles,
|
roles,
|
||||||
@ -110,7 +113,7 @@ describe('InvitationRepository', () => {
|
|||||||
return acc;
|
return acc;
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
expect(invitationModel.find).toHaveBeenCalledWith({});
|
expect(invitationModel.find).toHaveBeenCalledWith({}, undefined);
|
||||||
expect(result).toEqualPayload(invitationsWithRoles);
|
expect(result).toEqualPayload(invitationsWithRoles);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -56,7 +56,7 @@ describe('ModelRepository', () => {
|
|||||||
it('should find a model and populate its permissions', async () => {
|
it('should find a model and populate its permissions', async () => {
|
||||||
jest.spyOn(modelModel, 'findById');
|
jest.spyOn(modelModel, 'findById');
|
||||||
const result = await modelRepository.findOneAndPopulate(model.id);
|
const result = await modelRepository.findOneAndPopulate(model.id);
|
||||||
expect(modelModel.findById).toHaveBeenCalledWith(model.id);
|
expect(modelModel.findById).toHaveBeenCalledWith(model.id, undefined);
|
||||||
expect(result).toEqualPayload({
|
expect(result).toEqualPayload({
|
||||||
...modelFixtures.find(({ name }) => name === 'ContentType'),
|
...modelFixtures.find(({ name }) => name === 'ContentType'),
|
||||||
permissions,
|
permissions,
|
||||||
@ -79,7 +79,7 @@ describe('ModelRepository', () => {
|
|||||||
});
|
});
|
||||||
return acc;
|
return acc;
|
||||||
}, []);
|
}, []);
|
||||||
expect(modelModel.find).toHaveBeenCalledWith({});
|
expect(modelModel.find).toHaveBeenCalledWith({}, undefined);
|
||||||
expect(result).toEqualPayload(modelsWithPermissions);
|
expect(result).toEqualPayload(modelsWithPermissions);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -24,7 +24,7 @@ import { ModelRepository } from '../repositories/model.repository';
|
|||||||
import { PermissionRepository } from '../repositories/permission.repository';
|
import { PermissionRepository } from '../repositories/permission.repository';
|
||||||
import { RoleRepository } from '../repositories/role.repository';
|
import { RoleRepository } from '../repositories/role.repository';
|
||||||
import { ModelModel } from '../schemas/model.schema';
|
import { ModelModel } from '../schemas/model.schema';
|
||||||
import { PermissionModel, Permission } from '../schemas/permission.schema';
|
import { Permission, PermissionModel } from '../schemas/permission.schema';
|
||||||
import { RoleModel } from '../schemas/role.schema';
|
import { RoleModel } from '../schemas/role.schema';
|
||||||
import { Action } from '../types/action.type';
|
import { Action } from '../types/action.type';
|
||||||
|
|
||||||
@ -77,8 +77,12 @@ describe('PermissionRepository', () => {
|
|||||||
const model = await modelRepository.findOne(permission.model);
|
const model = await modelRepository.findOne(permission.model);
|
||||||
const result = await permissionRepository.findOneAndPopulate(
|
const result = await permissionRepository.findOneAndPopulate(
|
||||||
permission.id,
|
permission.id,
|
||||||
|
undefined,
|
||||||
|
);
|
||||||
|
expect(permissionModel.findById).toHaveBeenCalledWith(
|
||||||
|
permission.id,
|
||||||
|
undefined,
|
||||||
);
|
);
|
||||||
expect(permissionModel.findById).toHaveBeenCalledWith(permission.id);
|
|
||||||
expect(result).toEqualPayload({
|
expect(result).toEqualPayload({
|
||||||
...permissionFixtures.find(({ action }) => action === 'create'),
|
...permissionFixtures.find(({ action }) => action === 'create'),
|
||||||
role,
|
role,
|
||||||
@ -111,7 +115,7 @@ describe('PermissionRepository', () => {
|
|||||||
},
|
},
|
||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
expect(permissionModel.find).toHaveBeenCalledWith({});
|
expect(permissionModel.find).toHaveBeenCalledWith({}, undefined);
|
||||||
expect(result).toEqualPayload(permissionsWithRolesAndModels);
|
expect(result).toEqualPayload(permissionsWithRolesAndModels);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -74,7 +74,7 @@ describe('RoleRepository', () => {
|
|||||||
jest.spyOn(roleModel, 'findById');
|
jest.spyOn(roleModel, 'findById');
|
||||||
const permissions = await permissionRepository.find({ role: role.id });
|
const permissions = await permissionRepository.find({ role: role.id });
|
||||||
const result = await roleRepository.findOneAndPopulate(role.id);
|
const result = await roleRepository.findOneAndPopulate(role.id);
|
||||||
expect(roleModel.findById).toHaveBeenCalledWith(role.id);
|
expect(roleModel.findById).toHaveBeenCalledWith(role.id, undefined);
|
||||||
expect(result).toEqualPayload({
|
expect(result).toEqualPayload({
|
||||||
...roleFixtures.find(({ name }) => name === 'admin'),
|
...roleFixtures.find(({ name }) => name === 'admin'),
|
||||||
users,
|
users,
|
||||||
@ -106,7 +106,7 @@ describe('RoleRepository', () => {
|
|||||||
return acc;
|
return acc;
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
expect(roleModel.find).toHaveBeenCalledWith({});
|
expect(roleModel.find).toHaveBeenCalledWith({}, undefined);
|
||||||
expect(result).toEqualPayload(rolesWithPermissionsAndUsers);
|
expect(result).toEqualPayload(rolesWithPermissionsAndUsers);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -27,8 +27,8 @@ import { PermissionRepository } from '../repositories/permission.repository';
|
|||||||
import { RoleRepository } from '../repositories/role.repository';
|
import { RoleRepository } from '../repositories/role.repository';
|
||||||
import { UserRepository } from '../repositories/user.repository';
|
import { UserRepository } from '../repositories/user.repository';
|
||||||
import { PermissionModel } from '../schemas/permission.schema';
|
import { PermissionModel } from '../schemas/permission.schema';
|
||||||
import { RoleModel, Role } from '../schemas/role.schema';
|
import { Role, RoleModel } from '../schemas/role.schema';
|
||||||
import { UserModel, User } from '../schemas/user.schema';
|
import { User, UserModel } from '../schemas/user.schema';
|
||||||
|
|
||||||
describe('UserRepository', () => {
|
describe('UserRepository', () => {
|
||||||
let roleRepository: RoleRepository;
|
let roleRepository: RoleRepository;
|
||||||
@ -91,7 +91,7 @@ describe('UserRepository', () => {
|
|||||||
it('should find one user and populate its role', async () => {
|
it('should find one user and populate its role', async () => {
|
||||||
jest.spyOn(userModel, 'findById');
|
jest.spyOn(userModel, 'findById');
|
||||||
const result = await userRepository.findOneAndPopulate(user.id);
|
const result = await userRepository.findOneAndPopulate(user.id);
|
||||||
expect(userModel.findById).toHaveBeenCalledWith(user.id);
|
expect(userModel.findById).toHaveBeenCalledWith(user.id, undefined);
|
||||||
expect(result).toEqualPayload(
|
expect(result).toEqualPayload(
|
||||||
{
|
{
|
||||||
...userFixtures.find(({ username }) => username === 'admin'),
|
...userFixtures.find(({ username }) => username === 'admin'),
|
||||||
@ -118,7 +118,7 @@ describe('UserRepository', () => {
|
|||||||
return acc;
|
return acc;
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
expect(userModel.find).toHaveBeenCalledWith({});
|
expect(userModel.find).toHaveBeenCalledWith({}, undefined);
|
||||||
expect(result).toEqualPayload(usersWithRoles);
|
expect(result).toEqualPayload(usersWithRoles);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -77,7 +77,11 @@ describe('AuthService', () => {
|
|||||||
'admin@admin.admin',
|
'admin@admin.admin',
|
||||||
'adminadmin',
|
'adminadmin',
|
||||||
);
|
);
|
||||||
expect(userRepository.findOne).toHaveBeenCalledWith(searchCriteria, {});
|
expect(userRepository.findOne).toHaveBeenCalledWith(
|
||||||
|
searchCriteria,
|
||||||
|
{},
|
||||||
|
undefined,
|
||||||
|
);
|
||||||
expect(result.id).toBe(user.id);
|
expect(result.id).toBe(user.id);
|
||||||
});
|
});
|
||||||
it('should not validate user if the provided password is incorrect', async () => {
|
it('should not validate user if the provided password is incorrect', async () => {
|
||||||
@ -85,7 +89,11 @@ describe('AuthService', () => {
|
|||||||
'admin@admin.admin',
|
'admin@admin.admin',
|
||||||
'randomPassword',
|
'randomPassword',
|
||||||
);
|
);
|
||||||
expect(userRepository.findOne).toHaveBeenCalledWith(searchCriteria, {});
|
expect(userRepository.findOne).toHaveBeenCalledWith(
|
||||||
|
searchCriteria,
|
||||||
|
{},
|
||||||
|
undefined,
|
||||||
|
);
|
||||||
expect(result).toBeNull();
|
expect(result).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -99,6 +107,7 @@ describe('AuthService', () => {
|
|||||||
email: 'admin2@admin.admin',
|
email: 'admin2@admin.admin',
|
||||||
},
|
},
|
||||||
{},
|
{},
|
||||||
|
undefined,
|
||||||
);
|
);
|
||||||
expect(result).toBeNull();
|
expect(result).toBeNull();
|
||||||
});
|
});
|
||||||
|
@ -19,8 +19,8 @@ import {
|
|||||||
|
|
||||||
import { ModelRepository } from '../repositories/model.repository';
|
import { ModelRepository } from '../repositories/model.repository';
|
||||||
import { PermissionRepository } from '../repositories/permission.repository';
|
import { PermissionRepository } from '../repositories/permission.repository';
|
||||||
import { ModelModel, Model } from '../schemas/model.schema';
|
import { Model, ModelModel } from '../schemas/model.schema';
|
||||||
import { PermissionModel, Permission } from '../schemas/permission.schema';
|
import { Permission, PermissionModel } from '../schemas/permission.schema';
|
||||||
|
|
||||||
import { ModelService } from './model.service';
|
import { ModelService } from './model.service';
|
||||||
|
|
||||||
@ -83,6 +83,7 @@ describe('ModelService', () => {
|
|||||||
expect(modelRepository.findAndPopulate).toHaveBeenCalledWith(
|
expect(modelRepository.findAndPopulate).toHaveBeenCalledWith(
|
||||||
{},
|
{},
|
||||||
undefined,
|
undefined,
|
||||||
|
undefined,
|
||||||
);
|
);
|
||||||
expect(result).toEqualPayload(modelsWithPermissions);
|
expect(result).toEqualPayload(modelsWithPermissions);
|
||||||
});
|
});
|
||||||
|
@ -26,9 +26,9 @@ import { PermissionRepository } from '../repositories/permission.repository';
|
|||||||
import { RoleRepository } from '../repositories/role.repository';
|
import { RoleRepository } from '../repositories/role.repository';
|
||||||
import { ModelModel } from '../schemas/model.schema';
|
import { ModelModel } from '../schemas/model.schema';
|
||||||
import {
|
import {
|
||||||
PermissionModel,
|
|
||||||
Permission,
|
Permission,
|
||||||
PermissionFull,
|
PermissionFull,
|
||||||
|
PermissionModel,
|
||||||
} from '../schemas/permission.schema';
|
} from '../schemas/permission.schema';
|
||||||
import { RoleModel } from '../schemas/role.schema';
|
import { RoleModel } from '../schemas/role.schema';
|
||||||
import { Action } from '../types/action.type';
|
import { Action } from '../types/action.type';
|
||||||
@ -89,6 +89,7 @@ describe('PermissionService', () => {
|
|||||||
const result = await permissionService.findOneAndPopulate(permission.id);
|
const result = await permissionService.findOneAndPopulate(permission.id);
|
||||||
expect(permissionRepository.findOneAndPopulate).toHaveBeenLastCalledWith(
|
expect(permissionRepository.findOneAndPopulate).toHaveBeenLastCalledWith(
|
||||||
permission.id,
|
permission.id,
|
||||||
|
undefined,
|
||||||
);
|
);
|
||||||
expect(result).toEqualPayload({
|
expect(result).toEqualPayload({
|
||||||
...permissionFixtures.find(({ action }) => action === 'create'),
|
...permissionFixtures.find(({ action }) => action === 'create'),
|
||||||
|
@ -20,9 +20,9 @@ import {
|
|||||||
import { PermissionRepository } from '../repositories/permission.repository';
|
import { PermissionRepository } from '../repositories/permission.repository';
|
||||||
import { RoleRepository } from '../repositories/role.repository';
|
import { RoleRepository } from '../repositories/role.repository';
|
||||||
import { UserRepository } from '../repositories/user.repository';
|
import { UserRepository } from '../repositories/user.repository';
|
||||||
import { PermissionModel, Permission } from '../schemas/permission.schema';
|
import { Permission, PermissionModel } from '../schemas/permission.schema';
|
||||||
import { RoleModel, Role } from '../schemas/role.schema';
|
import { Role, RoleModel } from '../schemas/role.schema';
|
||||||
import { UserModel, User } from '../schemas/user.schema';
|
import { User, UserModel } from '../schemas/user.schema';
|
||||||
|
|
||||||
import { roleFixtures } from './../../utils/test/fixtures/role';
|
import { roleFixtures } from './../../utils/test/fixtures/role';
|
||||||
import { RoleService } from './role.service';
|
import { RoleService } from './role.service';
|
||||||
@ -72,8 +72,11 @@ describe('RoleService', () => {
|
|||||||
describe('findOneAndPopulate', () => {
|
describe('findOneAndPopulate', () => {
|
||||||
it('should find one role and populate its permissions and users', async () => {
|
it('should find one role and populate its permissions and users', async () => {
|
||||||
jest.spyOn(roleRepository, 'findOneAndPopulate');
|
jest.spyOn(roleRepository, 'findOneAndPopulate');
|
||||||
const result = await roleService.findOneAndPopulate(role.id);
|
const result = await roleService.findOneAndPopulate(role.id, undefined);
|
||||||
expect(roleRepository.findOneAndPopulate).toHaveBeenCalledWith(role.id);
|
expect(roleRepository.findOneAndPopulate).toHaveBeenCalledWith(
|
||||||
|
role.id,
|
||||||
|
undefined,
|
||||||
|
);
|
||||||
expect(result).toEqualPayload({
|
expect(result).toEqualPayload({
|
||||||
...roleFixtures.find(({ name }) => name == 'admin'),
|
...roleFixtures.find(({ name }) => name == 'admin'),
|
||||||
users,
|
users,
|
||||||
|
@ -28,8 +28,8 @@ import { PermissionRepository } from '../repositories/permission.repository';
|
|||||||
import { RoleRepository } from '../repositories/role.repository';
|
import { RoleRepository } from '../repositories/role.repository';
|
||||||
import { UserRepository } from '../repositories/user.repository';
|
import { UserRepository } from '../repositories/user.repository';
|
||||||
import { PermissionModel } from '../schemas/permission.schema';
|
import { PermissionModel } from '../schemas/permission.schema';
|
||||||
import { RoleModel, Role } from '../schemas/role.schema';
|
import { Role, RoleModel } from '../schemas/role.schema';
|
||||||
import { UserModel, User } from '../schemas/user.schema';
|
import { User, UserModel } from '../schemas/user.schema';
|
||||||
|
|
||||||
import { PermissionService } from './permission.service';
|
import { PermissionService } from './permission.service';
|
||||||
import { RoleService } from './role.service';
|
import { RoleService } from './role.service';
|
||||||
@ -100,7 +100,10 @@ describe('UserService', () => {
|
|||||||
it('should find one user and populate its role', async () => {
|
it('should find one user and populate its role', async () => {
|
||||||
jest.spyOn(userRepository, 'findOneAndPopulate');
|
jest.spyOn(userRepository, 'findOneAndPopulate');
|
||||||
const result = await userService.findOneAndPopulate(user.id);
|
const result = await userService.findOneAndPopulate(user.id);
|
||||||
expect(userRepository.findOneAndPopulate).toHaveBeenCalledWith(user.id);
|
expect(userRepository.findOneAndPopulate).toHaveBeenCalledWith(
|
||||||
|
user.id,
|
||||||
|
undefined,
|
||||||
|
);
|
||||||
expect(result).toEqualPayload(
|
expect(result).toEqualPayload(
|
||||||
{
|
{
|
||||||
...userFixtures.find(({ username }) => username === 'admin'),
|
...userFixtures.find(({ username }) => username === 'admin'),
|
||||||
|
@ -72,7 +72,7 @@ describe('BaseRepository', () => {
|
|||||||
jest.spyOn(dummyModel, 'findById');
|
jest.spyOn(dummyModel, 'findById');
|
||||||
const result = await dummyRepository.findOne(createdId);
|
const result = await dummyRepository.findOne(createdId);
|
||||||
|
|
||||||
expect(dummyModel.findById).toHaveBeenCalledWith(createdId);
|
expect(dummyModel.findById).toHaveBeenCalledWith(createdId, undefined);
|
||||||
expect(result).toEqualPayload({
|
expect(result).toEqualPayload({
|
||||||
dummy: 'dummy test 5',
|
dummy: 'dummy test 5',
|
||||||
});
|
});
|
||||||
@ -82,9 +82,12 @@ describe('BaseRepository', () => {
|
|||||||
jest.spyOn(dummyModel, 'findOne');
|
jest.spyOn(dummyModel, 'findOne');
|
||||||
const result = await dummyRepository.findOne({ dummy: 'dummy test 5' });
|
const result = await dummyRepository.findOne({ dummy: 'dummy test 5' });
|
||||||
|
|
||||||
expect(dummyModel.findOne).toHaveBeenCalledWith({
|
expect(dummyModel.findOne).toHaveBeenCalledWith(
|
||||||
|
{
|
||||||
dummy: 'dummy test 5',
|
dummy: 'dummy test 5',
|
||||||
});
|
},
|
||||||
|
undefined,
|
||||||
|
);
|
||||||
expect(result).toEqualPayload({
|
expect(result).toEqualPayload({
|
||||||
dummy: 'dummy test 5',
|
dummy: 'dummy test 5',
|
||||||
});
|
});
|
||||||
|
@ -58,6 +58,7 @@ describe('BaseService', () => {
|
|||||||
expect(dummyRepository.findOne).toHaveBeenCalledWith(
|
expect(dummyRepository.findOne).toHaveBeenCalledWith(
|
||||||
createdId,
|
createdId,
|
||||||
undefined,
|
undefined,
|
||||||
|
undefined,
|
||||||
);
|
);
|
||||||
expect(result).toEqualPayload(createdPayload);
|
expect(result).toEqualPayload(createdPayload);
|
||||||
});
|
});
|
||||||
@ -69,6 +70,7 @@ describe('BaseService', () => {
|
|||||||
expect(dummyRepository.findOne).toHaveBeenCalledWith(
|
expect(dummyRepository.findOne).toHaveBeenCalledWith(
|
||||||
createdPayload,
|
createdPayload,
|
||||||
undefined,
|
undefined,
|
||||||
|
undefined,
|
||||||
);
|
);
|
||||||
expect(result).toEqualPayload(createdPayload);
|
expect(result).toEqualPayload(createdPayload);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user