import { describe, expect, it } from "vitest";

import { appendCommercialMessage } from "../helper/commercial-message";

describe("chat commercial message", () => {
  const incoming = {
    messageId: "payment-thanks-1",
    message: "Thank you for supporting me.",
    characterId: "maya-tan",
    createdAt: "2026-07-28T08:30:00.000Z",
  };

  it("appends one persisted payment thank-you to the matching character chat", () => {
    const messages = appendCommercialMessage([], "maya-tan", incoming);

    expect(messages).toHaveLength(1);
    expect(messages[0]).toMatchObject({
      remoteId: "payment-thanks-1",
      content: "Thank you for supporting me.",
      isFromAI: true,
    });
  });

  it("ignores duplicate delivery and a message for another character", () => {
    const messages = appendCommercialMessage([], "maya-tan", incoming);

    expect(appendCommercialMessage(messages, "maya-tan", incoming)).toEqual(
      messages,
    );
    expect(appendCommercialMessage(messages, "elio", incoming)).toEqual(
      messages,
    );
  });
});
