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; } }