diff --git a/internal/handlers/handlers_test.go b/internal/handlers/handlers_test.go index 49da78a..5cb6b9c 100644 --- a/internal/handlers/handlers_test.go +++ b/internal/handlers/handlers_test.go @@ -404,6 +404,24 @@ func TestHandleDashboard(t *testing.T) { assert.Equal(t, http.StatusOK, recorder.Code) assert.Contains(t, recorder.Body.String(), "Applications") }) + + t.Run("renders dashboard with apps without crashing on CSRFField", func(t *testing.T) { + t.Parallel() + + testCtx := setupTestHandlers(t) + + // Create an app so the template iterates over AppStats and hits .CSRFField + createTestApp(t, testCtx, "csrf-test-app") + + request := httptest.NewRequest(http.MethodGet, "/", nil) + recorder := httptest.NewRecorder() + + handler := testCtx.handlers.HandleDashboard() + handler.ServeHTTP(recorder, request) + + assert.Equal(t, http.StatusOK, recorder.Code, "dashboard should not 500 when apps exist (CSRFField must be accessible)") + assert.Contains(t, recorder.Body.String(), "csrf-test-app") + }) } func TestHandleAppNew(t *testing.T) {