import { describe, expect, test, vi } from "vitest";
import { createExecuteSync } from "./execute-sync.js";
describe("createExecuteSync", () => {
    test("passes through bound parameters unchanged", async () => {
        const exec = vi.fn().mockReturnValue([]);
        const sqlite = { exec };
        const preprocess = vi.fn(({ sql, parameters }) => ({
            sql,
            parameters,
        }));
        const executeSync = createExecuteSync({
            engine: {
                sqlite,
                hooks: {},
                runtimeCacheRef: {},
                preprocessQuery: preprocess,
            },
        });
        const parameters = [1, "two", { three: 3 }];
        executeSync({ sql: "SELECT ?", parameters });
        expect(preprocess).toHaveBeenCalledWith(expect.objectContaining({ sql: "SELECT ?", parameters, mode: "full" }));
        expect(exec).toHaveBeenCalledWith(expect.objectContaining({ bind: parameters }));
    });
    test("passes preprocessing mode through when provided", async () => {
        const exec = vi.fn().mockReturnValue([]);
        const sqlite = { exec };
        const preprocess = vi.fn(({ sql, parameters }) => ({
            sql,
            parameters,
        }));
        const executeSync = createExecuteSync({
            engine: {
                sqlite,
                hooks: {},
                runtimeCacheRef: {},
                preprocessQuery: preprocess,
            },
        });
        const sql = "SELECT 1";
        const parameters = [];
        executeSync({ sql, parameters, preprocessMode: "vtable-select-only" });
        expect(preprocess).toHaveBeenCalledWith(expect.objectContaining({ sql, parameters, mode: "vtable-select-only" }));
        expect(exec).toHaveBeenCalledWith(expect.objectContaining({ sql, bind: parameters }));
    });
    test("bypasses the preprocessor when specified", async () => {
        const exec = vi.fn().mockReturnValue([]);
        const sqlite = { exec };
        const preprocess = vi.fn();
        const executeSync = createExecuteSync({
            engine: {
                sqlite,
                hooks: {},
                runtimeCacheRef: {},
                preprocessQuery: preprocess,
            },
        });
        const sql = "SELECT 1";
        const parameters = [];
        executeSync({ sql, parameters, preprocessMode: "none" });
        expect(preprocess).not.toHaveBeenCalled();
        expect(exec).toHaveBeenCalledWith(expect.objectContaining({ sql, bind: parameters }));
    });
});
//# sourceMappingURL=execute-sync.test.js.map