4ec1a3f4dd
refactor(测试): 重构用户数据加载逻辑以支持数组格式 fix(数据库): 修正数据库连接配置和凭证 test: 添加新的导航和用户管理测试场景 docs: 生成UAT测试报告和最终报告 ci: 更新Woodpecker CI配置和测试命令 build: 添加application-test.yml配置文件 chore: 清理旧的测试场景文件
48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import * as fs from 'fs';
|
|
import * as path from 'path';
|
|
import { uatConfig } from '../config/uat-config';
|
|
|
|
export interface TestData {
|
|
users: any[];
|
|
roles: any[];
|
|
scenarios: any;
|
|
}
|
|
|
|
export class DataLoader {
|
|
private static data: TestData | null = null;
|
|
|
|
static load(): TestData {
|
|
if (!this.data) {
|
|
const usersPath = path.join(uatConfig.testDataPath, 'users.json');
|
|
const rolesPath = path.join(uatConfig.testDataPath, 'roles.json');
|
|
const scenariosPath = path.join(uatConfig.testDataPath, 'scenarios.json');
|
|
|
|
this.data = {
|
|
users: JSON.parse(fs.readFileSync(usersPath, 'utf-8')),
|
|
roles: JSON.parse(fs.readFileSync(rolesPath, 'utf-8')),
|
|
scenarios: JSON.parse(fs.readFileSync(scenariosPath, 'utf-8'))
|
|
};
|
|
}
|
|
return this.data;
|
|
}
|
|
|
|
static getUserByRole(role: string): any {
|
|
const data = this.load();
|
|
if (Array.isArray(data.users)) {
|
|
return data.users.find((user: any) => user.role === role || user.username === role) || null;
|
|
} else {
|
|
return data.users[role] || null;
|
|
}
|
|
}
|
|
|
|
static getUsersByScenario(scenarioName: string): any[] {
|
|
const data = this.load();
|
|
const scenario = data.scenarios[scenarioName];
|
|
return scenario?.users || [];
|
|
}
|
|
|
|
static reset() {
|
|
this.data = null;
|
|
}
|
|
}
|