2022-05-10
(C) Questetra, Inc. (MIT License)
2
This item creates a folder in the specified folder on OneDrive.
この工程は、OneDrive の指定フォルダ内にフォルダを作成します。
https://support.questetra.com/bpmn-icons/onedrive-folder-create/
https://support.questetra.com/ja/bpmn-icons/onedrive-folder-create/
iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAADXUlEQVRYR8WXW0hUURSG/33GbC5e
8pJJF6nM6YKUmsFAIAZSONOM4FtqL/mQVg9GhXR5iCIiEAqF9KEMsvKpi06OZoRPGaRmVoSGU4om
aqaMzeXYOLPjTJ7R41w8k8bZLwNn1r/Wt9dee+29CSQeRHR8vVEpd7vzGTAHKKXpADYDiJnTTwEY
IIR0u+FuYxnmCYx6uxjfSwKotE2JbuoqB0EJALkYpwBYUNQwRHbDZtKNBtMEBVBqG0ooSAUAlcjA
i81sBPSs3ZRXE0gfEECuM94mlJb+Y2CBjBJSzTbpT/jz5RdAoTU+BGjBSgSf90EeOUz6wsU+fQBW
cuaLg/nLhABgbs2rV3bmQm8EtHRhTXgBPNUOV/8yCk4st42BbBu/O7wAitzGmyAoE+tlWXYUtxzN
htOcj78AeqNS4aI/Q9jneH5Ng0x1DCLkMlhZFz59m0ZZ9UfPr4jBOmQkjmtWHgC5rqGIUFIXTHih
QI3UzVHoH7HhsCYROzZF+JgPjNqxq/iViPgAJfQo25T3wAOg1BnvUkqP+VNGKsLQXpmF5PXCXmR1
zKJvyAqL3Yn4qHCoN0ZCHs6gvm0YxRXdS0IQQmrtTfpiD4BC2/gOANfffUbjVQ1yMtYKvnNZGJlg
kZESDeVqGSy2WbzoHPdkpdtswcnKniUBAHQ7TIYMHmBywcEiEPfey0FSgsL7zWJzosc8jazdcQI7
l5tiwvIbUaowTE47UfXMjMqnX4OBTDlMhlgegC62TNmgwp0z6UhLjsaqMMbzN5f25o4x5O5bhwhF
WNBZ2mdcyDn3Gu/NloB2DpOBBAToqs7GzqRIr/j7BIu+4V9I2xqN2KhwMSlGbcsgTlV9EAXgswSW
Bp135pQCrV3jOJSZICowb2RjXWjtHEfh9U5/OsES+BThj8daqOQyb+q/DFuRkbImJADOmKuNg+Xt
ePOZm6NgzBehv21YfzETek0iGIZgxun2OMjeEx8yACfIv/wWLR1jAq1gGwZqROePqLE/NRZjUzOo
ezmE++V7ER8tbv35aFzm0o63+YALGlEorfhS0XZsSVSKysTgmANX6nr92QpbMWch7WHEncFSH8dc
FiS9kPALJemVjIeQ9FL6PzIR8rWch5D0YcJDSPo0E3QQqR6nolreMoz+ACVfiTBvFfnjAAAAAElF
TkSuQmCC
{
configs.put('conf_OAuth2', 'Microsoft');
configs.put('conf_folderName', folderName);
// 作成するフォルダの親フォルダの URL を保存する文字型データ項目(単数行)を準備
const parentFolderUrlDef = engine.createDataDefinition('親フォルダの URL', 1, 'q_parent_folder_url', 'STRING_TEXTFIELD');
engine.setData(parentFolderUrlDef, parentFolderUrl);
configs.putObject('conf_parentFolderUrl', parentFolderUrlDef);
// フォルダ URL を保存する文字型データ項目(単数行)を準備
const folderUrlDef = engine.createDataDefinition('フォルダ URL', 2, 'q_folder_url', 'STRING_TEXTFIELD');
engine.setData(folderUrlDef, '事前文字列');
configs.putObject('conf_folderUrl', folderUrlDef);
return folderUrlDef;
};
/**
* フォルダ名が空でエラー
*/
test('Folder name is empty.', () => {
prepareConfigs('https://test-my.sharepoint.com/personal/aaa/Documents/parent1', '');
expect(execute).toThrow('Folder name is empty.');
});
/**
* GET リクエストのテスト
* @param {Object} request
* @param request.url
* @param request.method
* @param sharingUrl
*/
const assertGetRequest = ({url, method}, sharingUrl) => {
const encodedSharingUrl = encodeSharingUrl(sharingUrl);
expect(url).toEqual(`${GRAPH_URI}shares/${encodedSharingUrl}/driveItem`);
expect(method).toEqual('GET');
};
/**
* GET リクエストでエラー - 親フォルダURLをデータ項目で指定
*/
test('GET Failed - Specify Parent Folder URL as a data item', () => {
prepareConfigs('https://test-my.sharepoint.com/personal/aaa/Documents/parent2', 'folder2');
httpClient.setRequestHandler((request) => {
assertGetRequest(request, 'https://test-my.sharepoint.com/personal/aaa/Documents/parent2');
return httpClient.createHttpResponse(400, 'application/json', '{}');
});
expect(execute).toThrow('Failed to get drive item. status: 400');
});
/**
* POST リクエストのテスト
* @param {Object} request
* @param request.url
* @param request.method
* @param request.contentType
* @param request.body
* @param driveId
* @param folderId
* @param folderName
*/
const assertPostRequest = ({url, method, contentType, body}, driveId, folderId, folderName) => {
expect(url).toEqual(`${GRAPH_URI}${driveId}/items/${folderId}/children`);
expect(method).toEqual('POST');
expect(contentType).toEqual("application/json; charset=UTF-8");
const bodyObj = JSON.parse(body);
expect(bodyObj.name).toEqual(folderName);
};
const SAMPLE_GET1 = {
"id":"Id001",
"parentReference":{
"driveId":"Drive001"
}
};
/**
* フォルダ作成成功 - 親フォルダURLをデータ項目で指定
*/
test('201 Success - Specify Parent Folder URL as a data item', () => {
const folderUrlDef = prepareConfigs('https://test-my.sharepoint.com/personal/aaa/Documents/parent3', 'folder3');
let reqCount = 0;
httpClient.setRequestHandler((request) => {
if (reqCount === 0) {
assertGetRequest(request, 'https://test-my.sharepoint.com/personal/aaa/Documents/parent3');
reqCount++;
return httpClient.createHttpResponse(200, 'application/json', JSON.stringify(SAMPLE_GET1));
}
assertPostRequest(request, 'drives/Drive001', 'Id001', 'folder3');
return httpClient.createHttpResponse(201, 'application/json', `{"webUrl":"https://test-my.sharepoint.com/personal/aaa/Documents/parent3/folder3"}`);
});
execute();
// 文字型データ項目の値をチェック
expect(engine.findData(folderUrlDef)).toEqual('https://test-my.sharepoint.com/personal/aaa/Documents/parent3/folder3');
});
const SAMPLE_GET2 = {
"id":"Id002",
"parentReference":{
"driveId":"Drive002"
}
};
/**
* フォルダ作成成功 - 親フォルダURLを固定値で指定
*/
test('201 Success - Specify Parent Folder URL with a fixed value', () => {
const folderUrlDef = prepareConfigs(null, 'folder4');
configs.put('conf_parentFolderUrl', 'https://test-my.sharepoint.com/personal/aaa/Documents/parent4');
let reqCount = 0;
httpClient.setRequestHandler((request) => {
if (reqCount === 0) {
assertGetRequest(request, 'https://test-my.sharepoint.com/personal/aaa/Documents/parent4');
reqCount++;
return httpClient.createHttpResponse(201, 'application/json', JSON.stringify(SAMPLE_GET2));
}
assertPostRequest(request, 'drives/Drive002', 'Id002', 'folder4');
return httpClient.createHttpResponse(201, 'application/json', `{"webUrl":"https://test-my.sharepoint.com/personal/aaa/Documents/parent4/folder4"}`);
});
execute();
// 文字型データ項目の値をチェック
expect(engine.findData(folderUrlDef)).toEqual('https://test-my.sharepoint.com/personal/aaa/Documents/parent4/folder4');
});
/**
* フォルダ作成成功 - 親フォルダURLをデータ項目で指定し、その値が空
*/
test('201 Success - Specify Parent Folder URL as a data item and its value is blank', () => {
const folderUrlDef = prepareConfigs(null, 'folder5');
httpClient.setRequestHandler((request) => {
assertPostRequest(request, 'me/drive', 'root', 'folder5');
return httpClient.createHttpResponse(201, 'application/json', `{"webUrl":"https://test-my.sharepoint.com/personal/staff_questetra365_onmicrosoft_com/Documents/folder5"}`);
});
execute();
// 文字型データ項目の値をチェック
expect(engine.findData(folderUrlDef)).toEqual('https://test-my.sharepoint.com/personal/staff_questetra365_onmicrosoft_com/Documents/folder5');
});
/**
* POST リクエストでエラー - 親フォルダURLを固定値で指定し、その値が空
*/
test('POST Failed - Specify the parent folder URL with a fixed value, and that value is blank', () => {
const folderUrlDef = prepareConfigs(null, 'folder6');
configs.put('conf_parentFolderUrl', '');
httpClient.setRequestHandler((request) => {
assertPostRequest(request, 'me/drive', 'root', 'folder6');
return httpClient.createHttpResponse(400, 'application/json', '{}');
});
expect(execute).toThrow('Failed to create: folder6. status: 400');
});
/**
* フォルダ作成成功 - 親フォルダURLを固定値で指定し、その値が空
*/
test('201 Success - Specify the parent folder URL with a fixed value, and that value is blank', () => {
const folderUrlDef = prepareConfigs(null, 'folder7');
configs.put('conf_parentFolderUrl', '');
httpClient.setRequestHandler((request) => {
assertPostRequest(request, 'me/drive', 'root', 'folder7');
return httpClient.createHttpResponse(201, 'application/json', `{"webUrl":"https://test-my.sharepoint.com/personal/staff_questetra365_onmicrosoft_com/Documents/folder7"}`);
});
execute();
// 文字型データ項目の値をチェック
expect(engine.findData(folderUrlDef)).toEqual('https://test-my.sharepoint.com/personal/staff_questetra365_onmicrosoft_com/Documents/folder7');
});
]]>