import { describe, expect, it } from "vitest";
import { buildMailHeaders } from "./buildMailHeaders";

describe("buildMailHeaders", () => {
  it("includes X-SES-CONFIGURATION-SET when a configuration set is provided", () => {
    const headers = buildMailHeaders({
      fromAddress: "test-sender@example.test",
      sesConfigurationSet: "test-config-set",
    });

    expect(headers["X-SES-CONFIGURATION-SET"]).toBe("test-config-set");
  });

  it("omits X-SES-CONFIGURATION-SET entirely when no configuration set is provided", () => {
    const headers = buildMailHeaders({
      fromAddress: "test-sender@example.test",
      sesConfigurationSet: undefined,
    });

    expect(headers).not.toHaveProperty("X-SES-CONFIGURATION-SET");
  });

  it("always includes a List-Unsubscribe mailto pointing at the from address", () => {
    const headers = buildMailHeaders({
      fromAddress: "test-sender@example.test",
      sesConfigurationSet: undefined,
    });

    expect(headers["List-Unsubscribe"]).toBe("<mailto:test-sender@example.test>");
  });
});
