UNPKG

@tomei/sso

Version:
82 lines 4.4 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 user_group_1 = require("../../../../src/components/user-group/user-group"); const user_group_repository_1 = require("../../../../src/components/user-group/user-group.repository"); const general_1 = require("@tomei/general"); describe('UserGroup', () => { let userGroup; const userGroupAttr = { UserGroupId: 1, UserId: 1, GroupCode: 'group1', Status: 'active', InheritGroupPrivilegeYN: 'yes', InheritGroupSystemAccessYN: 'yes', CreatedById: 1, CreatedAt: new Date(), UpdatedById: 1, UpdatedAt: new Date(), }; beforeEach(() => { userGroup = new user_group_1.UserGroup(userGroupAttr); }); afterEach(() => { jest.clearAllMocks(); }); describe('constructor', () => { it('should create a new UserGroup instance', () => { expect(userGroup).toBeDefined(); expect(userGroup).toBeInstanceOf(user_group_1.UserGroup); expect(userGroup.UserGroupId).toBe(userGroupAttr.UserGroupId); expect(userGroup.UserId).toBe(userGroupAttr.UserId); expect(userGroup.GroupCode).toBe(userGroupAttr.GroupCode); expect(userGroup.Status).toBe(userGroupAttr.Status); expect(userGroup.InheritGroupPrivilegeYN).toBe(userGroupAttr.InheritGroupPrivilegeYN); expect(userGroup.InheritGroupSystemAccessYN).toBe(userGroupAttr.InheritGroupSystemAccessYN); expect(userGroup.CreatedById).toBe(userGroupAttr.CreatedById); expect(userGroup.CreatedAt).toBe(userGroupAttr.CreatedAt); expect(userGroup.UpdatedById).toBe(userGroupAttr.UpdatedById); expect(userGroup.UpdatedAt).toBe(userGroupAttr.UpdatedAt); }); }); describe('init', () => { it('should initialize UserGroup with valid UserGroupId', () => __awaiter(void 0, void 0, void 0, function* () { const findOneMock = jest .spyOn(user_group_repository_1.UserGroupRepository.prototype, 'findOne') .mockResolvedValueOnce(userGroupAttr); const result = yield user_group_1.UserGroup.init(null, 1); expect(findOneMock).toHaveBeenCalledTimes(1); expect(findOneMock).toHaveBeenCalledWith({ where: { UserGroupId: 1 }, transaction: null, }); expect(result).toBeInstanceOf(user_group_1.UserGroup); expect(result.UserGroupId).toBe(userGroupAttr.UserGroupId); expect(result.UserId).toBe(userGroupAttr.UserId); expect(result.GroupCode).toBe(userGroupAttr.GroupCode); expect(result.Status).toBe(userGroupAttr.Status); expect(result.InheritGroupPrivilegeYN).toBe(userGroupAttr.InheritGroupPrivilegeYN); expect(result.InheritGroupSystemAccessYN).toBe(userGroupAttr.InheritGroupSystemAccessYN); expect(result.CreatedById).toBe(userGroupAttr.CreatedById); expect(result.CreatedAt).toBe(userGroupAttr.CreatedAt); expect(result.UpdatedById).toBe(userGroupAttr.UpdatedById); expect(result.UpdatedAt).toBe(userGroupAttr.UpdatedAt); })); it('should throw ClassError when UserGroupId is not found', () => __awaiter(void 0, void 0, void 0, function* () { jest .spyOn(user_group_repository_1.UserGroupRepository.prototype, 'findOne') .mockResolvedValueOnce(null); yield expect(user_group_1.UserGroup.init(null, 1)).rejects.toThrow(general_1.ClassError); })); }); }); //# sourceMappingURL=user-group.spec.js.map