package placement

import (
	"strings"
	"testing"
)

func TestApplyPlacementURL(t *testing.T) {
	raw := `{"brand":"ecostore","product":"沐浴露","features":"無香抗敏"}`
	got := ApplyPlacementURL(raw, "https://shop.example.com/body-wash")
	formatted := ProductBriefFromContext(got)
	if !strings.Contains(formatted, "留言 CTA 連結") || !strings.Contains(formatted, "https://shop.example.com/body-wash") {
		t.Fatalf("formatted brief = %q", formatted)
	}

	existing := SerializeProductContext(ProductContextFields{
		Brand:   "ecostore",
		Product: "沐浴露",
		CtaType: CtaLink,
		CtaUrl:  "https://existing.example.com",
	})
	if changed := ApplyPlacementURL(existing, "https://new.example.com"); changed != existing {
		t.Fatalf("should not override existing cta url")
	}
}
