2023-09-29
(C) Questetra, Inc. (MIT License)
3
2
This item gets a label ID on Trello.
この工程は、Trello のラベル ID を取得します。
https://support.questetra.com/bpmn-icons/service-task-trello-labelid-get/
https://support.questetra.com/ja/bpmn-icons/service-task-trello-labelid-get/
iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAzBJREFUWEfF
l11IFFEUx/93xnH9iPzow0jBaIOsSNJWI+glX6KHJLcvkiKwF7WXolJ76iWiSLBeUortoSSLcDfp
pZfwJXrQVV8MIsNEjFbwI5T1e/bGndnZnRlnZ8ZZau/b3HvuOb97zrnnniFI8SC27Z8KZoGPeMHz
x0FpGSh2gSBP2k8xC4IxEDIEUeyFyPnxwbNgR7c1wLm+HRBJM0DqAWTYUQpgCaAd4OlDvKsMme0x
B6gJ1oOgFUC2TcN6sTAobiHg6Ui0PzGAN/gUQINDw/pt7fB7Go10GQPU9L8GIRfZhgyBQ3qadaSM
lM8tivFpSrsQqKjVy63XHD15aXEmAs1u7C5wOXbCyhqF79MUGp+NKzrWeUILIMe8nUl/uV+Co3ud
hl7L7G4cxujksjxJ0aDOiTiAlO3cDyXhlt6UwyU4c73eZQ8CIdzp/KVMh8FH9ii3I27B298GkOuK
1PLbck3s5xdF/AnLMXUJHLbnpMXsrIoUodlV6ZvjCHbmCSAq9taeSdx+OaHioo/hr7jBJmQxVmQE
TKvvuRogQgH+7IDmYCFfKQpyBWmutu0nuj7PxNZ914pRV7U19r0eAEtYxRZWrGSA032XwHGv1BbU
ACyZXBcGNQBjHQdRvC1dmjt5bwQfh+biBq8U4WZ1gRkAEIlcxvvKThngzIAPlNb9VwBCXqD78FUZ
wBtkxyv7rwDAEPyechmgJjgTe1iiFP88BOwBC3jyFQ9QTYABbASAZThLNGX0tLhRXZFrngNs1e+J
XhZvMCkApovdFDbYidRXkM0Z3AJZOAaQZAj03tN/GwLoQpBUEjoC0CShxTVcEymE89o6MPG8FIX5
ciGyGoYe0FxDi0LEDIxPrWB6fk2ylZnOoaTQbnOUIAc0hciiFFud0GrduhRLxcj8MbIyYrb+qGcS
TaaPEdute46/PjmA/UX23WwGcKTlG/pGwopIgueYLasakhOHNqO7yY1sF5fM4dE7PI+qu9/jOhI2
JIqIrhk9tm8TcrJ4RxCDowv4He0TogosWjLFjKopdWTZaJPtpjSBJ5IE2WBbHvNEKn9MFIiU/pqp
/Z6yn9Mkg2+1/S+COKkwjkUALAAAAABJRU5ErkJggg==
{
const authKey = httpClient.createAuthSettingToken(
'Trello',
'TrelloApiKey',
);
configs.putObject('conf_ApiKey', authKey);
const authToken = httpClient.createAuthSettingToken(
'Trello',
'TrelloApiToken',
);
configs.putObject('conf_ApiToken', authToken);
configs.put('conf_BoardId', boardId);
configs.put('conf_LabelNames', labelNames);
// 文字型データ項目を準備して、config に指定
const labelIdDef = engine.createDataDefinition('ラベル ID を保存するデータ項目', 3, 'q_LabelId', 'STRING_TEXTAREA');
configs.putObject('conf_LabelId', labelIdDef);
engine.setData(labelIdDef, '事前文字列');
return labelIdDef;
};
/**
* 異常系のテスト
* @param func
* @param errorMsg
*/
const assertError = (func, errorMsg) => {
try {
func();
fail();
} catch (e) {
expect(e.toString()).toEqual(errorMsg);
}
};
/**
* 改行のみ
*/
test("Failed - Empty lines only", () => {
prepareConfigs('234BCD', '\n\n\n');
assertError(main, 'Empty lines are not allowed.');
});
/**
* 先頭や、途中に空行がある 末尾に2行以上の改行がある
*/
test("Failed - Empty lines are set", () => {
prepareConfigs('234BCD', '\nnenhancement\n\nlow-priority\n\n\n\n');
assertError(main, 'Empty lines are not allowed.');
});
/**
* GET リクエスト のテスト
* @param url
* @param method
* @param boardId
*/
const assertRequest = ({ url, method }, boardId) => {
expect(url).toEqual(`https://api.trello.com/1/boards/${boardId}/labels?key=TrelloApiKey&token=TrelloApiToken`);
expect(method).toEqual('GET');
};
/**
* GET リクエストで失敗 存在しないボード ID 、権限のないボード ID など
*/
test("GET Failed", () => {
prepareConfigs('234BCD', 'enhancement');
httpClient.setRequestHandler((request) => {
assertRequest(request, "234BCD");
return httpClient.createHttpResponse(404, "application/json", "{}");
});
assertError(main, 'Failed to get label information. status: 404');
});
/**
* GET リクエストのレスポンス(ボード内のラベル情報を取得)を準備
*/
const responseArray = [
{
"id": "1234567890abcde",
"idBoard": "0000011111",
"name": "enhancement",
"color": "red",
"users": 1
},
{
"id": "234567890abcde1",
"idBoard": "0000011111",
"name": "",
"color": "sky",
"users": 1
},
{
"id": "34567890abcde12",
"idBoard": "0000011111",
"name": "enhancement",
"color": "orange",
"users": 1
},
{
"id": "4567890abcde123",
"idBoard": "0000011111",
"name": "low-priority",
"color": "green",
"users": 1
},
{
"id": "567890abcde1234",
"idBoard": "0000011111",
"name": "midium-priority",
"color": "yellow",
"users": 1
},
{
"id": "67890abcde12345",
"idBoard": "0000011111",
"name": "enhancement",
"color": "blue",
"users": 1
}
];
/**
* 成功 - ラベル名を 1 つ指定 - ボード内に 同じラベル名が 3 つある場合
*/
test("Success - Three same label names on the board", () => {
const labelIdDef = prepareConfigs('123ABC', 'enhancement');
httpClient.setRequestHandler((request) => {
assertRequest(request, "123ABC");
return httpClient.createHttpResponse(200, 'application/json', JSON.stringify(responseArray));
});
main();
expect(engine.findData(labelIdDef)).toEqual('1234567890abcde');
});
/**
* 成功 - ラベル名を 2 つ指定 - ボード内に 1 つずつラベル名がある場合 - 末尾にひとつ改行がある
*/
test("Success - 2names - newline at the end", () => {
const labelIdDef = prepareConfigs('123ABC', 'low-priority\nmidium-priority\n');
httpClient.setRequestHandler((request) => {
assertRequest(request, "123ABC");
return httpClient.createHttpResponse(200, 'application/json', JSON.stringify(responseArray));
});
main();
expect(engine.findData(labelIdDef)).toEqual('4567890abcde123\n567890abcde1234');
});
/**
* 失敗 - ラベル名を 2 つ指定 - 1 つのラベル名が存在しない
*/
test("Failed - Label name does not exist", () => {
prepareConfigs('123ABC', 'enhancement\ntest');
httpClient.setRequestHandler((request) => {
assertRequest(request, "123ABC");
return httpClient.createHttpResponse(200, 'application/json', JSON.stringify(responseArray));
});
assertError(main, 'Label name: "test" not found in the Board');
});
]]>