package utils

import "testing"

func TestParseAuditDetails(t *testing.T) {
	t.Run("empty details returns error", func(t *testing.T) {
		if _, err := ParseAuditDetails(""); err == nil {
			t.Fatalf("expected empty details error")
		}
	})

	t.Run("invalid JSON returns error", func(t *testing.T) {
		if _, err := ParseAuditDetails("{invalid"); err == nil {
			t.Fatalf("expected invalid JSON error")
		}
	})

	t.Run("valid JSON returns payload", func(t *testing.T) {
		payload, err := ParseAuditDetails(`{"actor":"admin","count":2}`)
		if err != nil {
			t.Fatalf("unexpected error: %v", err)
		}
		if payload["actor"] != "admin" || payload["count"] != float64(2) {
			t.Fatalf("unexpected payload: %#v", payload)
		}
	})
}
