2022-05-27
(C) Questetra, Inc. (MIT License)
2
This item adds metadata to the specified file on Box, using a metadata template defined within your
enterprise. An error occurs if the specified metadata template is already added to the file.
この工程は、会社内で定義されたメタデータテンプレートを利用して、Box 上のファイルにメタデータを追加します。
指定したメタデータテンプレートがすでにファイルに追加済みの場合は、エラーになります。
https://support.questetra.com/bpmn-icons/service-task-box-file-metadata-add/
https://support.questetra.com/ja/bpmn-icons/service-task-box-file-metadata-add/
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');
// ファイル ID を保存した文字型データ項目(単一行)を準備し、設定
const fileIdDef = engine.createDataDefinition('ファイル ID', 1, 'q_FileId', 'STRING_TEXTFIELD');
engine.setData(fileIdDef, fileId);
configs.putObject('conf_FileId', fileIdDef);
configs.put('conf_TemplateName', templateName);
for (let i = 0; i < FIELD_SIZE; i++) {
configs.put(`conf_FieldName${i+1}`, fieldNames[i]);
configs.put(`conf_FieldValue${i+1}`, fieldValues[i]);
}
}
/** フィールド名一覧のサンプル */
const SAMPLE_FIELD_NAMES = ['文字列1', '文字列2', '文字列3', '文字列4', '数値', '日付', '単一選択', '複数選択'];
/** フィールドの値一覧のサンプル */
const SAMPLE_FIELD_VALUES = ['文字列1の値', '文字列2の値', '文字列3の値', '文字列4の値', '1000', '2020-01-01', '単一選択の選択肢A', '複数選択の選択肢C'];
/** テンプレートのサンプル */
const SAMPLE_TEMPLATE = {
"templateKey": "template1",
"displayName": "テンプレート1",
"hidden": false,
"fields": [
{
"type": "string",
"key": "field1",
"displayName": "使用しないフィールド",
"hidden": false
},
{
"type": "string",
"key": "field2",
"displayName": "文字列1",
"hidden": false
},
{
"type": "string",
"key": "field3",
"displayName": "文字列2",
"hidden": false
},
{
"type": "string",
"key": "field4",
"displayName": "文字列3",
"hidden": false
},
{
"type": "string",
"key": "field5",
"displayName": "文字列4",
"hidden": false
},
{
"type": "float",
"key": "field6",
"displayName": "数値",
"hidden": false
},
{
"type": "date",
"key": "field7",
"displayName": "日付",
"hidden": false
},
{
"type": "enum",
"key": "field8",
"displayName": "単一選択",
"hidden": false,
"options": [
{
"key": "単一選択の選択肢A"
},
{
"key": "単一選択の選択肢B"
}
]
},
{
"type": "multiSelect",
"key": "field9",
"displayName": "複数選択",
"hidden": false,
"options": [
{
"key": "複数選択の選択肢A"
},
{
"key": "複数選択の選択肢B"
},
{
"key": "複数選択の選択肢C"
}
]
}
]
};
/** サンプルのフィールド名、値、テンプレートを指定した場合のメタデータオブジェクト */
const SAMPLE_METADATA_OBJ = {
'field2': '文字列1の値',
'field3': '文字列2の値',
'field4': '文字列3の値',
'field5': '文字列4の値',
'field6': 1000,
'field7': '2020-01-01T00:00:00Z',
'field8': '単一選択の選択肢A',
'field9': [
'複数選択の選択肢C'
]
};
/**
* ファイル ID の値が空でエラー
*/
test('File ID is blank', () => {
prepareConfigs(null, 'テンプレート1', SAMPLE_FIELD_NAMES, SAMPLE_FIELD_VALUES);
expect(execute).toThrow('File ID is blank.');
});
/**
* フィールド名が空なのに、値が指定されていればエラー
*/
test('Field name is blank while its value is set', () => {
prepareConfigs('fileId-1', 'テンプレート1', SAMPLE_FIELD_NAMES, SAMPLE_FIELD_VALUES);
configs.put('conf_FieldName6', '');
expect(execute).toThrow('Value for Field 6 is set but its display name is blank.');
});
/**
* フィールド名が重複していてエラー(1番目と3番目が重複)
*/
test('Same field name set multiple times - 1st and 3rd', () => {
prepareConfigs('fileId-1', 'テンプレート1', SAMPLE_FIELD_NAMES, SAMPLE_FIELD_VALUES);
configs.put('conf_FieldName3', '文字列1');
expect(execute).toThrow('The Field Name "文字列1" is set multiple times.');
});
/**
* フィールド名が重複していてエラー(5番目と8番目が重複)
*/
test('Same field name set multiple times - 5th and 8th', () => {
prepareConfigs('fileId-1', 'テンプレート1', SAMPLE_FIELD_NAMES, SAMPLE_FIELD_VALUES);
configs.put('conf_FieldName5', '複数選択');
expect(execute).toThrow('The Field Name "複数選択" is set multiple times.');
});
/**
* テンプレート一覧を取得する API リクエストのテスト
* @param {Object} request
* @param request.url
* @param request.method
*/
const assertGetTemplatesRequest = ({url, method}) => {
expect(url).toEqual(`https://api.box.com/2.0/metadata_templates/enterprise?limit=500`);
expect(method).toEqual('GET');
};
/**
* テンプレート一覧を取得する API リクエストのレスポンスを作成する
* @param templates
* @return responseString
*/
const buildGetTemplatesRes = (...templates) => {
const responseObj = {
"entries": []
};
templates.forEach(template => responseObj.entries.push(template));
return JSON.stringify(responseObj);
};
/**
* テンプレート一覧を取得する API リクエストで失敗
*/
test('Fail in API Request to get metadata templates', () => {
prepareConfigs('fileId-1', 'テンプレート1', SAMPLE_FIELD_NAMES, SAMPLE_FIELD_VALUES);
httpClient.setRequestHandler((request) => {
assertGetTemplatesRequest(request);
return httpClient.createHttpResponse(400, 'application/json', '{}');
});
expect(execute).toThrow('Failed to search template. status:400');
});
/**
* 企業内で定義されたテンプレートが 1 つも存在しない
*/
test('No templates found', () => {
prepareConfigs('fileId-1', 'テンプレート1', SAMPLE_FIELD_NAMES, SAMPLE_FIELD_VALUES);
const responseStr = buildGetTemplatesRes();
httpClient.setRequestHandler((request) => {
assertGetTemplatesRequest(request);
return httpClient.createHttpResponse(200, 'application/json', responseStr);
});
expect(execute).toThrow('Template with display name "テンプレート1" not found.');
});
/**
* 指定した表示名のテンプレートが存在しない
*/
test('Template not found', () => {
prepareConfigs('fileId-1', 'テンプレート2', SAMPLE_FIELD_NAMES, SAMPLE_FIELD_VALUES);
const responseStr = buildGetTemplatesRes(SAMPLE_TEMPLATE);
httpClient.setRequestHandler((request) => {
assertGetTemplatesRequest(request);
return httpClient.createHttpResponse(200, 'application/json', responseStr);
});
expect(execute).toThrow('Template with display name "テンプレート2" not found.');
});
/**
* 指定した表示名のテンプレートは存在するが、非表示に設定されている
*/
test('Template is hidden', () => {
prepareConfigs('fileId-1', 'テンプレート1', SAMPLE_FIELD_NAMES, SAMPLE_FIELD_VALUES);
const template = JSON.parse(JSON.stringify(SAMPLE_TEMPLATE)); // ディープコピー
template.hidden = true;
const responseStr = buildGetTemplatesRes(template);
httpClient.setRequestHandler((request) => {
assertGetTemplatesRequest(request);
return httpClient.createHttpResponse(200, 'application/json', responseStr);
});
expect(execute).toThrow('Template with display name "テンプレート1" not found.');
});
/**
* 指定した表示名のテンプレートが複数存在する
*/
test('Multiple templates found', () => {
prepareConfigs('fileId-1', 'テンプレート1', SAMPLE_FIELD_NAMES, SAMPLE_FIELD_VALUES);
const responseStr = buildGetTemplatesRes(SAMPLE_TEMPLATE, SAMPLE_TEMPLATE);
httpClient.setRequestHandler((request) => {
assertGetTemplatesRequest(request);
return httpClient.createHttpResponse(200, 'application/json', responseStr);
});
expect(execute).toThrow('Multiple templates with display name "テンプレート1" found.');
});
/**
* メタデータを追加する API リクエストのテスト
* @param {Object} request
* @param request.url
* @param request.method
* @param request.contentType
* @param request.body
* @param fileId
* @param templateKey
* @param metadataObj
*/
const assertPostMetadataRequest = ({url, method, contentType, body}, fileId, templateKey, metadataObj) => {
expect(url).toEqual(`https://api.box.com/2.0/files/${encodeURIComponent(fileId)}/metadata/enterprise/${encodeURIComponent(templateKey)}`);
expect(method).toEqual('POST');
expect(contentType).toEqual('application/json; charset=UTF-8');
expect(body).toEqual(JSON.stringify(metadataObj));
};
/**
* メタデータを追加する API リクエストで失敗
*/
test('Fail in API Request to add metadata', () => {
const fileId = 'fileId-1';
prepareConfigs(fileId, 'テンプレート1', SAMPLE_FIELD_NAMES, SAMPLE_FIELD_VALUES);
const responseStr = buildGetTemplatesRes(SAMPLE_TEMPLATE);
let reqCount = 0;
httpClient.setRequestHandler((request) => {
if (reqCount === 0) {
assertGetTemplatesRequest(request);
reqCount++;
return httpClient.createHttpResponse(200, 'application/json', responseStr);
}
assertPostMetadataRequest(request, fileId, SAMPLE_TEMPLATE.templateKey, SAMPLE_METADATA_OBJ);
return httpClient.createHttpResponse(400, 'application/json', '{}');
});
expect(execute).toThrow('Failed to add metadata. status:400');
});
/**
* メタデータの追加に成功
*/
test('Succeed to add metadata', () => {
const fileId = 'fileId-1';
prepareConfigs(fileId, 'テンプレート1', SAMPLE_FIELD_NAMES, SAMPLE_FIELD_VALUES);
const responseStr = buildGetTemplatesRes(SAMPLE_TEMPLATE);
let reqCount = 0;
httpClient.setRequestHandler((request) => {
if (reqCount === 0) {
assertGetTemplatesRequest(request);
reqCount++;
return httpClient.createHttpResponse(200, 'application/json', responseStr);
}
assertPostMetadataRequest(request, fileId, SAMPLE_TEMPLATE.templateKey, SAMPLE_METADATA_OBJ);
return httpClient.createHttpResponse(201, 'application/json', '{}');
});
execute();
});
/**
* メタデータの追加に成功
* 指定した表示名のテンプレートは複数存在するが、1 つを除き非表示の場合
*/
test('Succeed to add metadata - multiple templates found but only one visible', () => {
const fileId = 'fileId-2';
prepareConfigs(fileId, 'テンプレート1', SAMPLE_FIELD_NAMES, SAMPLE_FIELD_VALUES);
const hiddenTemplate = JSON.parse(JSON.stringify(SAMPLE_TEMPLATE)); // ディープコピー
hiddenTemplate.hidden = true;
const responseStr = buildGetTemplatesRes(hiddenTemplate, SAMPLE_TEMPLATE, hiddenTemplate);
let reqCount = 0;
httpClient.setRequestHandler((request) => {
if (reqCount === 0) {
assertGetTemplatesRequest(request);
reqCount++;
return httpClient.createHttpResponse(200, 'application/json', responseStr);
}
assertPostMetadataRequest(request, fileId, SAMPLE_TEMPLATE.templateKey, SAMPLE_METADATA_OBJ);
return httpClient.createHttpResponse(201, 'application/json', '{}');
});
execute();
});
/** フィールド名、値に設定するための、すべて空文字列の配列 */
const ALL_BLANK = new Array(FIELD_SIZE).fill('');
/**
* メタデータの追加に成功
* フィールド名、フィールドの値がすべて空の場合
*/
test('Succeed to add metadata - no fields set', () => {
const fileId = 'fileId-3';
prepareConfigs(fileId, 'テンプレート1', ALL_BLANK, ALL_BLANK);
const responseStr = buildGetTemplatesRes(SAMPLE_TEMPLATE);
let reqCount = 0;
httpClient.setRequestHandler((request) => {
if (reqCount === 0) {
assertGetTemplatesRequest(request);
reqCount++;
return httpClient.createHttpResponse(200, 'application/json', responseStr);
}
assertPostMetadataRequest(request, fileId, SAMPLE_TEMPLATE.templateKey, {}); // メタデータオブジェクトは空
return httpClient.createHttpResponse(201, 'application/json', '{}');
});
execute();
});
/**
* メタデータの追加に成功
* フィールド名は指定されているが、フィールドの値がすべて空の場合
*/
test('Succeed to add metadata - no field values set', () => {
const fileId = 'fileId-3';
prepareConfigs(fileId, 'テンプレート1', SAMPLE_FIELD_NAMES, ALL_BLANK);
const responseStr = buildGetTemplatesRes(SAMPLE_TEMPLATE);
let reqCount = 0;
httpClient.setRequestHandler((request) => {
if (reqCount === 0) {
assertGetTemplatesRequest(request);
reqCount++;
return httpClient.createHttpResponse(200, 'application/json', responseStr);
}
assertPostMetadataRequest(request, fileId, SAMPLE_TEMPLATE.templateKey, {}); // メタデータオブジェクトは空
return httpClient.createHttpResponse(201, 'application/json', '{}');
});
execute();
});
/** テンプレートのサンプル */
const SAMPLE_TEMPLATE_2 = {
"templateKey": "template2",
"displayName": "テンプレート2",
"hidden": false,
"fields": [
{
"type": "float",
"key": "field-hidden",
"displayName": "数値",
"hidden": true
},
{
"type": "float",
"key": "field1",
"displayName": "数値",
"hidden": false
},
{
"type": "date",
"key": "field2",
"displayName": "日付",
"hidden": false
},
{
"type": "enum",
"key": "field3",
"displayName": "単一選択",
"hidden": false,
"options": [
{
"key": "選択肢1"
},
{
"key": "選択肢2"
}
]
},
{
"type": "multiSelect",
"key": "field4",
"displayName": "複数選択",
"hidden": false,
"options": [
{
"key": "選択肢A"
},
{
"key": "選択肢B"
}
]
},
{
"type": "string",
"key": "field5",
"displayName": "表示名が重複したフィールド",
"hidden": false
},
{
"type": "string",
"key": "field6",
"displayName": "表示名が重複したフィールド",
"hidden": false
},
{
"type": "string",
"key": "field7",
"displayName": "非表示のフィールド",
"hidden": true
},
{
"type": "newType",
"key": "field8",
"displayName": "新しい型のフィールド",
"hidden": false
}
]
};
/**
* メタデータの追加に成功
* 一部のフィールドのみ設定
*/
test('Succeed to add metadata - Some fields are blank', () => {
const fileId = 'fileId-1';
const fieldNames = new Array(FIELD_SIZE).fill('');
const fieldValues = new Array(FIELD_SIZE).fill('');
fieldNames[2] = '数値';
fieldValues[2] = '9999.0000000001';
fieldNames[4] = '単一選択';
fieldValues[4] = '選択肢2';
fieldNames[5] = '複数選択';
fieldValues[5] = '選択肢A';
prepareConfigs(fileId, 'テンプレート2', fieldNames, fieldValues);
const metadataObj = {
'field1': 9999.0000000001,
'field3': '選択肢2',
'field4': ['選択肢A']
};
const responseStr = buildGetTemplatesRes(SAMPLE_TEMPLATE, SAMPLE_TEMPLATE_2);
let reqCount = 0;
httpClient.setRequestHandler((request) => {
if (reqCount === 0) {
assertGetTemplatesRequest(request);
reqCount++;
return httpClient.createHttpResponse(200, 'application/json', responseStr);
}
assertPostMetadataRequest(request, fileId, SAMPLE_TEMPLATE_2.templateKey, metadataObj);
return httpClient.createHttpResponse(201, 'application/json', '{}');
});
execute();
});
/**
* メタデータの追加に成功
* 数値型フィールドに0を入力
*/
test('Succeed to add metadata - Set 0 in float field', () => {
const fileId = 'fileId-1';
const fieldNames = new Array(FIELD_SIZE).fill('');
const fieldValues = new Array(FIELD_SIZE).fill('');
fieldNames[2] = '数値';
fieldValues[2] = '0';
prepareConfigs(fileId, 'テンプレート2', fieldNames, fieldValues);
const metadataObj = {
'field1': 0
};
const responseStr = buildGetTemplatesRes(SAMPLE_TEMPLATE, SAMPLE_TEMPLATE_2);
let reqCount = 0;
httpClient.setRequestHandler((request) => {
if (reqCount === 0) {
assertGetTemplatesRequest(request);
reqCount++;
return httpClient.createHttpResponse(200, 'application/json', responseStr);
}
assertPostMetadataRequest(request, fileId, SAMPLE_TEMPLATE_2.templateKey, metadataObj);
return httpClient.createHttpResponse(201, 'application/json', '{}');
});
execute();
});
/**
* メタデータの追加に成功
* 数値型フィールドにマイナス記号を含む数値を入力
*/
test('Succeed to add metadata - Set negative number in float field', () => {
const fileId = 'fileId-1';
const fieldNames = new Array(FIELD_SIZE).fill('');
const fieldValues = new Array(FIELD_SIZE).fill('');
fieldNames[0] = '数値';
fieldValues[0] = '-101.101';
prepareConfigs(fileId, 'テンプレート2', fieldNames, fieldValues);
const metadataObj = {
'field1': -101.101
};
const responseStr = buildGetTemplatesRes(SAMPLE_TEMPLATE, SAMPLE_TEMPLATE_2);
let reqCount = 0;
httpClient.setRequestHandler((request) => {
if (reqCount === 0) {
assertGetTemplatesRequest(request);
reqCount++;
return httpClient.createHttpResponse(200, 'application/json', responseStr);
}
assertPostMetadataRequest(request, fileId, SAMPLE_TEMPLATE_2.templateKey, metadataObj);
return httpClient.createHttpResponse(201, 'application/json', '{}');
});
execute();
});
/**
* 数値型フィールドに数値として解釈できない文字列を入力し、エラー
*/
test('The float value is invalid - includes invalid characters', () => {
const fileId = 'fileId-1';
const fieldNames = new Array(FIELD_SIZE).fill('');
const fieldValues = new Array(FIELD_SIZE).fill('');
fieldNames[0] = '数値';
fieldValues[0] = 'abc123';
prepareConfigs(fileId, 'テンプレート2', fieldNames, fieldValues);
const responseStr = buildGetTemplatesRes(SAMPLE_TEMPLATE, SAMPLE_TEMPLATE_2);
httpClient.setRequestHandler((request) => {
assertGetTemplatesRequest(request);
return httpClient.createHttpResponse(200, 'application/json', responseStr);
});
expect(execute).toThrow('The type of "数値" is float, but the value "abc123" is invalid as float.');
});
/**
* 数値型フィールドにカンマ区切りの数値を入力し、エラー
*/
test('The float value is invalid - includes comma', () => {
const fileId = 'fileId-1';
const fieldNames = new Array(FIELD_SIZE).fill('');
const fieldValues = new Array(FIELD_SIZE).fill('');
fieldNames[3] = '数値';
fieldValues[3] = '1,000';
prepareConfigs(fileId, 'テンプレート2', fieldNames, fieldValues);
const responseStr = buildGetTemplatesRes(SAMPLE_TEMPLATE, SAMPLE_TEMPLATE_2);
httpClient.setRequestHandler((request) => {
assertGetTemplatesRequest(request);
return httpClient.createHttpResponse(200, 'application/json', responseStr);
});
expect(execute).toThrow('The type of "数値" is float, but the value "1,000" is invalid as float.');
});
/**
* 数値型フィールドに一の位のない文字列を入力し、エラー
*/
test('The float value is invalid - missing ones place', () => {
const fileId = 'fileId-1';
const fieldNames = new Array(FIELD_SIZE).fill('');
const fieldValues = new Array(FIELD_SIZE).fill('');
fieldNames[1] = '数値';
fieldValues[1] = '.1';
prepareConfigs(fileId, 'テンプレート2', fieldNames, fieldValues);
const responseStr = buildGetTemplatesRes(SAMPLE_TEMPLATE, SAMPLE_TEMPLATE_2);
httpClient.setRequestHandler((request) => {
assertGetTemplatesRequest(request);
return httpClient.createHttpResponse(200, 'application/json', responseStr);
});
expect(execute).toThrow('The type of "数値" is float, but the value ".1" is invalid as float.');
});
/**
* 数値型フィールドに0はじまりの2桁以上の数字列を入力し、エラー
*/
test('The float value is invalid - starts with 0', () => {
const fileId = 'fileId-1';
const fieldNames = new Array(FIELD_SIZE).fill('');
const fieldValues = new Array(FIELD_SIZE).fill('');
fieldNames[2] = '数値';
fieldValues[2] = '01';
prepareConfigs(fileId, 'テンプレート2', fieldNames, fieldValues);
const responseStr = buildGetTemplatesRes(SAMPLE_TEMPLATE, SAMPLE_TEMPLATE_2);
httpClient.setRequestHandler((request) => {
assertGetTemplatesRequest(request);
return httpClient.createHttpResponse(200, 'application/json', responseStr);
});
expect(execute).toThrow('The type of "数値" is float, but the value "01" is invalid as float.');
});
/**
* 数値型フィールドにピリオドが複数個ある文字列を入力し、エラー
*/
test('The float value is invalid - multiple periods', () => {
const fileId = 'fileId-1';
const fieldNames = new Array(FIELD_SIZE).fill('');
const fieldValues = new Array(FIELD_SIZE).fill('');
fieldNames[7] = '数値';
fieldValues[7] = '1.00.1';
prepareConfigs(fileId, 'テンプレート2', fieldNames, fieldValues);
const responseStr = buildGetTemplatesRes(SAMPLE_TEMPLATE, SAMPLE_TEMPLATE_2);
httpClient.setRequestHandler((request) => {
assertGetTemplatesRequest(request);
return httpClient.createHttpResponse(200, 'application/json', responseStr);
});
expect(execute).toThrow('The type of "数値" is float, but the value "1.00.1" is invalid as float.');
});
/**
* 日付型フィールドに yyyy-MM-dd 形式でない文字列を入力し、エラー
*/
test('The date value is invalid - not in yyyy-MM-dd format', () => {
const fileId = 'fileId-1';
const fieldNames = new Array(FIELD_SIZE).fill('');
const fieldValues = new Array(FIELD_SIZE).fill('');
fieldNames[6] = '日付';
fieldValues[6] = '2015/05/01';
prepareConfigs(fileId, 'テンプレート2', fieldNames, fieldValues);
const responseStr = buildGetTemplatesRes(SAMPLE_TEMPLATE, SAMPLE_TEMPLATE_2);
httpClient.setRequestHandler((request) => {
assertGetTemplatesRequest(request);
return httpClient.createHttpResponse(200, 'application/json', responseStr);
});
expect(execute).toThrow('The type of "日付" is date, but the value "2015/05/01" is not in the format of "yyyy-MM-dd".');
});
/**
* 日付型フィールドに yyyy-MM-dd 形式だが日付として不正な文字列を入力し、エラー
*/
test('The date value is invalid - invalid date', () => {
const fileId = 'fileId-1';
const fieldNames = new Array(FIELD_SIZE).fill('');
const fieldValues = new Array(FIELD_SIZE).fill('');
fieldNames[5] = '日付';
fieldValues[5] = '2020-06-31';
prepareConfigs(fileId, 'テンプレート2', fieldNames, fieldValues);
const responseStr = buildGetTemplatesRes(SAMPLE_TEMPLATE, SAMPLE_TEMPLATE_2);
httpClient.setRequestHandler((request) => {
assertGetTemplatesRequest(request);
return httpClient.createHttpResponse(200, 'application/json', responseStr);
});
expect(execute).toThrow('The type of "日付" is date, but the value "2020-06-31" is invalid as date.');
});
/**
* 単一選択型フィールドに選択肢の表示名として存在しない文字列を入力し、エラー
*/
test('The enum value is invalid - option not found', () => {
const fileId = 'fileId-1';
const fieldNames = new Array(FIELD_SIZE).fill('');
const fieldValues = new Array(FIELD_SIZE).fill('');
fieldNames[4] = '単一選択';
fieldValues[4] = '選択肢A';
prepareConfigs(fileId, 'テンプレート2', fieldNames, fieldValues);
const responseStr = buildGetTemplatesRes(SAMPLE_TEMPLATE, SAMPLE_TEMPLATE_2);
httpClient.setRequestHandler((request) => {
assertGetTemplatesRequest(request);
return httpClient.createHttpResponse(200, 'application/json', responseStr);
});
expect(execute).toThrow('The value "選択肢A" is not in the options of the field "単一選択".');
});
/**
* 複数選択型フィールドに選択肢の表示名として存在しない文字列を入力し、エラー
*/
test('The multiSelect value is invalid - option not found', () => {
const fileId = 'fileId-1';
const fieldNames = new Array(FIELD_SIZE).fill('');
const fieldValues = new Array(FIELD_SIZE).fill('');
fieldNames[3] = '複数選択';
fieldValues[3] = '選択肢1';
prepareConfigs(fileId, 'テンプレート2', fieldNames, fieldValues);
const responseStr = buildGetTemplatesRes(SAMPLE_TEMPLATE, SAMPLE_TEMPLATE_2);
httpClient.setRequestHandler((request) => {
assertGetTemplatesRequest(request);
return httpClient.createHttpResponse(200, 'application/json', responseStr);
});
expect(execute).toThrow('The value "選択肢1" is not in the options of the field "複数選択".');
});
/**
* 指定した表示名のフィールドが存在しない
*/
test('Field not found', () => {
const fileId = 'fileId-1';
const fieldNames = new Array(FIELD_SIZE).fill('');
const fieldValues = new Array(FIELD_SIZE).fill('');
fieldNames[2] = '存在しないフィールド';
fieldValues[2] = '文字列';
prepareConfigs(fileId, 'テンプレート2', fieldNames, fieldValues);
const responseStr = buildGetTemplatesRes(SAMPLE_TEMPLATE, SAMPLE_TEMPLATE_2);
httpClient.setRequestHandler((request) => {
assertGetTemplatesRequest(request);
return httpClient.createHttpResponse(200, 'application/json', responseStr);
});
expect(execute).toThrow('Field with display name "存在しないフィールド" not found.');
});
/**
* 指定した表示名のフィールドは存在するが、非表示に設定されている
*/
test('Field is hidden', () => {
const fileId = 'fileId-1';
const fieldNames = new Array(FIELD_SIZE).fill('');
const fieldValues = new Array(FIELD_SIZE).fill('');
fieldNames[1] = '非表示のフィールド';
fieldValues[1] = '文字列';
prepareConfigs(fileId, 'テンプレート2', fieldNames, fieldValues);
const responseStr = buildGetTemplatesRes(SAMPLE_TEMPLATE, SAMPLE_TEMPLATE_2);
httpClient.setRequestHandler((request) => {
assertGetTemplatesRequest(request);
return httpClient.createHttpResponse(200, 'application/json', responseStr);
});
expect(execute).toThrow('Field with display name "非表示のフィールド" not found.');
});
/**
* 指定した表示名のフィールドが複数存在する
*/
test('Multiple fields found', () => {
const fileId = 'fileId-1';
const fieldNames = new Array(FIELD_SIZE).fill('');
const fieldValues = new Array(FIELD_SIZE).fill('');
fieldNames[0] = '表示名が重複したフィールド';
fieldValues[0] = '文字列';
prepareConfigs(fileId, 'テンプレート2', fieldNames, fieldValues);
const responseStr = buildGetTemplatesRes(SAMPLE_TEMPLATE, SAMPLE_TEMPLATE_2);
httpClient.setRequestHandler((request) => {
assertGetTemplatesRequest(request);
return httpClient.createHttpResponse(200, 'application/json', responseStr);
});
expect(execute).toThrow('Multiple fields with display name "表示名が重複したフィールド" found.');
});
/**
* フィールドの型が非対応(現状はありえないが、Box のメタデータのフィールド型が追加された場合に発生)
*/
test('Field type not supported', () => {
const fileId = 'fileId-1';
const fieldNames = new Array(FIELD_SIZE).fill('');
const fieldValues = new Array(FIELD_SIZE).fill('');
fieldNames[0] = '新しい型のフィールド';
fieldValues[0] = '文字列';
prepareConfigs(fileId, 'テンプレート2', fieldNames, fieldValues);
const responseStr = buildGetTemplatesRes(SAMPLE_TEMPLATE, SAMPLE_TEMPLATE_2);
httpClient.setRequestHandler((request) => {
assertGetTemplatesRequest(request);
return httpClient.createHttpResponse(200, 'application/json', responseStr);
});
expect(execute).toThrow('The type of "新しい型のフィールド" is not supported: newType');
});
]]>