package main

import "testing"

func TestNormalizeUserIDsSortsAndDeduplicatesExactSet(t *testing.T) {
	got, err := normalizeUserIDs([]int64{42, 7, 42})
	if err != nil {
		t.Fatalf("normalizeUserIDs failed: %v", err)
	}
	if len(got) != 2 || got[0] != 7 || got[1] != 42 {
		t.Fatalf("normalized IDs mismatch: %+v", got)
	}
	if fingerprint := userIDsSHA256(got); fingerprint != userIDsSHA256([]int64{7, 42}) {
		t.Fatalf("fingerprint must be stable, got %s", fingerprint)
	}
}

func TestNormalizeUserIDsRejectsUnsafeSets(t *testing.T) {
	for _, values := range [][]int64{nil, {0}, {-1}} {
		if _, err := normalizeUserIDs(values); err == nil {
			t.Fatalf("unsafe user IDs must fail: %+v", values)
		}
	}
}
