import test from "node:test";
import assert from "node:assert/strict";
import { resolveActiveVertical } from "../resolve-active-vertical.js";
function mockSession(records, capture) {
    return {
        run: async (cypher, params) => {
            capture?.calls.push({ cypher, params });
            return {
                records: records.map((r) => ({
                    get: (key) => r[key],
                })),
            };
        },
    };
}
test("resolveActiveVertical: undefined accountId → brand-default", async () => {
    const session = mockSession([]);
    const result = await resolveActiveVertical({
        session,
        accountId: undefined,
        brandVertical: "schema-estate-agent",
    });
    assert.deepEqual(result, {
        resolvedVertical: "schema-estate-agent",
        source: "brand-default",
    });
});
test("resolveActiveVertical: empty-string accountId → brand-default (no query)", async () => {
    const capture = { calls: [] };
    const session = mockSession([], capture);
    const result = await resolveActiveVertical({
        session,
        accountId: "   ",
        brandVertical: "schema-estate-agent",
    });
    assert.equal(result.source, "brand-default");
    assert.equal(capture.calls.length, 0);
});
test("resolveActiveVertical: no LocalBusiness rows → brand-default", async () => {
    const session = mockSession([]);
    const result = await resolveActiveVertical({
        session,
        accountId: "acct-1",
        brandVertical: "schema-estate-agent",
    });
    assert.equal(result.source, "brand-default");
    assert.equal(result.resolvedVertical, "schema-estate-agent");
});
test("resolveActiveVertical: LocalBusiness without businessType → brand-default", async () => {
    const session = mockSession([{ businessType: null }]);
    const result = await resolveActiveVertical({
        session,
        accountId: "acct-1",
        brandVertical: "schema-estate-agent",
    });
    assert.equal(result.source, "brand-default");
    assert.equal(result.resolvedVertical, "schema-estate-agent");
});
test("resolveActiveVertical: LocalBusiness with businessType → localbusiness-override", async () => {
    const session = mockSession([{ businessType: "creator" }]);
    const result = await resolveActiveVertical({
        session,
        accountId: "acct-1",
        brandVertical: "schema-estate-agent",
    });
    assert.deepEqual(result, {
        resolvedVertical: "schema-creator",
        source: "localbusiness-override",
    });
});
test("resolveActiveVertical: businessType override wins when brandVertical is null", async () => {
    const session = mockSession([{ businessType: "creator" }]);
    const result = await resolveActiveVertical({
        session,
        accountId: "acct-1",
        brandVertical: null,
    });
    assert.deepEqual(result, {
        resolvedVertical: "schema-creator",
        source: "localbusiness-override",
    });
});
test("resolveActiveVertical: businessType whitespace-only → brand-default", async () => {
    const session = mockSession([{ businessType: "   " }]);
    const result = await resolveActiveVertical({
        session,
        accountId: "acct-1",
        brandVertical: "schema-estate-agent",
    });
    assert.equal(result.source, "brand-default");
});
test("resolveActiveVertical: query parameters bind accountId", async () => {
    const capture = { calls: [] };
    const session = mockSession([{ businessType: "creator" }], capture);
    await resolveActiveVertical({
        session,
        accountId: "acct-7",
        brandVertical: null,
    });
    assert.equal(capture.calls.length, 1);
    assert.deepEqual(capture.calls[0].params, { accountId: "acct-7" });
    assert.match(capture.calls[0].cypher, /:LocalBusiness/);
});
test("resolveActiveVertical: session.run rejection propagates", async () => {
    const session = {
        run: async () => {
            throw new Error("connection refused");
        },
    };
    await assert.rejects(resolveActiveVertical({
        session,
        accountId: "acct-1",
        brandVertical: null,
    }), /connection refused/);
});
//# sourceMappingURL=resolve-active-vertical.test.js.map