package webui import ( "net/http" "net/http/httptest" "strings" "testing" ) // The dashboard renders every action the task's status offers, so the handler // must accept each one the action service applies. func TestDecodeTaskActionAcceptsServiceActions(t *testing.T) { tests := []struct { action string want int }{ {action: "merge", want: http.StatusOK}, {action: "archive", want: http.StatusOK}, {action: "open_pr", want: http.StatusBadRequest}, {action: "bogus", want: http.StatusBadRequest}, } for _, tc := range tests { t.Run(tc.action, func(t *testing.T) { r := httptest.NewRequestWithContext(t.Context(), http.MethodPost, "/api/tasks/1/actions", strings.NewReader(`{"action":"`+tc.action+`"}`)) w := httptest.NewRecorder() if _, _, ok := decodeTaskAction(w, r); ok { w.WriteHeader(http.StatusOK) } if w.Code != tc.want { t.Fatalf("status = %d, want %d (%s)", w.Code, tc.want, strings.TrimSpace(w.Body.String())) } }) } }