package service

import "testing"

func TestNormalizeRoutePath(t *testing.T) {
	tests := []struct {
		name   string
		path   string
		prefix string
		want   string
	}{
		{name: "empty prefix", path: "/api/login", prefix: "", want: "/api/login"},
		{name: "configured prefix", path: "/admin/api/login", prefix: "/admin", want: "/api/login"},
		{name: "trailing slash prefix", path: "/admin/api/login", prefix: "/admin/", want: "/api/login"},
		{name: "prefix root", path: "/admin", prefix: "/admin", want: "/"},
		{name: "prefix boundary", path: "/administrator/api/login", prefix: "/admin", want: "/administrator/api/login"},
		{name: "already normalized", path: "/api/login", prefix: "/admin", want: "/api/login"},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			if got := NormalizeRoutePath(tt.path, tt.prefix); got != tt.want {
				t.Fatalf("NormalizeRoutePath(%q, %q) = %q, want %q", tt.path, tt.prefix, got, tt.want)
			}
		})
	}
}
