feat: add UAT helper utilities and test data

This commit is contained in:
张翔
2026-03-25 09:44:57 +08:00
parent a02c64169a
commit 9cfa3e68f6
6 changed files with 179 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
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();
return data.users.find(user => user.role === role);
}
static getUsersByScenario(scenarioName: string): any[] {
const data = this.load();
const scenario = data.scenarios[scenarioName];
return scenario?.users || [];
}
static reset() {
this.data = null;
}
}