package opportunities import ( "net/http" "testing" "github.com/go-chi/chi/v5" ) // TestCaptureRoutesRegister is the module level route contract: it asserts the tenant capture surface mounts // exactly the expected method and path set. It does not touch the database; it proves the wiring, so a route // dropped or renamed in a refactor fails here rather than in production. func TestCaptureRoutesRegister(t *testing.T) { h := NewHandler(NewService(nil, nil)) r := chi.NewRouter() h.CaptureRoutes(r) got := map[string]bool{} err := chi.Walk(r, func(method, route string, _ http.Handler, _ ...func(http.Handler) http.Handler) error { got[method+" "+route] = true return nil }) if err != nil { t.Fatalf("walking the capture router: %v", err) } want := []string{ "POST /opportunities/tracked", "GET /opportunities/tracked", "GET /opportunities/tracked/{id}", "PATCH /opportunities/tracked/{id}", "GET /opportunities/tracked/{id}/scope", "POST /opportunities/tracked/{id}/scope/items", "PATCH /opportunities/tracked/{id}/scope/items/{item_id}", // Split and merge, Phase 2 item 4. They are listed here because the contract test only asserts what it // is TOLD to expect: an unlisted route passes silently, so adding a route without adding it here leaves // it unguarded, which is exactly how the promotion routes once sat unmounted. "POST /opportunities/tracked/{id}/scope/items/{item_id}/split", "POST /opportunities/tracked/{id}/scope/items/{item_id}/merge", "GET /opportunities/tracked/{id}/requirement-drafts", // Generation and manual completion, Phase 2 item 5. Both are held at scope.review, deliberately below // the promotion gate, so shaping a draft can never be the same act as making it live. "POST /opportunities/tracked/{id}/requirement-drafts/generate", "PATCH /requirement-drafts/{id}", "GET /opportunities/tracked/{id}/amendments", // The promotion gate. If either of these is ever unmounted, the safety path that lets a named human // turn a draft into a live requirement becomes unreachable, which is how it sat before this test. "POST /requirement-drafts/{id}/approve", "POST /requirement-drafts/{id}/reject", } for _, route := range want { if !got[route] { t.Errorf("capture route not registered: %s", route) } } }