Use dto from code for unit tests

This commit is contained in:
2026-02-03 18:24:42 +01:00
parent fe75973acd
commit 02e4c579c6
4 changed files with 17 additions and 26 deletions

View File

@@ -7,33 +7,20 @@ import (
"net/http/httptest"
"testing"
"git.artlef.fr/PersonalLibraryManager/internal/dto"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
)
type bookUserGet struct {
Count int64 `json:"count"`
Books []bookUserGetBook `json:"books"`
}
type bookUserGetBook struct {
BookId uint `json:"id"`
Title string `json:"title" binding:"required,max=300"`
Author string `json:"author" binding:"max=100"`
Rating int `json:"rating" binding:"min=0,max=10"`
Read bool `json:"read"`
WantRead bool `json:"wantread"`
}
func testGetbooksHandler(t *testing.T, router *gin.Engine, userToken string, expectedCode int, url string) bookUserGet {
func testGetbooksHandler(t *testing.T, router *gin.Engine, userToken string, expectedCode int, url string) dto.BookUserGet {
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", userToken))
w := httptest.NewRecorder()
router.ServeHTTP(w, req)
var parsedResponse bookUserGet
var parsedResponse dto.BookUserGet
err := json.Unmarshal(w.Body.Bytes(), &parsedResponse)
if err != nil {
t.Error(err)