package store

import "testing"

func TestAcceptanceMetadataRedactsSecrets(t *testing.T) {
	value := sanitizeAcceptanceMetadata(map[string]any{
		"token": "raw-token",
		"nested": map[string]any{
			"databaseUrl": "postgresql://example.invalid/database",
			"taskCount":   1200,
		},
	})
	next := value.(map[string]any)
	if next["token"] != "[REDACTED]" {
		t.Fatalf("token=%v", next["token"])
	}
	nested := next["nested"].(map[string]any)
	if nested["databaseUrl"] != "[REDACTED]" || nested["taskCount"] != 1200 {
		t.Fatalf("nested=%v", nested)
	}
}

func TestAcceptanceURLsMustBeAbsoluteAndCredentialFree(t *testing.T) {
	for _, raw := range []string{
		"http://acceptance-emulator.easyai.svc.cluster.local:8090",
		"https://acceptance.example.invalid/callbacks",
	} {
		if !validAcceptanceURL(raw) {
			t.Fatalf("valid URL rejected: %s", raw)
		}
	}
	for _, raw := range []string{"relative/path", "ftp://example.invalid/file", "https://user:pass@example.invalid"} {
		if validAcceptanceURL(raw) {
			t.Fatalf("invalid URL accepted: %s", raw)
		}
	}
}
