rdev/internal/handlers/sdlc_merge_test.go
jordan f22b220c6d feat: add SDLC branch management, merge, archive, and orchestrator APIs
Add branch lifecycle commands (branch, merge, archive) to the SDLC CLI.
Introduce orchestrator handler and service for multi-step SDLC workflows.
Expand skeleton template with 15 Claude commands covering the full feature
lifecycle. Extend classifier rules, error types, and executor port for
branch operations. Split rules.go and classifier_test.go to stay within
500-line limit.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 12:30:03 -07:00

92 lines
2.7 KiB
Go

package handlers
import (
"bytes"
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
"github.com/orchard9/rdev/internal/sdlc"
)
func TestSDLCHandler_MergeFeature(t *testing.T) {
exec := &testSDLCExecutor{}
_, router := setupSDLCHandler(exec)
req := httptest.NewRequest(http.MethodPost, "/projects/test-project/sdlc/features/auth-flow/merge", nil)
w := httptest.NewRecorder()
router.ServeHTTP(w, req)
if w.Code != http.StatusOK {
t.Errorf("expected status 200, got %d: %s", w.Code, w.Body.String())
}
}
func TestSDLCHandler_MergeFeature_WithStrategy(t *testing.T) {
exec := &testSDLCExecutor{}
_, router := setupSDLCHandler(exec)
body, _ := json.Marshal(MergeFeatureRequest{Strategy: "merge"})
req := httptest.NewRequest(http.MethodPost, "/projects/test-project/sdlc/features/auth-flow/merge", bytes.NewReader(body))
req.Header.Set("Content-Type", "application/json")
w := httptest.NewRecorder()
router.ServeHTTP(w, req)
if w.Code != http.StatusOK {
t.Errorf("expected status 200, got %d: %s", w.Code, w.Body.String())
}
}
func TestSDLCHandler_MergeFeature_NotReady(t *testing.T) {
exec := &testSDLCExecutor{err: sdlc.ErrMergeNotReady}
_, router := setupSDLCHandler(exec)
req := httptest.NewRequest(http.MethodPost, "/projects/test-project/sdlc/features/auth-flow/merge", nil)
w := httptest.NewRecorder()
router.ServeHTTP(w, req)
if w.Code != http.StatusBadRequest {
t.Errorf("expected status 400, got %d: %s", w.Code, w.Body.String())
}
}
func TestSDLCHandler_MergeFeature_FeatureNotFound(t *testing.T) {
exec := &testSDLCExecutor{err: sdlc.ErrFeatureNotFound}
_, router := setupSDLCHandler(exec)
req := httptest.NewRequest(http.MethodPost, "/projects/test-project/sdlc/features/nonexistent/merge", nil)
w := httptest.NewRecorder()
router.ServeHTTP(w, req)
if w.Code != http.StatusNotFound {
t.Errorf("expected status 404, got %d: %s", w.Code, w.Body.String())
}
}
func TestSDLCHandler_ArchiveFeature(t *testing.T) {
exec := &testSDLCExecutor{}
_, router := setupSDLCHandler(exec)
req := httptest.NewRequest(http.MethodPost, "/projects/test-project/sdlc/features/auth-flow/archive", nil)
w := httptest.NewRecorder()
router.ServeHTTP(w, req)
if w.Code != http.StatusOK {
t.Errorf("expected status 200, got %d: %s", w.Code, w.Body.String())
}
}
func TestSDLCHandler_ArchiveFeature_NotFound(t *testing.T) {
exec := &testSDLCExecutor{err: sdlc.ErrFeatureNotFound}
_, router := setupSDLCHandler(exec)
req := httptest.NewRequest(http.MethodPost, "/projects/test-project/sdlc/features/nonexistent/archive", nil)
w := httptest.NewRecorder()
router.ServeHTTP(w, req)
if w.Code != http.StatusNotFound {
t.Errorf("expected status 404, got %d: %s", w.Code, w.Body.String())
}
}