3 2 2024-01-15 (C) Questetra, Inc. (MIT License) This item gets categories on WordPress.com. When category names are specified (write one per line), the IDs of the categories will be saved. When no category name is specified, all categories will be retrieved and their names and IDs will be saved. この工程は、WordPress.com のカテゴリを取得します。カテゴリの名前を指定すると、そのカテゴリの ID が保存されます。複数指定する場合、1行につき1つずつ書くようにしてください。カテゴリの名前を指定しない場合、カテゴリ全件が取得され、名前と ID が保存されます。 https://support.questetra.com/bpmn-icons/service-task-wordpress-category-get/ https://support.questetra.com/ja/bpmn-icons/service-task-wordpress-category-get/ iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAABoxJREFUWEfF V3tQlFUU/52PXV4CrgqBD8IkEdLy/cgcUhNBFAFraLLSxnRwTFHBVeuPRqsZHxCRj9Ixycp0hqbY VSFMFKzxTfnAB5oVggoqYTwUlsd3mnsX1mV3Eaxmun/d795zzv2d3zn33PMR/udBnT4/Nac7mk2T FVLDGPQUwD3B5CP1CbcBlBPzBRX4AU5uuUiMqOyM7Y4BrDN6KgreY/BCImg6Y5QZTQTeoLq4rEZC ZPXDdNoHwExINcwmprUE+HbmYFsZZpQz8XIkxewEETuy0T6AZKOeiNeRIPhfDAaYmROhj03rHICM DCflmnM6CLM6Olcgc+iWI0WmNDXAtAxxcc3W2/beJWcuUYg+cmSjr5c7lo/qjzG9uiNQ5w4PrQYq A+X36nHuTjUMV29i27lr7eJWmZfaMtEWQIoxjFjNISLF1sqKUf3xwbinoDLj8PUKHLlRicI7VXDX ajDcV4eoQD880dUdV+7WYlLGEdyorbcDwswqE0ViWcz+1s0HAFbluZJHVbFtwnk5a3B0ZiiCe3hi 0+nfkZhXKL12NASQb6NHoWcXVyzNK8QnZ/6wBwEuY6UxEIlxdeYb3DpSDCsVYI2thjh8mK8Oobt/ wsnyux2lBdIjhmH2QH+ZG6N25uOXW1V2OtahMANgJkox3iSCn7X0vGcCsCVsCD4/X4IrlbWobmhE +vkSvDM6SM7vNTbDWVGg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ohEUP8POs8fK6iSc2wMtNFhW3tD1oankWBaiK hZGWqyqMWldH+wQwV0Gx/uA13JDtRSbTVaKWTtdKSxSb3dNG4qWgXnJVXDkR18uVtZKR0D7e+Cx8 KFw1CmoamhBjOIH80gq7c6X3zHdYVQKxIrqmLQDxlWIIJ+ZsRw2J2A4L8MG7Y4MR3N0T3Vy1FvQN zSpKaurkoSI0rczYIjA3JEoElkUfaN2zb8na6QtsjQlWRAMiwnLTQffjyP2OW7IWLSXFsA3AXIcc /tPFlmtnq95+y52SmUSg5P+oLU+APnaTI+wP7/mTDbFE2EiAudQ94mCgmBmJ0Mdktqfa8U/H1gIt aktfJaYEAEM6YkT8iAA4w0Sb4G/6wvY/oPMhcAR5Q7YPGk1TFaYRzDwIRANbxC4SUKgSF0DrkoWE yLaP/0OY65iBR6T9UcX/Bkm9qj9PJXC7AAAAAElFTkSuQmCC { configs.put('conf_Domain', domain); const namesDef = engine.createDataDefinition('名前', 1, 'q_names', 'STRING_TEXTAREA'); engine.setData(namesDef, names); configs.putObject('conf_Names', namesDef); const idsDef = engine.createDataDefinition('ID', 2, 'q_ids', 'STRING_TEXTAREA'); engine.setData(idsDef, '事前文字列'); configs.putObject('conf_Ids', idsDef); return { namesDef, idsDef }; }; /** * 異常系のテスト * @param errorMsg */ const assertError = (errorMsg) => { try { main(); fail(); } catch (e) { expect(e.message).toEqual(errorMsg); } }; /** * 名前に空行が含まれる場合、エラー */ test('Names include an empty line', () => { prepareConfigs('test1.example.com', 'カテゴリ 1\n\nカテゴリ 2'); assertError('Empty lines are not allowed for category names.'); }); /** * カテゴリ取得の GET リクエストのテスト * @param {Object} request * @param request.url * @param request.method * @param request.headers * @param domain */ const assertRequest = ({ url, method, headers }, domain) => { const expectedUrl = `https://public-api.wordpress.com/rest/${API_VERSION}/sites/${encodeURIComponent(domain)}/categories` + `?fields=${encodeURIComponent('ID,name')}&number=${MAX_NUMBER}`; expect(url).toEqual(expectedUrl); expect(method).toEqual('GET'); }; /** * カテゴリ取得の GET リクエストでエラー */ test('Fail in GET request', () => { prepareConfigs('test1.example.com', 'カテゴリ 1\nカテゴリ 2\n'); httpClient.setRequestHandler((request) => { assertRequest(request, 'test1.example.com'); return httpClient.createHttpResponse(400, 'application/json', '{}'); }); assertError('Failed to get categories. status: 400'); }); /** * カテゴリ取得の API レスポンスを作成 * @param found カテゴリの総数 * @param prefix カテゴリ名の接頭辞 * @param number カテゴリの数 */ const createResponse = (found, prefix, number) => { const categories = new Array(number).fill('').map((_, i) => ({ ID: i + 1, name: `${prefix}${i + 1}` })); return httpClient.createHttpResponse(200, 'application/json', JSON.stringify({ found, categories })); }; /** * カテゴリの総数が多すぎる場合、エラー */ test('Too many categories', () => { prepareConfigs('test1.example.com', 'カテゴリ 1\nカテゴリ 2\n'); httpClient.setRequestHandler((request) => { assertRequest(request, 'test1.example.com'); return createResponse(MAX_NUMBER + 1, 'カテゴリ ', 1); }); assertError('Too many categories.'); }); /** * 成功 - カテゴリ名を指定 */ test('Succeed - specified categories', () => { const names = 'カテゴリ 3\nカテゴリ 5\n'; // 末尾の改行は無視される const { namesDef, idsDef } = prepareConfigs('test1.example.com', names); httpClient.setRequestHandler((request) => { assertRequest(request, 'test1.example.com'); return createResponse(10, 'カテゴリ ', 10); }); expect(main()).toEqual(undefined); expect(engine.findData(namesDef)).toEqual(names); // 変更なし expect(engine.findData(idsDef)).toEqual('3\n5'); }); /** * 成功 - 全件取得 */ test('Succeed - all categories', () => { const { namesDef, idsDef } = prepareConfigs('test1.example.com', null); httpClient.setRequestHandler((request) => { assertRequest(request, 'test1.example.com'); return createResponse(7, 'category_', 7); }); expect(main()).toEqual(undefined); const expectedNames = new Array(7).fill('').map((_, i) => `category_${i + 1}`).join('\n'); const expectedIds = new Array(7).fill('').map((_, i) => `${i + 1}`).join('\n'); expect(engine.findData(namesDef)).toEqual(expectedNames); expect(engine.findData(idsDef)).toEqual(expectedIds); }); ]]>