import { describe, expect, it } from "vitest";
import { qqDnaEmailPool } from "@/lib/flock/qqdna-email-pool";
import { createFreshFlockTestAccount } from "@/lib/flock/fresh-account";

describe("qqDnaEmailPool", () => {
  it("全部为合法长度 QQ@qq.com", () => {
    const pool = qqDnaEmailPool();
    expect(pool.length).toBeGreaterThan(50);
    for (const email of pool) {
      expect(email).toMatch(/^\d{5,11}@qq\.com$/);
    }
  });
});

describe("FLOCK_EMAIL_MODE=qqdna", () => {
  it("轮询取 qqdna 池", () => {
    const prev = process.env.FLOCK_EMAIL_MODE;
    process.env.FLOCK_EMAIL_MODE = "qqdna";
    delete process.env.FLOCK_EMAIL_POOL;
    const a = createFreshFlockTestAccount();
    const b = createFreshFlockTestAccount();
    expect(a.email).toMatch(/^\d{5,11}@qq\.com$/);
    expect(b.email).toMatch(/^\d{5,11}@qq\.com$/);
    expect(a.email).not.toBe(b.email);
    process.env.FLOCK_EMAIL_MODE = prev;
  });
});
