UNPKG

@tomei/sso

Version:
58 lines 3.73 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_reporting_user_1 = require("../../../../src/components/group-reporting-user/group-reporting-user"); const group_reporting_user_repository_1 = require("../../../../src/components/group-reporting-user/group-reporting-user.repository"); const general_1 = require("@tomei/general"); describe('GroupReportingUser', () => { const mockGroupReportingUserAttr = { GroupReportingUserId: 1, GroupCode: 'test', UserId: 1, Rank: 1, Status: 'active', CreatedById: 1, CreatedAt: new Date(), UpdatedById: 1, UpdatedAt: new Date(), }; beforeEach(() => __awaiter(void 0, void 0, void 0, function* () { jest.clearAllMocks(); })); describe('init', () => { const mockDbTransaction = {}; it('should initialize GroupReportingUser without GroupReportingUserId', () => __awaiter(void 0, void 0, void 0, function* () { const initGroupReportingUser = yield group_reporting_user_1.GroupReportingUser.init(mockDbTransaction); expect(initGroupReportingUser).toBeDefined(); expect(initGroupReportingUser).toBeInstanceOf(group_reporting_user_1.GroupReportingUser); })); it('should initialize GroupReportingUser with valid GroupReportingUserId', () => __awaiter(void 0, void 0, void 0, function* () { const mockFindByPk = jest .spyOn(group_reporting_user_repository_1.GroupReportingUserRepository.prototype, 'findByPk') .mockResolvedValue(Object.assign(Object.assign({}, mockGroupReportingUserAttr), { get: () => mockGroupReportingUserAttr })); const initGroupReportingUser = yield group_reporting_user_1.GroupReportingUser.init(mockDbTransaction, '1'); expect(initGroupReportingUser).toBeDefined(); expect(initGroupReportingUser).toBeInstanceOf(group_reporting_user_1.GroupReportingUser); expect(mockFindByPk).toHaveBeenCalledWith('1', { transaction: mockDbTransaction, }); })); it('should throw ClassError when GroupReportingUser is not found', () => __awaiter(void 0, void 0, void 0, function* () { jest.spyOn(group_reporting_user_repository_1.GroupReportingUserRepository.prototype, 'findByPk').mockResolvedValue(null); yield expect(group_reporting_user_1.GroupReportingUser.init(mockDbTransaction, '1')).rejects.toThrowError(general_1.ClassError); })); it('should throw ClassError when failed to initialize GroupReportingUser', () => __awaiter(void 0, void 0, void 0, function* () { jest.spyOn(group_reporting_user_repository_1.GroupReportingUserRepository.prototype, 'findByPk').mockRejectedValue(new Error()); yield expect(group_reporting_user_1.GroupReportingUser.init(mockDbTransaction, '1')).rejects.toThrowError(general_1.ClassError); })); }); }); //# sourceMappingURL=group-reporting-user.spec.js.map