chore: sync project snapshot for gitea/github upload
This commit is contained in:
@@ -10,12 +10,21 @@ const path = require('path');
|
||||
* 3. 准备测试数据
|
||||
* 4. 验证服务可用性
|
||||
*
|
||||
* 凭证配置:
|
||||
* - E2E_USER_TOKEN: 真实用户令牌(可选)
|
||||
* * 如果设置:使用真实凭证创建测试数据,严格模式
|
||||
* * 如果未设置:使用假token,降级模式(smoke测试)
|
||||
* - E2E_STRICT=true: 严格模式,无真实凭证时测试会失败并明确提示
|
||||
*
|
||||
* 如果无法创建真实数据,将使用默认占位数据
|
||||
*/
|
||||
|
||||
// 测试配置
|
||||
const API_BASE_URL = process.env.API_BASE_URL || 'http://localhost:8080';
|
||||
const TEST_USER_TOKEN = 'test-e2e-token-' + Date.now();
|
||||
// E2E_USER_TOKEN 环境变量:有真实凭证时直接使用,无则生成假token用于服务就绪检测
|
||||
const E2E_USER_TOKEN = process.env.E2E_USER_TOKEN;
|
||||
const TEST_USER_TOKEN = E2E_USER_TOKEN || 'test-e2e-token-' + Date.now();
|
||||
const USE_REAL_CREDENTIALS = Boolean(E2E_USER_TOKEN);
|
||||
|
||||
// 默认测试数据
|
||||
const DEFAULT_TEST_DATA = {
|
||||
@@ -152,7 +161,10 @@ async function createTestActivity() {
|
||||
);
|
||||
|
||||
if (response.status === 401 || response.status === 403) {
|
||||
throw new Error(`认证失败: ${response.status} - 需要有效的用户令牌`);
|
||||
if (USE_REAL_CREDENTIALS) {
|
||||
throw new Error(`认证失败: ${response.status} - 提供的 E2E_USER_TOKEN 无效,请检查凭证是否过期`);
|
||||
}
|
||||
throw new Error(`认证失败: ${response.status} - 需要有效的用户令牌(请设置 E2E_USER_TOKEN 环境变量)`);
|
||||
}
|
||||
|
||||
if (response.status !== 201) {
|
||||
@@ -186,7 +198,10 @@ async function generateApiKey(activityId) {
|
||||
);
|
||||
|
||||
if (response.status === 401 || response.status === 403) {
|
||||
throw new Error(`认证失败: ${response.status} - 需要有效的用户令牌`);
|
||||
if (USE_REAL_CREDENTIALS) {
|
||||
throw new Error(`认证失败: ${response.status} - 提供的 E2E_USER_TOKEN 无效,请检查凭证是否过期`);
|
||||
}
|
||||
throw new Error(`认证失败: ${response.status} - 需要有效的用户令牌(请设置 E2E_USER_TOKEN 环境变量)`);
|
||||
}
|
||||
|
||||
if (response.status !== 201) {
|
||||
@@ -220,7 +235,10 @@ async function createShortLink(activityId, apiKey) {
|
||||
);
|
||||
|
||||
if (response.status === 401 || response.status === 403) {
|
||||
throw new Error(`认证失败: ${response.status} - 需要有效的用户令牌`);
|
||||
if (USE_REAL_CREDENTIALS) {
|
||||
throw new Error(`认证失败: ${response.status} - 提供的 E2E_USER_TOKEN 无效,请检查凭证是否过期`);
|
||||
}
|
||||
throw new Error(`认证失败: ${response.status} - 需要有效的用户令牌(请设置 E2E_USER_TOKEN 环境变量)`);
|
||||
}
|
||||
|
||||
if (response.status !== 201) {
|
||||
|
||||
Reference in New Issue
Block a user