package handlers import ( "database/sql" "demoon/config" "demoon/internal/models" "log/slog" "net/http" "net/http/httptest" "testing" "github.com/stretchr/testify/assert" ) func TestGetQuestionHandler(t *testing.T) { t.Run("get existing question", func(t *testing.T) { // Setup mock repository mockRepo := &MockRepo{} handlers := NewHandlers(config.Config{}, slog.Default(), mockRepo) // Test request/response req := httptest.NewRequest("GET", "/question/1", nil) w := httptest.NewRecorder() // Call handler directly GetQuestion(w, req) // Verify response resp := w.Result() assert.Equal(t, http.StatusOK, resp.StatusCode) // Add more assertions about response body }) } type MockRepo struct { questions map[uint32]*models.Question } func (m *MockRepo) DBGetQuestion(id string) (*models.Question, error) { if q, ok := m.questions[1]; ok { return q, nil } return nil, sql.ErrNoRows } func (m *MockRepo) DBGetDefaultsMap() (map[string]string, error) { return map[string]string{}, nil }