Added inventaire import from ISBN

This commit is contained in:
2026-02-02 20:31:57 +01:00
parent 21162cc63e
commit 82db737d30
7 changed files with 167 additions and 48 deletions

View File

@@ -9,25 +9,11 @@ import (
"net/url"
"testing"
"git.artlef.fr/PersonalLibraryManager/internal/dto"
"git.artlef.fr/PersonalLibraryManager/internal/testutils"
"github.com/stretchr/testify/assert"
)
type bookSearchGet struct {
Count int64 `json:"count"`
Books []bookSearchGetBook `json:"books"`
}
type bookSearchGetBook struct {
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) {
result := testSearchBook(t, "san", "", "")
@@ -39,10 +25,10 @@ func TestSearchBook_OneBookNotUserBook(t *testing.T) {
result := testSearchBook(t, "iliade", "", "")
assert.Equal(t, int64(1), result.Count)
assert.Equal(t,
[]bookSearchGetBook{{
[]dto.BookSearchGetBook{{
Title: "Iliade",
Author: "Homère",
Id: 29,
ID: 29,
Rating: 0,
Read: false,
WantRead: false,
@@ -55,10 +41,10 @@ func TestSearchBook_OneBookRead(t *testing.T) {
result := testSearchBook(t, "dieux", "", "")
assert.Equal(t, int64(1), result.Count)
assert.Equal(t,
[]bookSearchGetBook{{
[]dto.BookSearchGetBook{{
Title: "Les dieux ont soif",
Author: "Anatole France",
Id: 4,
ID: 4,
Rating: 7,
Read: true,
WantRead: false,
@@ -71,10 +57,10 @@ func TestSearchBook_ISBN(t *testing.T) {
result := testSearchBook(t, "9782070337903", "", "")
assert.Equal(t, int64(1), result.Count)
assert.Equal(t,
[]bookSearchGetBook{{
[]dto.BookSearchGetBook{{
Title: "Le complot contre l'Amérique",
Author: "Philip Roth",
Id: 22,
ID: 22,
Rating: 6,
Read: true,
WantRead: false,
@@ -83,6 +69,25 @@ func TestSearchBook_ISBN(t *testing.T) {
result.Books)
}
func TestSearchBook_ISBNInventaire(t *testing.T) {
result := testSearchBook(t, "9782253158400", "", "")
assert.Equal(t, int64(1), result.Count)
assert.Equal(t,
[]dto.BookSearchGetBook{{
ID: 0,
Title: "Les premières enquêtes de Maigret",
Author: "Georges Simenon",
Description: "roman de Georges Simenon",
InventaireID: "isbn:9782253158400",
IsInventaireEdition: true,
Rating: 0,
Read: false,
WantRead: false,
CoverPath: "https://inventaire.io/img/entities/17663a503d984204078c910d5bae68d52942b47d",
}},
result.Books)
}
func TestSearchBook_Limit(t *testing.T) {
result := testSearchBook(t, "a", "10", "")
assert.Equal(t, 10, len(result.Books))
@@ -94,7 +99,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) bookSearchGet {
func testSearchBook(t *testing.T, searchterm string, limit string, offset string) dto.BookSearchGet {
router := testutils.TestSetup()
u, err := url.Parse("/search/" + searchterm)
@@ -112,13 +117,17 @@ func testSearchBook(t *testing.T, searchterm string, limit string, offset string
u.RawQuery = q.Encode()
}
q := u.Query()
q.Set("lang", "fr")
u.RawQuery = q.Encode()
token := testutils.ConnectDemoUser(router)
req, _ := http.NewRequest("GET", u.String(), nil)
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", token))
w := httptest.NewRecorder()
router.ServeHTTP(w, req)
var result bookSearchGet
var result dto.BookSearchGet
s := w.Body.String()
err = json.Unmarshal([]byte(s), &result)
if err != nil {