// Integration test setup

const path = require("path");
require("dotenv").config({ path: path.join(__dirname, "..", ".env.test") });

process.env.NODE_ENV = "test";

// Required environment variables - fail fast if missing
const requiredEnvVars = [
  "JWT_ACCESS_SECRET",
  "JWT_REFRESH_SECRET",
  "CSRF_SECRET",
  "TOTP_ENCRYPTION_KEY",
];

const missingVars = requiredEnvVars.filter((v) => !process.env[v]);
if (missingVars.length > 0) {
  throw new Error(
    `Missing required environment variables for integration tests: ${missingVars.join(", ")}\n` +
      `Please ensure these are set in your .env.test file.`,
  );
}

// Optional variables with safe defaults
process.env.JWT_SECRET =
  process.env.JWT_SECRET || process.env.JWT_ACCESS_SECRET;
process.env.EMAIL_ENABLED = "false";
process.env.FRONTEND_URL = process.env.FRONTEND_URL || "http://localhost:3000";
process.env.GOOGLE_MAPS_API_KEY = process.env.GOOGLE_MAPS_API_KEY || "test-key";
process.env.STRIPE_SECRET_KEY = process.env.STRIPE_SECRET_KEY || "sk_test_key";
