55 lines
1.1 KiB
Go
55 lines
1.1 KiB
Go
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, 22, 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)
|
|
}
|