UNPKG

boldsign

Version:

NodeJS client for boldsign

160 lines 7.74 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); 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()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const identityVerificationApi_1 = require("../../api/identityVerificationApi"); const documentApi_1 = require("../../api/documentApi"); const model_1 = require("../../model"); const fs = __importStar(require("fs")); const config_1 = __importDefault(require("../config")); describe('Document API Test Suite', () => { let identityVerificationApi; let documentApi; let createdDocumentId; beforeAll(() => { createdDocumentId = null; const apiKey = config_1.default.apiKey; const baseUrl = config_1.default.baseUrl; if (!apiKey || !baseUrl) { throw new Error("Environment variables 'API_KEY' or 'HOST_URL' are not set."); } documentApi = new documentApi_1.DocumentApi(baseUrl); documentApi.setApiKey(apiKey); identityVerificationApi = new identityVerificationApi_1.IdentityVerificationApi(baseUrl); identityVerificationApi.setApiKey(apiKey); }); test('Test1:should send a document with identity verification', () => __awaiter(void 0, void 0, void 0, function* () { try { const signer = new model_1.DocumentSigner(); signer.name = 'Test Signer'; signer.emailAddress = 'sivaramani.sivaraj@syncfusion.com'; signer.signerOrder = 1; signer.signerType = model_1.DocumentSigner.SignerTypeEnum.Signer; signer.authenticationType = model_1.DocumentSigner.AuthenticationTypeEnum.IdVerification; const formField = new model_1.FormField(); formField.name = 'Sign'; formField.fieldType = model_1.FormField.FieldTypeEnum.Signature; formField.font = model_1.FormField.FontEnum.Helvetica; formField.pageNumber = 1; formField.isRequired = true; const bounds = new model_1.Rectangle(); bounds.x = 50; bounds.y = 50; bounds.width = 200; bounds.height = 50; formField.bounds = bounds; signer.formFields = [formField]; signer.privateMessage = 'This is a private message for signer'; const idVerificationSettings = new model_1.IdentityVerificationSettings(); idVerificationSettings.type = model_1.IdentityVerificationSettings.TypeEnum.EveryAccess; idVerificationSettings.maximumRetryCount = 2; const sendDocumentRequest = new model_1.SendForSign(); sendDocumentRequest.title = 'Document SDK API - ID Verification'; sendDocumentRequest.files = [fs.createReadStream('tests/documents/agreement.pdf')]; sendDocumentRequest.enablePrintAndSign = true; sendDocumentRequest.signers = [signer]; sendDocumentRequest.message = 'Please verify your identity and sign this document'; const response = yield documentApi.sendDocument(sendDocumentRequest); expect(response.documentId).toBeDefined(); createdDocumentId = response.documentId; console.log('Document sent with ID verification. Document ID:', createdDocumentId); } catch (error) { console.error('Error occurred while sending document with identity verification:', error); expect(error).toBeUndefined(); } }), 7000000); test('Test2:should fail to create an embedded verification URL with invalid document ID', () => __awaiter(void 0, void 0, void 0, function* () { const manualVerification = { emailId: 'sivaramani.sivaraj@syncfusion.com', countryCode: '+91', phoneNumber: '8807799764', redirectUrl: 'https://www.boldsign.com', order: 1 }; try { const response = yield identityVerificationApi.createEmbeddedVerificationUrl(createdDocumentId, manualVerification); fail('Expected 400 Bad Request error, but the API call succeeded.'); } catch (error) { console.error(error); expect(error).toBeDefined(); } }), 700000); test('Test3:should fail when requesting verification report with invalid or unauthorized data', () => __awaiter(void 0, void 0, void 0, function* () { const requestData = { emailId: 'sivaramani.sivaraj@syncfusion.com', countryCode: '+91', phoneNumber: '8807799764', order: 1 }; try { yield identityVerificationApi.report(createdDocumentId, requestData); fail('Expected 403 Forbidden error, but the API call succeeded.'); } catch (error) { expect(error).toBeDefined(); } }), 700000); test('Test4:should fail invalid file ID in image download request', () => __awaiter(void 0, void 0, void 0, function* () { const imageRequest = { emailId: 'sivaramani.sivaraj@syncfusion.com', countryCode: '+91', phoneNumber: '8807799764', fileId: 'invalid-file-id', order: 1 }; try { const imageResponse = yield identityVerificationApi.image(createdDocumentId, imageRequest); console.log('Unexpectedly received image response:', imageResponse); fail('Expected 403 Forbidden error, but the API call succeeded.'); } catch (error) { expect(error).toBeDefined(); } }), 700000); }); //# sourceMappingURL=IdentityVerificationApiTest.spec.js.map