feat: add UAT helper utilities and test data
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user