2022-09-09
(C) Questetra, Inc. (MIT License)
2
https://support.questetra.com/bpmn-icons/service-task-stripe-customer-update/
https://support.questetra.com/ja/bpmn-icons/service-task-stripe-customer-update/
This item updates a customer object on Stripe. Fields with blank value remain unchanged.
この工程は、Stripe 上の顧客オブジェクトを更新します。値が設定されていない項目は変更されません。
-
-
iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAvJJREFUWEfF
l19I01EUxz/XKZqWNbVS6cH+UfSUGQlCD0EQRCkoFDkDUzENi6IgkB4sKEgjDStFnVlzalC9+BBR
IEFBEeVbFP3R/lhRpLRpKHO78dtv021u+pszfnv87Zzv+dxzzj33XoHOP6E1fvleGe9KJF/CDiSZ
CDIAo8d/BMkggn4BfVE27rX0ir9atOcEKC6WqdEOTkuoAOK0iALjAponY7jY0SF+zOYzK0CJSVYI
uAQkaAwcaDYm4VS7VTSH8g8JUFokryOpnGdgfzdBk7lTHAmmFRSgxCS7BBxYkOAeEQnd7VZRGKg5
A2BBVz4z2oxM+AF4at60kCsP1JJQ6dsTUwBKtxscvI+g4bRyjzljWOfdHVMAZSZZL+G4VpVI7AQ0
tFnFCUXDDaAMGWciv8PY55HEV3zHDTaSlWHlBigzySIJlvmoxsbBxHj4ngIOtllFpxug1CTNQMls
MjnbIS0d7t6etmpshe9DcKEmfACg3WwVpSpAoXyFIDNQZuMm2J2rfk1Ng6XL4NlTSE4Blwt6LOB0
QtEhkBKGvsCdHli9FnLzoe8h9L8MASfpN3eJLd4MDPscLFMeTTcgOhocDjXNi5fAr5+wYqUa+NOA
ClF9FiYnVdtHD2DnLpiYgNhYqKmGr5+DQoyYrSLJCyCDmdQ1gtEIdpv6r7LKbgscroKr9ZC/Dzpa
VIBr9VBeBYYoiDKotkLA/V7/svnGMVuFYuLugaAAx05C+ipIWa4KShe8eA7ZOdB4GQr2TwMMfoSM
NfDuLazfALY/YLdD9y148zp4GXwBgpag9goYk2BkGJ48hj15MDoK8QnQUAtZ26DrJrRaVMBRO9Sd
h7wC2JylAp87A9+G5ipBiCbU0ttbs6HiqFqCkA0XTCigCefchqFgFsWrO2TggxZcP5vpbRjJIAo7
rMfBbxDpPoo941i/w0gB0P04ViB0vZB4m0nXK5kXQtdL6X/JRLjXcp9M6Pcw8ULo+jTznXK6PU7n
O2q1+v0D2nRCMMki7aoAAAAASUVORK5CYII=
{
const sourceStr = 'あいうえおかきくけこ';
const string = sourceStr.repeat(Math.floor(length / sourceStr.length))
+ sourceStr.slice(0, length % sourceStr.length);
return string;
}
/**
* 設定の準備 - 顧客 ID を文字型データ項目で指定
* @param customerId
* @param name
* @param language
* @param email
* @param description
*/
const prepareConfigs = (customerId, name, language, email, description) => {
configs.put('conf_Auth', 'Stripe');
// 顧客 ID が保存されている文字型データ項目(単一行)を準備し、設定
const idDef = engine.createDataDefinition('顧客 ID', 1, 'q_customerId', 'STRING_TEXTFIELD');
engine.setData(idDef, customerId);
configs.putObject('conf_CustomerId', idDef);
configs.put('conf_Name', name);
configs.put('conf_Language', language);
configs.put('conf_Email', email);
configs.put('conf_Description', description);
}
/**
* 顧客 ID が空
*/
test('Customer ID is blank', () => {
prepareConfigs('', 'テスト顧客 1', 'ja-JP', 'test1@example.com', 'これはテスト顧客 1 です。');
expect(execute).toThrow('Customer ID is blank.');
});
/**
* 顧客の名前が長すぎる
*/
test('Customer Name is too long', () => {
const name = createString(NAME_MAX_LENGTH + 1);
prepareConfigs('cus_00001', name, 'ja-JP', 'test1@example.com', 'これはテスト顧客 1 です。');
expect(execute).toThrow(`Customer Name must be at most ${NAME_MAX_LENGTH} characters.`);
});
/**
* メールアドレスが長すぎる
*/
test('Customer Email is too long', () => {
const email = createString(EMAIL_MAX_LENGTH + 1);
prepareConfigs('cus_00001', 'テスト顧客 1', 'ja-JP', email, 'これはテスト顧客 1 です。');
expect(execute).toThrow(`Customer Email must be at most ${EMAIL_MAX_LENGTH} characters.`);
});
/**
* 説明が長すぎる
*/
test('Customer Description is too long', () => {
const description = createString(DESCRIPTION_MAX_LENGTH + 1);
prepareConfigs('cus_00001', 'テスト顧客 1', 'ja-JP', 'test1@example.com', description);
expect(execute).toThrow(`Customer Description must be at most ${DESCRIPTION_MAX_LENGTH} characters.`);
});
/**
* 更新すべき項目がない
*/
test('No fields to update', () => {
prepareConfigs('cus_00001', '', '', '', '');
expect(execute).toThrow('No fields to update.');
});
/**
* 顧客を更新する API リクエストのテスト
* @param {Object} request
* @param request.url
* @param request.method
* @param request.headers
* @param request.contentType
* @param request.body
* @param customerId
* @param name
* @param language
* @param email
* @param description
*/
const assertRequest = ({url, method, headers, contentType, body}, customerId, name, language, email, description) => {
expect(url).toEqual(`https://api.stripe.com/v1/customers/${encodeURIComponent(customerId)}`);
expect(method).toEqual('POST');
expect(headers.get('Stripe-Version')).toEqual(STRIPE_VERSION);
expect(contentType).startsWith('application/x-www-form-urlencoded');
const formParamList = [];
pushToListIfNotBlank(formParamList, 'name', name);
pushToListIfNotBlank(formParamList, 'preferred_locales[0]', language);
pushToListIfNotBlank(formParamList, 'email', email);
pushToListIfNotBlank(formParamList, 'description', description);
const expectedBody = formParamList.join('&')
.replace(/%20/g, '+'); // HttpRequestWrapper#formParam() はスペースを + に置き換える
expect(body).toEqual(expectedBody);
};
/**
* 値が空でない場合のみ、key=value 形式の文字列を list に追加する
* @param list
* @param key
* @param value
*/
const pushToListIfNotBlank = (list, key, value) => {
if (value !== '') {
list.push(`${encodeURIComponent(key)}=${encodeURIComponent(value)}`);
}
};
/**
* 顧客を更新する HTTP リクエストで失敗
*/
test('Fail to update customer', () => {
prepareConfigs('cus_00001', 'テスト顧客 1', 'ja-JP', 'test1@example.com', 'これはテスト顧客 1 です。');
httpClient.setRequestHandler((request) => {
assertRequest(request, 'cus_00001', 'テスト顧客 1', 'ja-JP', 'test1@example.com', 'これはテスト顧客 1 です。');
return httpClient.createHttpResponse(400, 'application/json', '{}');
});
expect(execute).toThrow('Failed to update customer. status: 400');
});
/**
* 成功 - 顧客 ID を文字型データ項目で指定し、すべての項目を更新
*/
test('Success - set customer ID by string-type data item, update all fields', () => {
const name = createString(NAME_MAX_LENGTH);
const email = createString(EMAIL_MAX_LENGTH);
const description = createString(DESCRIPTION_MAX_LENGTH);
prepareConfigs('cus_00001', name, 'ja-JP', email, description);
httpClient.setRequestHandler((request) => {
assertRequest(request, 'cus_00001', name, 'ja-JP', email, description);
return httpClient.createHttpResponse(200, 'application/json', '{}');
});
execute();
});
/**
* 成功 - 名前なし
*/
test('Success - without name', () => {
prepareConfigs('cus_00002', '', 'en-US', 'test2@example.com', 'これはテスト顧客 2 です。');
httpClient.setRequestHandler((request) => {
assertRequest(request, 'cus_00002', '', 'en-US', 'test2@example.com', 'これはテスト顧客 2 です。');
return httpClient.createHttpResponse(200, 'application/json', '');
});
execute();
});
/**
* 成功 - メールアドレスなし
*/
test('Success - without email', () => {
prepareConfigs('cus_00003', 'テスト顧客 3', 'en-US', '', 'これはテスト顧客 3 です。');
httpClient.setRequestHandler((request) => {
assertRequest(request, 'cus_00003', 'テスト顧客 3', 'en-US', '', 'これはテスト顧客 3 です。');
return httpClient.createHttpResponse(200, 'application/json', '');
});
execute();
});
/**
* 成功 - 言語なし
*/
test('Success - without language', () => {
prepareConfigs('cus_00004', 'テスト顧客 4', '', 'test4@example.com', 'これはテスト顧客 4 です。');
httpClient.setRequestHandler((request) => {
assertRequest(request, 'cus_00004', 'テスト顧客 4', '', 'test4@example.com', 'これはテスト顧客 4 です。');
return httpClient.createHttpResponse(200, 'application/json', '');
});
execute();
});
/**
* 成功 - 説明なし
*/
test('Success - without description', () => {
prepareConfigs('cus_00005', 'テスト顧客 5', 'en-US', 'test5@example.com', '');
httpClient.setRequestHandler((request) => {
assertRequest(request, 'cus_00005', 'テスト顧客 5', 'en-US', 'test5@example.com', '');
return httpClient.createHttpResponse(200, 'application/json', '');
});
execute();
});
/**
* 成功 - 顧客 ID を選択型データ項目で指定
*/
test('Success - customer ID is set by select-type data item', () => {
prepareConfigs('', 'テスト顧客', 'ja-JP', 'test@example.com', 'テスト顧客です。');
// 選択型データ項目を準備し、設定
const customerId = 'cus_00010';
const idDef = engine.createDataDefinition('顧客 ID を選択', 2, 'q_customerIdSelect', 'SELECT_SINGLE');
const select = new java.util.ArrayList();
const item = engine.createItem(customerId, `${customerId} を選択`);
select.add(item);
engine.setData(idDef, select);
configs.putObject('conf_CustomerId', idDef);
httpClient.setRequestHandler((request) => {
assertRequest(request, 'cus_00010', 'テスト顧客', 'ja-JP', 'test@example.com', 'テスト顧客です。');
return httpClient.createHttpResponse(200, 'application/json', '{}');
});
execute();
});
/**
* 顧客 ID を選択型データ項目で指定し、選択されていない
*/
test('Customer ID is set by select-type data item and it is not selected', () => {
prepareConfigs('cus_00011', 'テスト顧客', 'ja-JP', 'test@example.com', 'テスト顧客です。');
// 選択型データ項目を準備し、未選択のまま設定
const idDef = engine.createDataDefinition('顧客 ID を選択', 2, 'q_customerIdSelect', 'SELECT_SINGLE');
configs.putObject('conf_CustomerId', idDef);
expect(execute).toThrow('Customer ID is not selected.');
});
/**
* 成功 - 顧客 ID を固定値で指定
*/
test('Success - customer ID is set as fixed value', () => {
prepareConfigs('', 'テスト顧客', 'ja-JP', 'test@example.com', 'テスト顧客です。');
configs.put('conf_CustomerId', 'cus_00020');
httpClient.setRequestHandler((request) => {
assertRequest(request, 'cus_00020', 'テスト顧客', 'ja-JP', 'test@example.com', 'テスト顧客です。');
return httpClient.createHttpResponse(200, 'application/json', '{}');
});
execute();
});
]]>