summaryrefslogtreecommitdiff
path: root/internal/handlers/handlers_test.go
blob: 4eef3b9ef47ca3ab552381daa2a340253997e79a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package handlers

import (
	"fmt"
	"testing"

	"github.com/playwright-community/playwright-go"
	"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
		handlers.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
}