Make "want read" button work

This commit is contained in:
2025-11-06 15:53:24 +01:00
parent 6bfd3ae2da
commit a8f83db83f
14 changed files with 268 additions and 100 deletions

View File

@@ -2,14 +2,17 @@ package testutils
import (
"encoding/json"
"fmt"
"log"
"net/http"
"net/http/httptest"
"strings"
"testing"
"git.artlef.fr/PersonalLibraryManager/internal/config"
"git.artlef.fr/PersonalLibraryManager/internal/setup"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
)
func TestSetup() *gin.Engine {
@@ -51,3 +54,13 @@ func connectUser(router *gin.Engine, loginJson string) string {
}
return parsedResponse.Token
}
func TestBookPutCallWithDemoPayload(t *testing.T, payload string, bookId string, expectedCode int, url string) {
router := TestSetup()
token := ConnectDemoUser(router)
req, _ := http.NewRequest("PUT", url, strings.NewReader(payload))
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", token))
w := httptest.NewRecorder()
router.ServeHTTP(w, req)
assert.Equal(t, expectedCode, w.Code)
}