Use the same widget for books everywhere

This commit is contained in:
2026-03-27 22:08:24 +01:00
parent 726c640657
commit e05c9f2b45
17 changed files with 70 additions and 146 deletions

View File

@@ -19,7 +19,7 @@ func TestFetchAllBooks(t *testing.T) {
assert.Equal(t, 15, len(result.Books))
}
func testFetchBooks(t *testing.T, limit string, offset string) dto.BookSearchGet {
func testFetchBooks(t *testing.T, limit string, offset string) dto.BookItemsGet {
router := testutils.TestSetup()
u, err := url.Parse("/ws/books")
@@ -47,7 +47,7 @@ func testFetchBooks(t *testing.T, limit string, offset string) dto.BookSearchGet
w := httptest.NewRecorder()
router.ServeHTTP(w, req)
var result dto.BookSearchGet
var result dto.BookItemsGet
s := w.Body.String()
err = json.Unmarshal([]byte(s), &result)
if err != nil {

View File

@@ -15,7 +15,7 @@ import (
func TestGetBook_Ok(t *testing.T) {
book := testGetBook(t, "3", http.StatusOK)
assert.Equal(t,
dto.BookGet{
dto.FullBookGet{
Title: "D'un château l'autre",
Author: "Louis-Ferdinand Céline",
AuthorID: 2,
@@ -29,7 +29,7 @@ func TestGetBook_Ok(t *testing.T) {
func TestGetBook_NoUserBook(t *testing.T) {
book := testGetBook(t, "18", http.StatusOK)
assert.Equal(t,
dto.BookGet{
dto.FullBookGet{
Title: "De sang-froid",
Author: "Truman Capote",
AuthorID: 14,
@@ -41,7 +41,7 @@ func TestGetBook_NoUserBook(t *testing.T) {
func TestGetBook_Description(t *testing.T) {
book := testGetBook(t, "22", http.StatusOK)
assert.Equal(t,
dto.BookGet{
dto.FullBookGet{
Title: "Le complot contre l'Amérique",
Author: "Philip Roth",
AuthorID: 17,
@@ -61,7 +61,7 @@ func TestGetBook_IdNotInt(t *testing.T) {
testGetBook(t, "wrong", http.StatusBadRequest)
}
func testGetBook(t *testing.T, id string, status int) dto.BookGet {
func testGetBook(t *testing.T, id string, status int) dto.FullBookGet {
router := testutils.TestSetup()
token := testutils.ConnectDemoUser(router)
@@ -70,7 +70,7 @@ func testGetBook(t *testing.T, id string, status int) dto.BookGet {
w := httptest.NewRecorder()
router.ServeHTTP(w, req)
var book dto.BookGet
var book dto.FullBookGet
err := json.Unmarshal(w.Body.Bytes(), &book)
if err != nil {
t.Error(err)

View File

@@ -60,14 +60,14 @@ func TestGetReadBooksHandler_CheckOneBook(t *testing.T) {
token := testutils.ConnectDemo2User(router)
result := testGetReadBooksHandler(t, router, token, 200, "100", "")
var book dto.BookUserGetBook
var book dto.BookItemGet
for _, b := range result.Books {
if b.Title == "De sang-froid" {
book = b
}
}
assert.Equal(t,
dto.BookUserGetBook{
dto.BookItemGet{
ID: 18,
Title: "De sang-froid",
Author: "Truman Capote",
@@ -77,7 +77,7 @@ func TestGetReadBooksHandler_CheckOneBook(t *testing.T) {
}, book)
}
func testGetReadBooksHandler(t *testing.T, router *gin.Engine, userToken string, expectedCode int, limit string, offset string) dto.BookUserGet {
func testGetReadBooksHandler(t *testing.T, router *gin.Engine, userToken string, expectedCode int, limit string, offset string) dto.BookItemsGet {
u, err := url.Parse("/ws/mybooks/read")
if err != nil {
t.Error(err)

View File

@@ -28,7 +28,7 @@ func TestGetReadingBooksHandler_Demo2(t *testing.T) {
assert.Equal(t, int64(0), result.Count)
}
func testGetReadingBooksHandler(t *testing.T, router *gin.Engine, userToken string, expectedCode int, limit string, offset string) dto.BookUserGet {
func testGetReadingBooksHandler(t *testing.T, router *gin.Engine, userToken string, expectedCode int, limit string, offset string) dto.BookItemsGet {
u, err := url.Parse("/ws/mybooks/reading")
if err != nil {
t.Error(err)

View File

@@ -13,14 +13,14 @@ import (
"github.com/stretchr/testify/assert"
)
func testGetbooksHandler(t *testing.T, router *gin.Engine, userToken string, expectedCode int, url string) dto.BookUserGet {
func testGetbooksHandler(t *testing.T, router *gin.Engine, userToken string, expectedCode int, url string) dto.BookItemsGet {
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", userToken))
w := httptest.NewRecorder()
router.ServeHTTP(w, req)
var parsedResponse dto.BookUserGet
var parsedResponse dto.BookItemsGet
err := json.Unmarshal(w.Body.Bytes(), &parsedResponse)
if err != nil {
t.Error(err)

View File

@@ -27,6 +27,6 @@ func TestGetWantReadBooksHandler_Demo2(t *testing.T) {
assert.Equal(t, int64(0), result.Count)
}
func testGetWantReadBooksHandler(t *testing.T, router *gin.Engine, userToken string, expectedCode int) dto.BookUserGet {
func testGetWantReadBooksHandler(t *testing.T, router *gin.Engine, userToken string, expectedCode int) dto.BookItemsGet {
return testGetbooksHandler(t, router, userToken, expectedCode, "/ws/mybooks/wantread")
}

View File

@@ -25,7 +25,7 @@ func TestSearchBook_OneBookNotUserBook(t *testing.T) {
result := testSearchBook(t, "iliade", "", "")
assert.Equal(t, int64(1), result.Count)
assert.Equal(t,
[]dto.BookSearchGetBook{{
[]dto.BookItemGet{{
Title: "Iliade",
Author: "Homère",
ID: 29,
@@ -41,7 +41,7 @@ func TestSearchBook_OneBookRead(t *testing.T) {
result := testSearchBook(t, "dieux", "", "")
assert.Equal(t, int64(1), result.Count)
assert.Equal(t,
[]dto.BookSearchGetBook{{
[]dto.BookItemGet{{
Title: "Les dieux ont soif",
Author: "Anatole France",
ID: 4,
@@ -58,7 +58,7 @@ func TestSearchBook_OneBookStartRead(t *testing.T) {
result := testSearchBook(t, "Recherches", "", "")
assert.Equal(t, int64(1), result.Count)
assert.Equal(t,
[]dto.BookSearchGetBook{{
[]dto.BookItemGet{{
Title: "Recherches philosophiques",
Author: "Ludwig Wittgenstein",
ID: 30,
@@ -75,7 +75,7 @@ func TestSearchBook_ISBN(t *testing.T) {
result := testSearchBook(t, "9782070337903", "", "")
assert.Equal(t, int64(1), result.Count)
assert.Equal(t,
[]dto.BookSearchGetBook{{
[]dto.BookItemGet{{
Title: "Le complot contre l'Amérique",
Author: "Philip Roth",
ID: 22,
@@ -91,7 +91,7 @@ func TestSearchBook_ISBNInventaire(t *testing.T) {
result := testSearchBook(t, "9782253158400", "", "")
assert.Equal(t, int64(1), result.Count)
assert.Equal(t,
[]dto.BookSearchGetBook{{
[]dto.BookItemGet{{
ID: 0,
Title: "Les premières enquêtes de Maigret",
Author: "Georges Simenon",
@@ -117,7 +117,7 @@ func TestSearchBook_Offset(t *testing.T) {
assert.Equal(t, 3, len(result.Books))
}
func testSearchBook(t *testing.T, searchterm string, limit string, offset string) dto.BookSearchGet {
func testSearchBook(t *testing.T, searchterm string, limit string, offset string) dto.BookItemsGet {
router := testutils.TestSetup()
u, err := url.Parse("/ws/search/" + searchterm)
@@ -145,7 +145,7 @@ func testSearchBook(t *testing.T, searchterm string, limit string, offset string
w := httptest.NewRecorder()
router.ServeHTTP(w, req)
var result dto.BookSearchGet
var result dto.BookItemsGet
s := w.Body.String()
err = json.Unmarshal([]byte(s), &result)
if err != nil {