Files
sam 0a37b551f5
Quality / check (push) Successful in 3m47s
deploy / gate (push) Successful in 4m32s
deploy / archied-image (push) Successful in 2m51s
deploy / agent-image (push) Successful in 10s
deploy / dist-zip (push) Skipped
refactor(webui): extract the tasks resource module (#1778)
2026-11-03 08:06:56 +11:00

35 lines
983 B
Go

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()))
}
})
}
}