// Wiring test for the two-factor (TOTP) plugin: the Drizzle schema must carry
// the plugin's columns, and the auth instance must expose its server endpoints.
import { describe, expect, test } from "bun:test";
import { auth } from "../auth";
import { twoFactor, user } from "../db/auth-schema";

describe("two-factor plugin wiring", () => {
  test("user table has the twoFactorEnabled column", () => {
    expect(user.twoFactorEnabled).toBeDefined();
    expect(user.twoFactorEnabled.name).toBe("two_factor_enabled");
  });

  test("twoFactor table carries the plugin's documented columns", () => {
    // better-auth 1.6.17 schema: secret, backupCodes, userId, verified (no
    // failedVerificationCount/lockedUntil in this version).
    expect(twoFactor.secret.name).toBe("secret");
    expect(twoFactor.backupCodes.name).toBe("backup_codes");
    expect(twoFactor.userId.name).toBe("user_id");
    expect(twoFactor.verified.name).toBe("verified");
  });

  test("auth.api exposes the two-factor endpoints", () => {
    expect(typeof auth.api.enableTwoFactor).toBe("function");
    expect(typeof auth.api.disableTwoFactor).toBe("function");
    expect(typeof auth.api.verifyTOTP).toBe("function");
    expect(typeof auth.api.getTOTPURI).toBe("function");
    expect(typeof auth.api.verifyBackupCode).toBe("function");
    expect(typeof auth.api.generateBackupCodes).toBe("function");
  });
});
