Add pagination for "my books" display
This commit is contained in:
54
internal/apitest/get_count_user_book_test.go
Normal file
54
internal/apitest/get_count_user_book_test.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package apitest
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"git.artlef.fr/PersonalLibraryManager/internal/testutils"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
type countResponse struct {
|
||||
Count int
|
||||
}
|
||||
|
||||
func TestGetReadBooksCountHandler_Demo(t *testing.T) {
|
||||
router := testutils.TestSetup()
|
||||
|
||||
token := testutils.ConnectDemoUser(router)
|
||||
|
||||
req, _ := http.NewRequest("GET", "/mybooks/read/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, 23, c.Count)
|
||||
}
|
||||
|
||||
func TestGetWantReadBooksCountHandler_Demo(t *testing.T) {
|
||||
router := testutils.TestSetup()
|
||||
|
||||
token := testutils.ConnectDemoUser(router)
|
||||
|
||||
req, _ := http.NewRequest("GET", "/mybooks/wantread/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)
|
||||
}
|
||||
Reference in New Issue
Block a user