import {
  generateInsertStatement,
  generateUpdateStatement,
} from "@/utils/sqlHelpers";

describe("sqlHelpers SQL Statement Generation", () => {
  it("generates correct INSERT statement", () => {
    const contact = {
      name: "Alice",
      age: 30,
      isActive: true,
      tags: ["friend"],
    };
    const { sql, params } = generateInsertStatement(contact, "contacts");
    expect(sql).toBe(
      "INSERT INTO contacts (name, age, isActive, tags) VALUES (?, ?, ?, ?)",
    );
    expect(params).toEqual(["Alice", 30, 1, JSON.stringify(["friend"])]);
  });

  it("generates correct UPDATE statement", () => {
    const changes = { name: "Bob", isActive: false };
    const { sql, params } = generateUpdateStatement(
      changes,
      "contacts",
      "id = ?",
      [42],
    );
    expect(sql).toBe("UPDATE contacts SET name = ?, isActive = ? WHERE id = ?");
    expect(params).toEqual(["Bob", 0, 42]);
  });
});
