UNPKG

@tomei/sso

Version:
76 lines 4.21 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_privilege_1 = require("../../../../src/components/user-privilege/user-privilege"); const user_privilege_repository_1 = require("../../../../src/components/user-privilege/user-privilege.repository"); const general_1 = require("@tomei/general"); describe('UserPrivilege', () => { let userPrivilege; const userPrivilegeAttr = { UserPrivilegeId: 1, UserId: 1, SystemPrivilegeId: 'privilege1', Status: 'active', CreatedById: 1, CreatedAt: new Date(), UpdatedById: 1, UpdatedAt: new Date(), }; beforeEach(() => { userPrivilege = new user_privilege_1.UserPrivilege(userPrivilegeAttr); }); afterEach(() => { jest.clearAllMocks(); }); describe('constructor', () => { it('should create a new UserPrivilege instance', () => { expect(userPrivilege).toBeDefined(); expect(userPrivilege).toBeInstanceOf(user_privilege_1.UserPrivilege); expect(userPrivilege.UserPrivilegeId).toBe(userPrivilegeAttr.UserPrivilegeId); expect(userPrivilege.UserId).toBe(userPrivilegeAttr.UserId); expect(userPrivilege.SystemPrivilegeId).toBe(userPrivilegeAttr.SystemPrivilegeId); expect(userPrivilege.Status).toBe(userPrivilegeAttr.Status); expect(userPrivilege.CreatedById).toBe(userPrivilegeAttr.CreatedById); expect(userPrivilege.CreatedAt).toBe(userPrivilegeAttr.CreatedAt); expect(userPrivilege.UpdatedById).toBe(userPrivilegeAttr.UpdatedById); expect(userPrivilege.UpdatedAt).toBe(userPrivilegeAttr.UpdatedAt); }); }); describe('init', () => { it('should initialize UserPrivilege with valid UserPrivilegeId', () => __awaiter(void 0, void 0, void 0, function* () { const findOneMock = jest .spyOn(user_privilege_repository_1.UserPrivilegeRepository.prototype, 'findOne') .mockResolvedValueOnce(userPrivilegeAttr); const result = yield user_privilege_1.UserPrivilege.init(null, 1); expect(findOneMock).toHaveBeenCalledTimes(1); expect(findOneMock).toHaveBeenCalledWith({ where: { UserPrivilegeId: 1 }, transaction: null, }); expect(result).toBeInstanceOf(user_privilege_1.UserPrivilege); expect(result.UserPrivilegeId).toBe(userPrivilegeAttr.UserPrivilegeId); expect(result.UserId).toBe(userPrivilegeAttr.UserId); expect(result.SystemPrivilegeId).toBe(userPrivilegeAttr.SystemPrivilegeId); expect(result.Status).toBe(userPrivilegeAttr.Status); expect(result.CreatedById).toBe(userPrivilegeAttr.CreatedById); expect(result.CreatedAt).toBe(userPrivilegeAttr.CreatedAt); expect(result.UpdatedById).toBe(userPrivilegeAttr.UpdatedById); expect(result.UpdatedAt).toBe(userPrivilegeAttr.UpdatedAt); })); it('should throw ClassError when UserPrivilegeId is not found', () => __awaiter(void 0, void 0, void 0, function* () { jest .spyOn(user_privilege_repository_1.UserPrivilegeRepository.prototype, 'findOne') .mockResolvedValueOnce(null); yield expect(user_privilege_1.UserPrivilege.init(null, 1)).rejects.toThrow(general_1.ClassError); })); }); }); //# sourceMappingURL=user-privilege.spec.js.map