add "reading" filter for books currently being read
This commit is contained in:
44
internal/apitest/get_reading_user_book_test.go
Normal file
44
internal/apitest/get_reading_user_book_test.go
Normal 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())
|
||||
}
|
||||
Reference in New Issue
Block a user