Display read/wantread in search view

This commit is contained in:
2025-11-18 17:34:34 +01:00
parent 81d0be3a77
commit 59f6635f1b
5 changed files with 71 additions and 20 deletions

View File

@@ -14,9 +14,13 @@ import (
)
type bookSearchGet struct {
Title string `json:"title" binding:"required,max=300"`
Author string `json:"author" binding:"max=100"`
Id uint `json:"id"`
Id uint `json:"id"`
Title string `json:"title" binding:"required,max=300"`
Author string `json:"author" binding:"max=100"`
Rating int `json:"rating"`
Read bool `json:"read"`
WantRead bool `json:"wantread"`
CoverPath string `json:"coverPath"`
}
func TestSearchBook_MultipleBooks(t *testing.T) {
@@ -25,11 +29,35 @@ func TestSearchBook_MultipleBooks(t *testing.T) {
assert.Equal(t, 2, len(books))
}
func TestSearchBook_AllFields(t *testing.T) {
books := testSearchBook(t, "de san", "", "")
func TestSearchBook_OneBookNotUserBook(t *testing.T) {
books := testSearchBook(t, "iliade", "", "")
assert.Equal(t, 1, len(books))
assert.Equal(t,
[]bookSearchGet{{Title: "De sang-froid", Author: "Truman Capote", Id: 18}},
[]bookSearchGet{{
Title: "Iliade",
Author: "Homère",
Id: 29,
Rating: 0,
Read: false,
WantRead: false,
CoverPath: "/bookcover/iliade.jpeg",
}},
books)
}
func TestSearchBook_OneBookRead(t *testing.T) {
books := testSearchBook(t, "dieux", "", "")
assert.Equal(t, 1, len(books))
assert.Equal(t,
[]bookSearchGet{{
Title: "Les dieux ont soif",
Author: "Anatole France",
Id: 4,
Rating: 7,
Read: true,
WantRead: false,
CoverPath: "/bookcover/lesdieuxontsoif.jpg",
}},
books)
}
@@ -68,7 +96,8 @@ func testSearchBook(t *testing.T, searchterm string, limit string, offset string
router.ServeHTTP(w, req)
var books []bookSearchGet
err = json.Unmarshal(w.Body.Bytes(), &books)
s := w.Body.String()
err = json.Unmarshal([]byte(s), &books)
if err != nil {
t.Error(err)
}