76 lines
2.3 KiB
JavaScript
76 lines
2.3 KiB
JavaScript
/**
|
||
* 使用者資料流程冒煙測試
|
||
*
|
||
* 此測試用於 Dev/QA 環境,快速驗證使用者資料管理流程是否正常運作。
|
||
* 測試重點:完整流程可用性,不關注性能。
|
||
*/
|
||
|
||
import { registerWithCredentials } from '../../scenarios/apis/auth.js';
|
||
import { getAndUpdateProfileFlow, userProfileInitializationFlow } from '../../scenarios/e2e/user-profile-flow.js';
|
||
|
||
export const options = {
|
||
scenarios: {
|
||
smoke_user_profile_flow: {
|
||
executor: 'shared-iterations',
|
||
vus: 1,
|
||
iterations: 1,
|
||
maxDuration: '30s',
|
||
tags: { test_type: 'smoke', api: 'user', flow: 'profile' },
|
||
},
|
||
},
|
||
thresholds: {
|
||
checks: ['rate==1.0'], // 所有檢查必須通過
|
||
http_req_duration: ['p(95)<3000'], // 95% 的請求應在 3 秒內完成(流程測試允許稍長)
|
||
},
|
||
};
|
||
|
||
export default function () {
|
||
const baseUrl = __ENV.BASE_URL || 'http://localhost:8888';
|
||
const timestamp = Date.now();
|
||
const loginId = `smoke_flow_${timestamp}@example.com`;
|
||
const password = 'SmokeTest123!';
|
||
|
||
// 方式 1: 使用完整初始化流程(註冊 → 取得資訊 → 更新資訊)
|
||
console.log('測試完整使用者資料初始化流程...');
|
||
const initFlowResult = userProfileInitializationFlow({
|
||
baseUrl,
|
||
loginId,
|
||
password,
|
||
updateData: {
|
||
nickname: `SmokeFlow_${timestamp}`,
|
||
preferred_language: 'zh-tw',
|
||
currency: 'TWD',
|
||
},
|
||
});
|
||
|
||
if (!initFlowResult.success) {
|
||
console.error(`Smoke test failed: ${initFlowResult.step} - ${initFlowResult.error}`);
|
||
return;
|
||
}
|
||
|
||
console.log('完整初始化流程測試通過');
|
||
|
||
// 方式 2: 使用取得並更新流程(需要先有 Token)
|
||
// 這裡使用上面流程獲得的 Token
|
||
if (initFlowResult.tokens) {
|
||
console.log('測試取得並更新流程...');
|
||
const getUpdateFlowResult = getAndUpdateProfileFlow({
|
||
baseUrl,
|
||
accessToken: initFlowResult.tokens.accessToken,
|
||
updateData: {
|
||
nickname: `SmokeFlow_Updated_${timestamp}`,
|
||
preferred_language: 'en-us',
|
||
},
|
||
});
|
||
|
||
if (!getUpdateFlowResult.success) {
|
||
console.error(`Smoke test failed: ${getUpdateFlowResult.step} - ${getUpdateFlowResult.error}`);
|
||
return;
|
||
}
|
||
|
||
console.log('取得並更新流程測試通過');
|
||
}
|
||
|
||
console.log('Smoke test passed: All user profile flow operations succeeded');
|
||
}
|