package server

import (
	"net/http"
	"testing"
)

func TestIsGlobalRoute(t *testing.T) {
	t.Parallel()
	tests := []struct {
		method string
		path   string
		want   bool
	}{
		{http.MethodGet, "/api/ext/v1", true},
		{http.MethodGet, "/api/ext/v1/openapi.json", true},
		{http.MethodPost, "/api/ext/v1/agents", true},
		{http.MethodPost, "/api/ext/v1/oidc/session", true},
		{http.MethodPost, "/api/ext/v1/analytics/events", true},
		{http.MethodGet, "/login/device", true},
		{http.MethodPost, "/login/device/code", true},
		{http.MethodGet, "/auth/connected/login", true},
		{http.MethodGet, "/api/v3/users/alice/starred", true},
		{http.MethodGet, "/avatars/alice", true},
		{http.MethodOptions, "/api/ext/v1/user", true},
		{http.MethodGet, "/api/ext/v1/user", false},
		{http.MethodPost, "/api/graphql", false},
		{http.MethodGet, "/api/v3/repos/acme/repo", false},
		{http.MethodGet, "/owner/repo.git/info/refs", false},
	}
	for _, test := range tests {
		t.Run(test.method+" "+test.path, func(t *testing.T) {
			if got := IsGlobalRoute(test.method, test.path); got != test.want {
				t.Fatalf("IsGlobalRoute(%q, %q) = %v, want %v", test.method, test.path, got, test.want)
			}
		})
	}
}
