2022-05-06 (C) Questetra, Inc. (MIT License) 2 This item creates a signing document from the specified file on Box and sends a sign request. この工程は、Box 上のファイルから署名用ドキュメントを作成し、署名リクエストを送信します。 https://support.questetra.com/bpmn-icons/service-task-box-sign-request-create/ https://support.questetra.com/ja/bpmn-icons/service-task-box-sign-request-create/ iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAEBElEQVRYR82Xb2jbRRjHP/fL2jXJ 0qSd65x11aK0YgJWZUwEWZ0DfSNaHYKKmgykbP7pH/SVghvCkIlb6kREwfyGOougbgxB2Yt1oGwg aietdOJoV21ty2ob26xdm+TkLsufJr+2Sdtt3pv8uDx3z+ee+z53zwmucRMF+ff/9ijEtwB1IDwI 9QtIOkGOA50I0UHIezTfeRcH8Pd64GITyGaE8OQ1sVQwIgiONsxqBTZvWxjA3+UHDuTtONuNBjEC mLcfmY9gfgB/dxBBU14rXsxIyiCmr8XKzBog0GWCeG6xeQv6X2JiegPZY3IBVnLlOVtCG6a3ObN7 LoDacyFCBa2sUGMpGjI1kQbQao/0Lllw+YJoYTqrk9mRAdC9G8Eb+c6zLDvJHkzvbjVHGiDQpXLX nZw4tOMGyp02Hjn457J8WQ5WUTB9ZWkAdcIJ+XWm8XCwFkexwLWrZ+UB9OmZ0EIiAhbKH2lLAKzZ eaUAEhmRAAh0dYBQZ3yqKQDnaoPDp8PUVZXo/pM9EV75Ylh/77q/jO2bSlmz2mBgLErjoUHad95I Z/80re0Jmw+e3UD1dcU8uP+8RRTlSUK++ssA3X3ATdkA61y2nIE/9k7Rd2GWx+4uxWZkAP8bo9Ru YAho+XyIUruNNxsqiMzE8bxgEUV1gZneO5MAMtuTioACUM7e+W4Uj8Pg5W1rdV9cwvSsxPx+nNPn LvLStnI2VdsZi8TwOGyMTsY0nNth493j/9DSPmSto5BXLAigsmDLW7388MeUnuDVh9ay74n1+vvI zxM0vJfOkNGDtdiLDH7pn+beW+3a5kRPhK37rMJ/mScDIGcLBvfXsM61isrWs4xMxPSIpza7+ayx Un8rbTz94UBqZX8fqNFp+82vkzTc5dL9n54K88xHaZu5YZBnCPnq5hXhqdequecWO2rPH3j7PBvc qzjWVEXN9cV6HhVmJbwvf5rgcGMlT2526y1wldiYiUl9wKhtUHp4/8TYIiK0SMP6WgdfvbiRMqeN yKU4NkNQUiToH51lcDyq4aIxtMjcdoOpGYkSkrJpOz6qt6OxvowLkzEqms7mAsjMNLQ4iNSIrbc5 2bu9QqdSNC7pHrjEjo8H+GssyifPV3JfjQNHscFQOMqeoyPsfXw9vw/P8HBbv3b4bWsVG8uL8L5+ zgIg8yBSf2cdxdayXaleGSbk0+Xd/+gyUtexiPRlXkgrtd4s9YeRzptzr2NldU0LkiTmlS3JUnVA 0t3VK0qRhwj5VJk/p12lsjxdAeUPoDWhCpW4KtFTlVJhwpRhpOFf2sMkpQn9NGtGyOb8QZRj/TQL Lu9plr1c/TiV9QipHqUeEHckTOQZYBwpOkF0LLTiwragsHgvyfo/g3CBMFgjn40AAAAASUVORK5C YII= { configs.put('conf_OAuth2', 'Box Sign'); // ファイル ID を設定した文字型データ項目(単一行)を準備し、設定 const fileIdDef = engine.createDataDefinition('ファイル ID', 1, 'q_FileId', 'STRING_TEXTFIELD'); engine.setData(fileIdDef, fileId); configs.putObject('conf_SourceFileId', fileIdDef); // フォルダ ID を設定した文字型データ項目(単一行)を準備し、設定 const folderIdDef = engine.createDataDefinition('フォルダ ID', 2, 'q_FolderId', 'STRING_TEXTFIELD'); engine.setData(folderIdDef, folderId); configs.putObject('conf_FolderId', folderIdDef); // メールアドレスを設定した文字型データ項目(複数行)を準備し、設定 const emailDef = engine.createDataDefinition('メールアドレス', 3, 'q_EmailAddress', 'STRING_TEXTAREA'); engine.setData(emailDef, emails); configs.putObject('conf_EmailAddress', emailDef); // パスワードを設定した文字型データ項目(複数行)を準備し、設定 const passwordDef = engine.createDataDefinition('パスワード', 4, 'q_Password', 'STRING_TEXTAREA'); engine.setData(passwordDef, passwords); configs.putObject('conf_Password', passwordDef); // メールの件名、メッセージを設定 configs.put('conf_EmailSubject', subject); configs.put('conf_EmailMessage', message); } /** * ファイル ID をデータ項目で指定し、値が空でエラー */ test('Source File ID is blank', () => { prepareConfigs(null, 'folderId-1', 'test1@example.com', 'password1', '', ''); expect(execute).toThrow('Source File ID is blank.'); }); /** * フォルダ ID をデータ項目で指定し、値が空でエラー */ test('Folder ID is blank', () => { prepareConfigs('fileId-1', null, 'test1@example.com', 'password1', '', ''); expect(execute).toThrow('Folder ID is blank.'); }); /** * フォルダ ID に 0 (ルートフォルダの ID) を指定しエラー */ test('Root folder cannot be used', () => { prepareConfigs('fileId-1', '0', 'test1@example.com', 'password1', '', ''); expect(execute).toThrow('Root folder cannot be used.'); }); /** * メールアドレスが空でエラー */ test('No Email Address - Data item is set but its content is empty', () => { prepareConfigs('fileId-1', 'folderId-1', null, 'password1', '', ''); expect(execute).toThrow('Data item for Email Address is set but its content is empty.'); }); /** * メールアドレスが改行のみでエラー */ test('No Email Address - A blank line', () => { prepareConfigs('fileId-1', 'folderId-1', '\n', 'password1', '', ''); expect(execute).toThrow('Email Address at line 1 is blank.'); }); /** * メールアドレスが 35 件を超えていてエラー */ test('Number of Email Addresses exceeds the limit', () => { const emails = 'test@example.com\n'.repeat(36); const passwords = 'password\n'.repeat(36); prepareConfigs('fileId-1', 'folderId-1', emails, passwords, '', ''); expect(execute).toThrow('Number of Email Addresses exceeds the limit. The maximum number is 35.'); }); /** * メールアドレスの途中に空行がありエラー */ test('An Email Address is blank', () => { const emails = 'test1@example.com\n\ntest2@example.com'; // 2 件。2行目が空行 const passwords = 'password1\npassword2'; // 2件 prepareConfigs('fileId-1', 'folderId-1', emails, passwords, '', ''); expect(execute).toThrow('Email Address at line 2 is blank.'); }); /** * パスワードが空でエラー */ test('Data item for Password is set but its content is empty', () => { prepareConfigs('fileId-1', 'folderId-1', 'test1@example.com', null, '', ''); expect(execute).toThrow('Data item for Password is set but its content is empty.'); }); /** * パスワードの途中に空行がありエラー */ test('A Password is blank', () => { const emails = 'test1@example.com\ntest2@example.com'; // 2 件 const passwords = '\npassword1\npassword2'; // 2件。先頭に空行がある prepareConfigs('fileId-1', 'folderId-1', emails, passwords, '', ''); expect(execute).toThrow('Password at line 1 is blank.'); }); /** * パスワードが改行のみでエラー */ test('No Password - A blank line', () => { prepareConfigs('fileId-1', 'folderId-1', 'test1@example.com', '\n', '', ''); expect(execute).toThrow('Password at line 1 is blank.'); }); /** * メールアドレスとパスワードの件数が一致せずエラー */ test('Number of Passwords does not match the number of Email Addresses', () => { const emails = 'test1@example.com\ntest2@example.com\ntest3@example.com'; // 3 件 const passwords = 'password1\npassword2'; // 2件 prepareConfigs('fileId-1', 'folderId-1', emails, passwords, '', ''); expect(execute).toThrow('Number of Passwords does not match the number of Email Addresses.'); }); /** * POST リクエストのテスト * @param {Object} request * @param request.url * @param request.method * @param request.contentType * @param request.body * @param fileId * @param folderId * @param signers * @param subject * @param message */ const assertPostRequest = ({url, method, contentType, body}, fileId, folderId, signers, subject, message) => { expect(url).toEqual('https://api.box.com/2.0/sign_requests'); expect(method).toEqual('POST'); expect(contentType).toEqual('application/json; charset=UTF-8'); const bodyObj = JSON.parse(body); expect(bodyObj.source_files[0].id).toEqual(fileId); expect(bodyObj.source_files[0].type).toEqual('file'); expect(bodyObj.parent_folder.id).toEqual(folderId); expect(bodyObj.parent_folder.type).toEqual('folder'); expect(bodyObj.signers).toEqual(signers); if (subject !== '') { expect(bodyObj.email_subject).toEqual(subject); } else { expect(bodyObj.email_subject).toEqual(undefined); } if (message !== '') { expect(bodyObj.email_message).toEqual(message); } else { expect(bodyObj.email_message).toEqual(undefined); } }; /** * POST リクエストで失敗 */ test('Fail in POST Request', () => { const email = 'test1@example.com'; const password = 'password1'; const signers = [{email, password}]; prepareConfigs('fileId-1', 'folderId-1', email, password, '', ''); httpClient.setRequestHandler((request) => { assertPostRequest(request, 'fileId-1', 'folderId-1', signers, '', ''); return httpClient.createHttpResponse(400, 'application/json', '{}'); }); expect(execute).toThrow('Failed to create Sign Request. status:400'); }); /** * 署名リクエスト作成成功 * Box Sign の上限 35 件の署名者でテスト * パスワード設定あり */ test('Success - 35 signers with passwords', () => { const emails = []; const passwords = []; const signers = []; for (let i = 0; i < 35; i++) { const email = `test${i+1}@example.com`; const password = `password${i+1}` emails.push(email); passwords.push(password); signers.push({email, password}); } const emailString = emails.join('\n') + '\n'; // 末尾の改行は無視される const passwordString = passwords.join('\n'); prepareConfigs('fileId-1', 'folderId-1', emailString, passwordString, '', ''); httpClient.setRequestHandler((request) => { assertPostRequest(request, 'fileId-1', 'folderId-1', signers, '', ''); return httpClient.createHttpResponse(201, 'application/json', '{}'); }); execute(); }); /** * 署名リクエスト作成成功 * メールアドレスを単一行データ項目で指定 * パスワード設定あり */ test('Success - Email Address set with TEXTFIELD', () => { const email = 'test2@example.com'; const password = 'password2'; const signers = [{email, password}]; // メールアドレスはいったん null に prepareConfigs('fileId-2', 'folderId-2', null, password, '', ''); // メールアドレスを設定した文字型データ項目(単一行)を準備し、設定 const emailDef = engine.createDataDefinition('メールアドレス (単一行)', 5, 'q_EmailAddressSingle', 'STRING_TEXTFIELD'); engine.setData(emailDef, email); configs.putObject('conf_EmailAddress', emailDef); httpClient.setRequestHandler((request) => { assertPostRequest(request, 'fileId-2', 'folderId-2', signers, '', ''); return httpClient.createHttpResponse(201, 'application/json', '{}'); }); execute(); }); /** * 署名リクエスト作成成功 * パスワードを単一行データ項目で指定 */ test('Success - Password set with TEXTFIELD', () => { const email = 'test3@example.com'; const password = 'password3'; const signers = [{email, password}]; // パスワードはいったん null に prepareConfigs('fileId-3', 'folderId-3', email, null, '', ''); // メールアドレスを設定した文字型データ項目(単一行)を準備し、設定 const passwordDef = engine.createDataDefinition('パスワード (単一行)', 5, 'q_PasswordSingle', 'STRING_TEXTFIELD'); engine.setData(passwordDef, password); configs.putObject('conf_Password', passwordDef); httpClient.setRequestHandler((request) => { assertPostRequest(request, 'fileId-3', 'folderId-3', signers, '', ''); return httpClient.createHttpResponse(201, 'application/json', '{}'); }); execute(); }); /** * 署名リクエスト作成成功 * パスワードを指定しない */ test('Success - Without passwords', () => { const emails = []; const signers = []; for (let i = 0; i < 5; i++) { const email = `test${i+1}@example.com`; emails.push(email); signers.push({email}); } const emailString = emails.join('\n'); // パスワードはいったん null に prepareConfigs('fileId-3', 'folderId-3', emailString, null, '', ''); // パスワードの設定をクリア configs.put('conf_Password', ''); httpClient.setRequestHandler((request) => { assertPostRequest(request, 'fileId-3', 'folderId-3', signers, '', ''); return httpClient.createHttpResponse(201, 'application/json', '{}'); }); execute(); }); /** * 署名リクエスト作成成功 * メールの件名、メッセージを指定 */ test('Success - With email subject and message', () => { const email = 'test1@example.com'; const password = 'password1'; const signers = [{email, password}]; const subject = '署名リクエスト'; const message = '署名リクエストです。\n署名をお願いします。'; prepareConfigs('fileId-1', 'folderId-2', email, password, subject, message); httpClient.setRequestHandler((request) => { assertPostRequest(request, 'fileId-1', 'folderId-2', signers, subject, message); return httpClient.createHttpResponse(201, 'application/json', '{}'); }); execute(); }); /** * 署名リクエスト作成成功 * ファイル ID、フォルダ ID を固定値で指定 */ test('Success - File ID and Folder ID are set as fixed values', () => { const email = 'test1@example.com'; const password = 'password1'; const signers = [{email, password}]; // ファイル ID、フォルダ ID はいったん null に prepareConfigs(null, null, email, password, '', ''); // ファイル ID、フォルダ ID を固定値で指定 configs.put('conf_SourceFileId', 'fileId-2'); configs.put('conf_FolderId', 'folderId-1'); httpClient.setRequestHandler((request) => { assertPostRequest(request, 'fileId-2', 'folderId-1', signers, '', ''); return httpClient.createHttpResponse(201, 'application/json', '{}'); }); execute(); }); ]]>