/**
 * Authentication Helper for Playwright Tests
 *
 * Shared authentication utilities for all test files.
 * Credentials can be overridden via environment variables.
 */

const TEST_USERNAME = process.env.TEST_USERNAME || 'test_admin';
const TEST_PASSWORD = process.env.TEST_PASSWORD || 'testpass123';

/**
 * Authenticate a page by logging in with test credentials
 * @param {import('@playwright/test').Page} page - Playwright page object
 */
async function authenticate(page) {
  await page.goto('/auth/login');
  await page.fill('input[name="username"]', TEST_USERNAME);
  await page.fill('input[name="password"]', TEST_PASSWORD);
  await page.click('button[type="submit"]');
  await page.waitForURL('/', { timeout: 30000 });
}

module.exports = { authenticate, TEST_USERNAME, TEST_PASSWORD };
