package actionvalidate

import (
	"strings"
	"testing"
)

func TestStrictChildCopyInConfigPointsAuthorsToFlowOwnedContract(t *testing.T) {
	err := StrictChildCopyInConfig("CloneChildren", map[string]interface{}{
		"workflow": map[string]interface{}{
			"childCopy": []interface{}{
				map[string]interface{}{"sourceObject": "LineItem"},
			},
		},
	})
	if err == nil {
		t.Fatal("StrictChildCopyInConfig = nil, want retired-surface error")
	}

	msg := err.Error()
	for _, want := range []string{
		"#979 Flow-owned create contract",
		"_System_ObjectFieldMapping",
		"Flow expressions, lookups, loops, and recordCreate",
		"legacy/transitional compatibility install primitive",
	} {
		if !strings.Contains(msg, want) {
			t.Fatalf("StrictChildCopyInConfig error = %q, want %q", msg, want)
		}
	}
	for _, forbidden := range []string{
		"Move the rule",
		"source-backed object_spec childCloneRules",
		"object-level authoring site _System_Object.ChildCloneRules",
	} {
		if strings.Contains(msg, forbidden) {
			t.Fatalf("StrictChildCopyInConfig error = %q, must not direct authors to %q", msg, forbidden)
		}
	}
}
