diff --git a/internal/apitest/get_book_test.go b/internal/apitest/get_book_test.go index 2da855a..e966ca7 100644 --- a/internal/apitest/get_book_test.go +++ b/internal/apitest/get_book_test.go @@ -7,29 +7,15 @@ import ( "net/http/httptest" "testing" + "git.artlef.fr/PersonalLibraryManager/internal/dto" "git.artlef.fr/PersonalLibraryManager/internal/testutils" "github.com/stretchr/testify/assert" ) -type fetchedBook struct { - Title string `json:"title" binding:"required,max=300"` - Author string `json:"author" binding:"max=100"` - ISBN string `json:"isbn"` - InventaireID string `json:"inventaireid"` - OpenLibraryId string `json:"openlibraryid"` - Summary string `json:"summary"` - Rating int `json:"rating"` - Read bool `json:"read"` - WantRead bool `json:"wantread"` - StartReadDate string `json:"startReadDate"` - EndReadDate string `json:"endReadDate"` - CoverPath string `json:"coverPath"` -} - func TestGetBook_Ok(t *testing.T) { book := testGetBook(t, "3", http.StatusOK) assert.Equal(t, - fetchedBook{ + dto.BookGet{ Title: "D'un château l'autre", Author: "Louis-Ferdinand Céline", Rating: 10, @@ -41,7 +27,7 @@ func TestGetBook_Ok(t *testing.T) { func TestGetBook_NoUserBook(t *testing.T) { book := testGetBook(t, "18", http.StatusOK) assert.Equal(t, - fetchedBook{ + dto.BookGet{ Title: "De sang-froid", Author: "Truman Capote", Read: false, @@ -52,7 +38,7 @@ func TestGetBook_NoUserBook(t *testing.T) { func TestGetBook_Description(t *testing.T) { book := testGetBook(t, "22", http.StatusOK) assert.Equal(t, - fetchedBook{ + dto.BookGet{ Title: "Le complot contre l'Amérique", Author: "Philip Roth", ISBN: "9782070337903", @@ -71,7 +57,7 @@ func TestGetBook_IdNotInt(t *testing.T) { testGetBook(t, "wrong", http.StatusBadRequest) } -func testGetBook(t *testing.T, id string, status int) fetchedBook { +func testGetBook(t *testing.T, id string, status int) dto.BookGet { router := testutils.TestSetup() token := testutils.ConnectDemoUser(router) @@ -80,7 +66,7 @@ func testGetBook(t *testing.T, id string, status int) fetchedBook { w := httptest.NewRecorder() router.ServeHTTP(w, req) - var book fetchedBook + var book dto.BookGet err := json.Unmarshal(w.Body.Bytes(), &book) if err != nil { t.Error(err) diff --git a/internal/apitest/post_importbook_test.go b/internal/apitest/post_importbook_test.go index 6307b31..b88c376 100644 --- a/internal/apitest/post_importbook_test.go +++ b/internal/apitest/post_importbook_test.go @@ -22,7 +22,7 @@ func TestPostImportBookHandler_Ok(t *testing.T) { book := testGetBook(t, strconv.FormatUint(uint64(id), 10), 200) assert.Equal(t, "les Hauts de Hurle-Vent", book.Title) assert.Equal(t, "Emily Brontë", book.Author) - assert.Equal(t, "isbn:9782253004752", book.InventaireID) + assert.Equal(t, "isbn:9782253004752", book.InventaireId) assert.Equal(t, "/bookcover/44abbcbdc1092212c2bae66f5165019dac1e2a7b.webp", book.CoverPath) } @@ -31,7 +31,7 @@ func TestPostImportBookHandler_OkAuthorKey(t *testing.T) { book := testGetBook(t, strconv.FormatUint(uint64(id), 10), 200) assert.Equal(t, "Dr Bloodmoney", book.Title) assert.Equal(t, "Philip K. Dick", book.Author) - assert.Equal(t, "isbn:9782290033630", book.InventaireID) + assert.Equal(t, "isbn:9782290033630", book.InventaireId) assert.Equal(t, "/bookcover/1d1493159d031224a42b37c4417fcbb8c76b00bd.webp", book.CoverPath) }