import { describe, expect, it } from "vitest";
import { createConfig } from "../../config.js";
import type { Secrets } from "../../secrets.js";

const baseSecrets: Secrets = {
  supabaseServiceRoleKey: "service-role-from-secret-manager",
  supabaseConnectionString: "postgres://secret-manager",
  supabaseCaCert: "ca-cert",
  emailClientSecret: "email-client-secret",
  emailRefreshToken: "email-refresh-token",
  r2AccessKeyId: "r2-access-key-id",
  r2SecretAccessKey: "r2-secret-access-key",
  streamChatApiSecret: "stream-chat-api-secret",
  stripeSecretKey: "sk_live_secret_manager",
  stripeWebhookSecret: "whsec_live_secret_manager",
  streamChatApiSecretStaging: "stream-chat-api-secret-staging",
  stripeSecretKeyStaging: "sk_live_staging_secret_manager",
  stripeWebhookSecretStaging: "whsec_live_staging_secret_manager",
};

describe("createConfig stripe env overrides", () => {
  it("prefers env stripe keys in development to avoid local sandbox/account mismatch", () => {
    process.env.NODE_ENV = "development";
    process.env.STRIPE_SECRET_KEY = "sk_test_env_override";
    process.env.STRIPE_WEBHOOK_SECRET = "whsec_test_env_override";

    const config = createConfig(baseSecrets);

    expect(config.STRIPE_SECRET_KEY).toBe("sk_test_env_override");
    expect(config.STRIPE_WEBHOOK_SECRET).toBe("whsec_test_env_override");
  });
});
