import test from "node:test";
import assert from "node:assert/strict";
import { accountHandoffRequestIsCurrent, shouldConfirmAccountHandoff } from "./account-handoff.js";

test("account handoff confirmation is required only when the selected account differs", () => {
  assert.equal(shouldConfirmAccountHandoff("account-a", "account-b"), true);
  assert.equal(shouldConfirmAccountHandoff("account-a", "account-a"), false);
  assert.equal(shouldConfirmAccountHandoff("account-a", ""), false);
});

test("a pending handoff can send only for the unchanged chat and account pair", () => {
  const request = { sessionId: "session-1", fromAccountId: "account-a", toAccountId: "account-b" };

  assert.equal(accountHandoffRequestIsCurrent(request, "session-1", "account-a", "account-b"), true);
  assert.equal(accountHandoffRequestIsCurrent(request, "session-2", "account-a", "account-b"), false);
  assert.equal(accountHandoffRequestIsCurrent(request, "session-1", "account-a", "account-c"), false);
  assert.equal(accountHandoffRequestIsCurrent(request, "session-1", "account-b", "account-b"), false);
});
