package commerce

import "testing"

func TestNormalizeTicketStoragePath(t *testing.T) {
	for input, want := range map[string]string{
		"ticket-images/2026/07/a.png":                         "ticket-images/2026/07/a.png",
		"/media/ticket-images/2026/07/a.png":                  "ticket-images/2026/07/a.png",
		"data/ticket-attachments/ticket-images/2026/07/a.png": "ticket-images/2026/07/a.png",
		`ticket-images\2026\07\a.png`:                         "ticket-images/2026/07/a.png",
	} {
		got, err := normalizeTicketStoragePath(input)
		if err != nil {
			t.Fatalf("normalizeTicketStoragePath(%q): %v", input, err)
		}
		if got != want {
			t.Fatalf("normalizeTicketStoragePath(%q) = %q, want %q", input, got, want)
		}
	}
}

func TestNormalizeTicketStoragePathRejectsTraversalAndOtherRoots(t *testing.T) {
	for _, input := range []string{"", "../secret", "ticket-images/../../secret", "/etc/passwd", "other/a.png"} {
		if got, err := normalizeTicketStoragePath(input); err == nil {
			t.Fatalf("normalizeTicketStoragePath(%q) = %q, want error", input, got)
		}
	}
}
