import { IamClient, createIamClient } from '../../core/iam-client'; import { MemoryStorage } from '../../core/storage/memory-storage'; const API_URL = 'http://localhost:8081/api'; const API_KEY = 'god-is-just-a-good-developer'; const ADMIN_EMAIL = 'admin@applica.guru'; const ADMIN_PASSWORD = 'applica'; const CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; function createRandomString(length: number): string { return Array(length) .fill(0) .map(() => CHARS.charAt(Math.floor(Math.random() * CHARS.length))) .join(''); } function createClient(): IamClient { return createIamClient({ apiUrl: API_URL, storage: new MemoryStorage(), apiKey: API_KEY }); } async function createAdminClient(): Promise { const client = createClient(); await client.auth.login({ username: ADMIN_EMAIL, password: ADMIN_PASSWORD }); return client; } async function createUserAndLogin(client: IamClient): Promise<{ email: string; password: string; userId: string }> { const salt = createRandomString(4).toLowerCase(); const email = `test+${salt}@applica.guru`; const password = createRandomString(10); const name = `Test User (${salt})`; const registerResponse = await client.auth.register({ name, email, password }); const activationCode = registerResponse.userId.substring(0, 6); await client.auth.activate(activationCode); await client.auth.login({ username: email, password }); return { email, password, userId: registerResponse.userId }; } export { ADMIN_EMAIL, ADMIN_PASSWORD, API_KEY, API_URL, createAdminClient, createClient, createRandomString, createUserAndLogin };