package main import ( "bytes" "encoding/json" "io" "net/http" "strings" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) // TestMediaNoteLengthLimits verifies the note content validator cap // (internal/handlers/media.go): content up to 100,000 chars is accepted, // longer content is rejected with 400. func TestMediaNoteLengthLimits(t *testing.T) { setup := setupTestServer(t) token := setup.Token mediaItemID := createTestMediaItemID(t, setup) postNote := func(content string) int { payload := map[string]interface{}{ "content": content, "position": "page:1", } body, _ := json.Marshal(payload) req, _ := http.NewRequest("POST", setup.Server.URL+"/api/media-items/"+mediaItemID+"/notes", bytes.NewBuffer(body)) req.Header.Set("Content-Type", "application/json") req.Header.Set("Authorization", "Bearer "+token) client := &http.Client{} resp, err := client.Do(req) require.NoError(t, err) defer func(Body io.ReadCloser) { _ = Body.Close() }(resp.Body) return resp.StatusCode } t.Run("50k-char note accepted", func(t *testing.T) { assert.Equal(t, http.StatusCreated, postNote(strings.Repeat("a", 50000))) }) t.Run("100k-char note accepted at boundary", func(t *testing.T) { assert.Equal(t, http.StatusCreated, postNote(strings.Repeat("b", 100000))) }) t.Run("over-limit note rejected", func(t *testing.T) { assert.Equal(t, http.StatusBadRequest, postNote(strings.Repeat("c", 100001))) }) }