@tomei/sso
Version:
Tomei SSO Package
84 lines (76 loc) • 4.01 kB
text/typescript
import { GroupSystemAccess } from '../../../../src/components/group-system-access/group-system-access';
import { GroupSystemAccessRepository } from '../../../../src/components/group-system-access/group-system-access.repository';
import { ClassError } from '@tomei/general';
describe('GroupSystemAccess', () => {
let groupSystemAccess: GroupSystemAccess;
const groupSystemAccessAttr = {
GroupSystemAccessId: 1,
GroupCode: 'test',
SystemCode: 'test',
Status: 'test',
CreatedById: 1,
CreatedAt: new Date(),
UpdatedById: 1,
UpdatedAt: new Date(),
};
beforeEach(() => {
jest.resetAllMocks();
groupSystemAccess = new GroupSystemAccess(groupSystemAccessAttr);
});
it('should create a new GroupSystemAccess instance', () => {
expect(groupSystemAccess).toBeDefined();
expect(groupSystemAccess).toBeInstanceOf(GroupSystemAccess);
expect(groupSystemAccess.GroupSystemAccessId).toBe(groupSystemAccessAttr.GroupSystemAccessId);
expect(groupSystemAccess.GroupCode).toBe(groupSystemAccessAttr.GroupCode);
expect(groupSystemAccess.SystemCode).toBe(groupSystemAccessAttr.SystemCode);
expect(groupSystemAccess.Status).toBe(groupSystemAccessAttr.Status);
expect(groupSystemAccess.CreatedById).toBe(groupSystemAccessAttr.CreatedById);
expect(groupSystemAccess.CreatedAt).toBe(groupSystemAccessAttr.CreatedAt);
expect(groupSystemAccess.UpdatedById).toBe(groupSystemAccessAttr.UpdatedById);
expect(groupSystemAccess.UpdatedAt).toBe(groupSystemAccessAttr.UpdatedAt);
});
describe('init', () => {
it('should initialize GroupSystemAccess without GroupSystemAccessId', async () => {
const groupSystemAccess = await GroupSystemAccess.init(null);
expect(groupSystemAccess).toBeDefined();
expect(groupSystemAccess).toBeInstanceOf(GroupSystemAccess);
expect(groupSystemAccess.GroupSystemAccessId).toBeUndefined();
expect(groupSystemAccess.GroupCode).toBeUndefined();
expect(groupSystemAccess.SystemCode).toBeUndefined();
expect(groupSystemAccess.Status).toBeUndefined();
expect(groupSystemAccess.CreatedById).toBeUndefined();
expect(groupSystemAccess.CreatedAt).toBeUndefined();
expect(groupSystemAccess.UpdatedById).toBeUndefined();
expect(groupSystemAccess.UpdatedAt).toBeUndefined();
});
it('should initialize GroupSystemAccess with GroupSystemAccessId', async () => {
const findOneSpy = jest
.spyOn(GroupSystemAccessRepository.prototype, 'findOne')
.mockResolvedValue({
...groupSystemAccessAttr,
get: () => groupSystemAccessAttr,
} as any);
const groupSystemAccess = await GroupSystemAccess.init(null, 1);
expect(findOneSpy).toHaveBeenCalledWith({
where: { GroupSystemAccessId: 1 },
transaction: null,
});
expect(groupSystemAccess).toBeDefined();
expect(groupSystemAccess).toBeInstanceOf(GroupSystemAccess);
expect(groupSystemAccess.GroupSystemAccessId).toBe(groupSystemAccessAttr.GroupSystemAccessId);
expect(groupSystemAccess.GroupCode).toBe(groupSystemAccessAttr.GroupCode);
expect(groupSystemAccess.SystemCode).toBe(groupSystemAccessAttr.SystemCode);
expect(groupSystemAccess.Status).toBe(groupSystemAccessAttr.Status);
expect(groupSystemAccess.CreatedById).toBe(groupSystemAccessAttr.CreatedById);
expect(groupSystemAccess.CreatedAt).toBe(groupSystemAccessAttr.CreatedAt);
expect(groupSystemAccess.UpdatedById).toBe(groupSystemAccessAttr.UpdatedById);
expect(groupSystemAccess.UpdatedAt).toBe(groupSystemAccessAttr.UpdatedAt);
});
it('should throw an error if GroupSystemAccessId is not found', async () => {
jest.spyOn(GroupSystemAccessRepository.prototype, 'findOne').mockResolvedValue(null);
await expect(GroupSystemAccess.init(null, 1)).rejects.toThrow(
new ClassError('groupSystemAccess', 'groupSystemAccessErrMsg00', 'groupSystemAccess not found'),
);
});
});
});