UNPKG

@tomei/sso

Version:
85 lines 5.25 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 system_privilege_1 = require("../../../../src/components/system-privilege/system-privilege"); const system_privilege_repository_1 = require("../../../../src/components/system-privilege/system-privilege.repository"); const general_1 = require("@tomei/general"); describe('SystemPrivilege', () => { let systemPrivilege; const systemPrivilegeAttr = { PrivilegeCode: 'test', SystemCode: 'test', Name: 'test', Description: 'test', Status: 'test', CreatedById: 1, CreatedAt: new Date(), UpdatedById: 1, UpdatedAt: new Date(), }; beforeEach(() => { jest.resetAllMocks(); }); describe('constructor', () => { it('should create a new SystemPrivilege instance', () => { systemPrivilege = new system_privilege_1.SystemPrivilege(systemPrivilegeAttr); expect(systemPrivilege).toBeDefined(); expect(systemPrivilege).toBeInstanceOf(system_privilege_1.SystemPrivilege); expect(systemPrivilege.PrivilegeCode).toBe(systemPrivilegeAttr.PrivilegeCode); expect(systemPrivilege.SystemCode).toBe(systemPrivilegeAttr.SystemCode); expect(systemPrivilege.Description).toBe(systemPrivilegeAttr.Description); expect(systemPrivilege.Status).toBe(systemPrivilegeAttr.Status); expect(systemPrivilege.CreatedById).toBe(systemPrivilegeAttr.CreatedById); expect(systemPrivilege.CreatedAt).toBe(systemPrivilegeAttr.CreatedAt); expect(systemPrivilege.UpdatedById).toBe(systemPrivilegeAttr.UpdatedById); expect(systemPrivilege.UpdatedAt).toBe(systemPrivilegeAttr.UpdatedAt); }); }); describe('init', () => { it('should initialize SystemPrivilege without PrivilegeCode', () => __awaiter(void 0, void 0, void 0, function* () { const systemPrivilege = yield system_privilege_1.SystemPrivilege.init(null); expect(systemPrivilege).toBeDefined(); expect(systemPrivilege).toBeInstanceOf(system_privilege_1.SystemPrivilege); expect(systemPrivilege.PrivilegeCode).toBeUndefined(); expect(systemPrivilege.SystemCode).toBeUndefined(); expect(systemPrivilege.Description).toBeUndefined(); expect(systemPrivilege.Status).toBeUndefined(); expect(systemPrivilege.CreatedById).toBeUndefined(); expect(systemPrivilege.CreatedAt).toBeUndefined(); expect(systemPrivilege.UpdatedById).toBeUndefined(); expect(systemPrivilege.UpdatedAt).toBeUndefined(); })); it('should initialize SystemPrivilege with PrivilegeCode', () => __awaiter(void 0, void 0, void 0, function* () { const findByPkSpy = jest .spyOn(system_privilege_repository_1.SystemPrivilegeRepository.prototype, 'findByPk') .mockResolvedValue(systemPrivilegeAttr); const systemPrivilege = yield system_privilege_1.SystemPrivilege.init(null, 'test'); expect(findByPkSpy).toHaveBeenCalledWith('test', { transaction: null, }); expect(systemPrivilege).toBeDefined(); expect(systemPrivilege).toBeInstanceOf(system_privilege_1.SystemPrivilege); expect(systemPrivilege.PrivilegeCode).toBe(systemPrivilegeAttr.PrivilegeCode); expect(systemPrivilege.SystemCode).toBe(systemPrivilegeAttr.SystemCode); expect(systemPrivilege.Description).toBe(systemPrivilegeAttr.Description); expect(systemPrivilege.Status).toBe(systemPrivilegeAttr.Status); expect(systemPrivilege.CreatedById).toBe(systemPrivilegeAttr.CreatedById); expect(systemPrivilege.CreatedAt).toBe(systemPrivilegeAttr.CreatedAt); expect(systemPrivilege.UpdatedById).toBe(systemPrivilegeAttr.UpdatedById); expect(systemPrivilege.UpdatedAt).toBe(systemPrivilegeAttr.UpdatedAt); })); it('should throw an error if PrivilegeCode is not found', () => __awaiter(void 0, void 0, void 0, function* () { jest.spyOn(system_privilege_repository_1.SystemPrivilegeRepository.prototype, 'findByPk').mockResolvedValue(null); yield expect(system_privilege_1.SystemPrivilege.init(null, 'test')).rejects.toThrow(new general_1.ClassError('SystemPrivilege', 'SystemPrivilegeErrMsg00', 'System Privilege Not Found')); })); }); }); //# sourceMappingURL=system-privilege.spec.js.map