package connector_outboundintent

import "testing"

func TestAssociationRemoteLinkDependencyUsesStableWakeGroupAndExactReadiness(t *testing.T) {
	scope := outboundIntentTestScope()
	current := linkKeyForIdentity(scope, "owner", "current-slot", "Opportunity", "record", "destination")
	previous := linkKeyForIdentity(scope, "owner", "previous-slot", "Opportunity", "record", "destination")
	first := associationRemoteLinkDependency(
		scope, "owner", "Opportunity", "record", "destination", []string{current, previous},
	)
	second := associationRemoteLinkDependency(
		scope, "owner", "Opportunity", "record", "destination", []string{previous, current},
	)
	if first.Kind != dependencyKindAssociationRemoteLink || first.Key == "" || first.Key != second.Key {
		t.Fatalf("stable association wake group = %#v / %#v", first, second)
	}
	if len(first.ReadinessKeys) != 2 || first.ReadinessKeys[0] != current || first.ReadinessKeys[1] != previous {
		t.Fatalf("exact readiness candidates = %v", first.ReadinessKeys)
	}
	otherRecord := associationRemoteLinkDependency(
		scope, "owner", "Opportunity", "other-record", "destination", []string{current},
	)
	otherOwner := associationRemoteLinkDependency(
		scope, "other-owner", "Opportunity", "record", "destination", []string{current},
	)
	otherDestination := associationRemoteLinkDependency(
		scope, "owner", "Opportunity", "record", "other-destination", []string{current},
	)
	if first.Key == otherRecord.Key || first.Key == otherOwner.Key || first.Key == otherDestination.Key {
		t.Fatalf("unrelated association identities share wake group: %q", first.Key)
	}
}
