import { test } from "node:test";
import assert from "node:assert/strict";
import { replyRouteForConversation } from "./replyRouting.ts";

test("web-mirrored conversations route through the companion send endpoint", () => {
  assert.deepEqual(
    replyRouteForConversation({ id: "web:LINKEDIN:chat-abc", account_id: "int1", external_id: "chat-abc" }),
    { kind: "web", conversationId: "chat-abc", integrationId: "int1" },
  );
});

test("local conversations keep the local send path", () => {
  assert.deepEqual(
    replyRouteForConversation({ id: "wa:123@s.whatsapp.net", account_id: "wp", external_id: "123@s.whatsapp.net" }),
    { kind: "local" },
  );
});

test("web-mirrored conversations require stored web ids", () => {
  assert.throws(
    () => replyRouteForConversation({ id: "web:LINKEDIN:chat-abc", account_id: null, external_id: "chat-abc" }),
    /account_id\/integrationId/,
  );
  assert.throws(
    () => replyRouteForConversation({ id: "web:LINKEDIN:chat-abc", account_id: "int1", external_id: null }),
    /external_id/,
  );
});
