UNPKG

@tomei/sso

Version:
83 lines 5.46 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const group_system_access_1 = require("../../../../src/components/group-system-access/group-system-access"); const group_system_access_repository_1 = require("../../../../src/components/group-system-access/group-system-access.repository"); const general_1 = require("@tomei/general"); describe('GroupSystemAccess', () => { let 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 group_system_access_1.GroupSystemAccess(groupSystemAccessAttr); }); it('should create a new GroupSystemAccess instance', () => { expect(groupSystemAccess).toBeDefined(); expect(groupSystemAccess).toBeInstanceOf(group_system_access_1.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', () => __awaiter(void 0, void 0, void 0, function* () { const groupSystemAccess = yield group_system_access_1.GroupSystemAccess.init(null); expect(groupSystemAccess).toBeDefined(); expect(groupSystemAccess).toBeInstanceOf(group_system_access_1.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', () => __awaiter(void 0, void 0, void 0, function* () { const findOneSpy = jest .spyOn(group_system_access_repository_1.GroupSystemAccessRepository.prototype, 'findOne') .mockResolvedValue(Object.assign(Object.assign({}, groupSystemAccessAttr), { get: () => groupSystemAccessAttr })); const groupSystemAccess = yield group_system_access_1.GroupSystemAccess.init(null, 1); expect(findOneSpy).toHaveBeenCalledWith({ where: { GroupSystemAccessId: 1 }, transaction: null, }); expect(groupSystemAccess).toBeDefined(); expect(groupSystemAccess).toBeInstanceOf(group_system_access_1.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', () => __awaiter(void 0, void 0, void 0, function* () { jest.spyOn(group_system_access_repository_1.GroupSystemAccessRepository.prototype, 'findOne').mockResolvedValue(null); yield expect(group_system_access_1.GroupSystemAccess.init(null, 1)).rejects.toThrow(new general_1.ClassError('groupSystemAccess', 'groupSystemAccessErrMsg00', 'groupSystemAccess not found')); })); }); }); //# sourceMappingURL=group-system-access.spec.js.map