add "reading" filter for books currently being read

This commit is contained in:
2025-11-24 13:58:31 +01:00
parent 8c0a9fe431
commit 46492967a3
9 changed files with 154 additions and 2 deletions

View File

@@ -52,3 +52,22 @@ func TestGetWantReadBooksCountHandler_Demo(t *testing.T) {
}
assert.Equal(t, 2, c.Count)
}
func TestGetReadingBooksCountHandler_Demo(t *testing.T) {
router := testutils.TestSetup()
token := testutils.ConnectDemoUser(router)
req, _ := http.NewRequest("GET", "/mybooks/reading/count", nil)
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", token))
w := httptest.NewRecorder()
router.ServeHTTP(w, req)
var c countResponse
err := json.Unmarshal(w.Body.Bytes(), &c)
if err != nil {
t.Error(err)
}
assert.Equal(t, 2, c.Count)
}

View File

@@ -0,0 +1,44 @@
package apitest
import (
"net/url"
"testing"
"git.artlef.fr/PersonalLibraryManager/internal/testutils"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
)
func TestGetReadingBooksHandler_Demo(t *testing.T) {
router := testutils.TestSetup()
token := testutils.ConnectDemoUser(router)
books := testGetReadingBooksHandler(t, router, token, 200, "", "")
assert.Equal(t, 2, len(books))
}
func TestGetReadingBooksHandler_Demo2(t *testing.T) {
router := testutils.TestSetup()
token := testutils.ConnectDemo2User(router)
books := testGetReadingBooksHandler(t, router, token, 200, "", "")
assert.Equal(t, 0, len(books))
}
func testGetReadingBooksHandler(t *testing.T, router *gin.Engine, userToken string, expectedCode int, limit string, offset string) []bookUserGet {
u, err := url.Parse("/mybooks/reading")
if err != nil {
t.Error(err)
}
if limit != "" {
q := u.Query()
q.Set("limit", limit)
u.RawQuery = q.Encode()
}
if offset != "" {
q := u.Query()
q.Set("offset", offset)
u.RawQuery = q.Encode()
}
return testGetbooksHandler(t, router, userToken, expectedCode, u.String())
}