import { afterEach, describe, expect, it } from "vitest";
import {
  FLOCK_POLL_TIMEOUT_DEFAULT_MS,
  getFlockPollTimeoutMs,
} from "@/lib/flock/poll-timeout";

describe("getFlockPollTimeoutMs", () => {
  const prev = {
    public: process.env.NEXT_PUBLIC_FLOCK_POLL_TIMEOUT_MS,
    server: process.env.FLOCK_POLL_TIMEOUT_MS,
  };

  afterEach(() => {
    process.env.NEXT_PUBLIC_FLOCK_POLL_TIMEOUT_MS = prev.public;
    process.env.FLOCK_POLL_TIMEOUT_MS = prev.server;
  });

  it("无 env 时默认 210s（覆盖 3 轮换）", () => {
    delete process.env.NEXT_PUBLIC_FLOCK_POLL_TIMEOUT_MS;
    delete process.env.FLOCK_POLL_TIMEOUT_MS;
    expect(getFlockPollTimeoutMs()).toBe(FLOCK_POLL_TIMEOUT_DEFAULT_MS);
  });

  it("优先 NEXT_PUBLIC_", () => {
    process.env.NEXT_PUBLIC_FLOCK_POLL_TIMEOUT_MS = "240000";
    process.env.FLOCK_POLL_TIMEOUT_MS = "90000";
    expect(getFlockPollTimeoutMs()).toBe(240_000);
  });
});
