Manage display of book covers

This commit is contained in:
2025-10-28 18:35:36 +01:00
parent 8b8eee8210
commit b4df375e4c
20 changed files with 257 additions and 353 deletions

View File

@@ -14,9 +14,11 @@ import (
)
type bookUserGet 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"`
}
func TestGetBooksHandler_Demo(t *testing.T) {
@@ -35,6 +37,27 @@ func TestGetBooksHandler_Demo2(t *testing.T) {
assert.Equal(t, 2, len(books))
}
func TestGetBooksHandler_CheckOneBook(t *testing.T) {
router := testutils.TestSetup()
token := testutils.ConnectDemo2User(router)
books := testGetbooksHandler(t, router, token, 200)
var book bookUserGet
for _, b := range books {
if b.Title == "De sang-froid" {
book = b
}
}
assert.Equal(t,
bookUserGet{
BookId: 18,
Title: "De sang-froid",
Author: "Truman Capote",
Rating: 6,
Read: true,
}, book)
}
func testGetbooksHandler(t *testing.T, router *gin.Engine, userToken string, expectedCode int) []bookUserGet {
req, _ := http.NewRequest("GET", "/mybooks", nil)
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", userToken))