2022-11-25 (C) Questetra, Inc. (MIT License) 2 This item creates a new folder in the specified folder on Box, and saves the folder ID and URL. When there is a folder with the same name, this item saves that folder ID and URL. この工程は、Box の指定フォルダ内に新しいフォルダを作成し、フォルダ ID / URL を保存します。すでに同名のフォルダがある場合は、そのフォルダ ID / URL を保存します。 https://support.questetra.com/bpmn-icons/box-folder-create/ https://support.questetra.com/ja/bpmn-icons/box-folder-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('FolderName', ''); expect(execute).toThrow('Folder Name is blank'); }); test('Folder Name Length > 255', () => { let name = ''; while (name.length <= 255) { name += 'a'; } configs.put('FolderName', name); expect(execute).toThrow('Folder Name shoule be less than 256 characters'); }); test('Folder Name uses /', () => { configs.put('FolderName', 'sample/test'); expect(execute).toThrow('Invalid Folder Name'); }); test('Folder Name uses \\', () => { configs.put('FolderName', 'sample\\test'); expect(execute).toThrow('Invalid Folder Name'); }); test('Folder Name starts with space', () => { configs.put('FolderName', ' test'); expect(execute).toThrow('Invalid Folder Name'); }); test('Folder Name ends with space', () => { configs.put('FolderName', 'test '); expect(execute).toThrow('Invalid Folder Name'); }); test('Folder Name is .', () => { configs.put('FolderName', '.'); expect(execute).toThrow('Invalid Folder Name'); }); test('Folder Name is ..', () => { configs.put('FolderName', '..'); expect(execute).toThrow('Invalid Folder Name'); }); /** * 設定の準備 * @param configs * @param name * @param parent * @return {{folderIdDef: Object, urlDef: Object}} */ const prepareConfigs = (configs, name, parent) => { configs.put('FolderName', name); configs.put('ParentFolderId', parent); configs.put('conf_OAuth2', 'Box'); const folderIdDef = engine.createDataDefinition('フォルダ ID', 3, 'q_folderId', 'STRING_TEXTFIELD'); configs.putObject('FolderIdItem', folderIdDef); engine.setData(folderIdDef, '事前文字列'); const urlDef = engine.createDataDefinition('フォルダ URL', 5, 'q_folderUrl', 'STRING_TEXTFIELD'); configs.putObject('WebViewUrlItem', urlDef); engine.setData(urlDef, '事前文字列'); return { folderIdDef, urlDef }; }; /** * リクエストのテスト * @param {Object} request * @param request.url * @param request.method * @param request.contentType * @param request.body * @param name * @param parentId */ const assertRequest = ({url, method, contentType, body}, name, parentId) => { expect(url).toEqual('https://api.box.com/2.0/folders?fields=id'); expect(method).toEqual('POST'); expect(contentType).toEqual('application/json; charset=UTF-8'); const bodyObj = JSON.parse(body); expect(bodyObj.parent.id).toEqual(parentId); expect(bodyObj.name).toEqual(name); }; const SAMPLE_RESPONSE_OBJ = { "id": 12345, "type": "folder", "etag": 1 }; test('201 Success', () => { const { folderIdDef, urlDef } = prepareConfigs(configs, '.test.', ''); httpClient.setRequestHandler((request) => { assertRequest(request, '.test.', 0); return httpClient.createHttpResponse(201, 'application/json', JSON.stringify(SAMPLE_RESPONSE_OBJ)); }); execute(); expect(engine.findData(folderIdDef)).toEqual(12345); expect(engine.findData(urlDef)).toEqual('https://app.box.com/folder/12345'); }); test('201 Not JSON', () => { const { folderIdDef, urlDef } = prepareConfigs(configs, 'hello world', ''); httpClient.setRequestHandler((request) => { assertRequest(request, 'hello world', 0); return httpClient.createHttpResponse(201, 'text/html; charset=UTF-8', 'テスト') }); expect(execute).toThrow('Failed to create. status: 201'); expect(engine.findData(folderIdDef)).toEqual('事前文字列'); expect(engine.findData(urlDef)).toEqual('事前文字列'); }); const SAMPLE_409_FOLDER = { "type": "error", "code": "item_name_in_use", "context_info": { "conflicts": [ { "id": 23456, "etag": 1, "type": "folder", "sequence_id": 3, "name": ".test.", } ], "message": "" }, "help_url": "http://developers.box.com/docs/#errors", "message": "", "request_id": "abcdef123456", "status": 409 }; test('409 Conflicts with Folder', () => { const { folderIdDef, urlDef } = prepareConfigs(configs, 'テスト', '45678'); httpClient.setRequestHandler((request) => { assertRequest(request, 'テスト', '45678'); return httpClient.createHttpResponse(409, 'application/json', JSON.stringify(SAMPLE_409_FOLDER)); }); execute(); expect(engine.findData(folderIdDef)).toEqual(23456); expect(engine.findData(urlDef)).toEqual('https://app.box.com/folder/23456'); }); const SAMPLE_409_FILE = { "type": "error", "code": "item_name_in_use", "context_info": { "conflicts": [ { "id": 23456, "etag": 1, "type": "file", "sequence_id": 3, "name": ".test.", } ], "message": "" }, "help_url": "http://developers.box.com/docs/#errors", "message": "", "request_id": "abcdef123456", "status": 409 }; test('409 Conflicts with File', () => { const { folderIdDef, urlDef } = prepareConfigs(configs, 'test.txt', '987'); httpClient.setRequestHandler((request) => { assertRequest(request, 'test.txt', '987'); return httpClient.createHttpResponse(409, 'application/json', JSON.stringify(SAMPLE_409_FILE)); }); expect(execute).toThrow('Failed to create. status: 409'); expect(engine.findData(folderIdDef)).toEqual('事前文字列'); expect(engine.findData(urlDef)).toEqual('事前文字列'); }); const SAMPLE_ERROR = { "type": "error", "status": 400, "code": "bad_digest", "help_url": "http://developers.box.com/docs/#errors", "message": "The specified content-md5 did not match what we received", "request_id": "abcdef123456" }; test('ERROR', () => { const { folderIdDef, urlDef } = prepareConfigs(configs, 'ほげ', ''); httpClient.setRequestHandler((request) => { assertRequest(request, 'ほげ', 0); return httpClient.createHttpResponse(400, 'application/json', JSON.stringify(SAMPLE_ERROR)); }); expect(execute).toThrow('Failed to create. status: 400'); expect(engine.findData(folderIdDef)).toEqual('事前文字列'); expect(engine.findData(urlDef)).toEqual('事前文字列'); }); ]]>