package submit

import (
	"strings"
	"testing"
)

func TestBuildMessagePublishesProfileIdentityAndTransportSender(t *testing.T) {
	sub := Submission{
		From:         "Alice <alice@example.invalid>",
		Newsgroups:   []string{"misc.test"},
		Subject:      "Test",
		Message:      "hello",
		PublicKeyB64: "unused-without-face",
		SignatureB64: "unused-without-face",
	}

	raw, _, err := BuildMessage(
		sub,
		"mail2news@mail2news.tcpreset.net",
		"n2usenet@virebent.art",
		"n2usenet.virebent.art",
		"/missing/identicons-cli",
		false,
	)
	if err != nil {
		t.Fatalf("BuildMessage returned error: %v", err)
	}
	if !strings.Contains(raw, "From: \"Alice\" <alice@example.invalid>\r\n") {
		t.Fatalf("profile identity is not used as the public From:\n%s", raw)
	}
	if !strings.Contains(raw, "Sender: <n2usenet@virebent.art>\r\n") {
		t.Fatalf("transport Sender is missing:\n%s", raw)
	}
	if strings.Contains(raw, "From: \"Alice\" <n2usenet@virebent.art>\r\n") {
		t.Fatalf("transport account replaced the public profile identity:\n%s", raw)
	}
	if strings.Contains(raw, "X-N2Usenet-Identity:") {
		t.Fatalf("redundant private identity header is present:\n%s", raw)
	}
}
