58 lines
2.1 KiB
Go
58 lines
2.1 KiB
Go
package apitest
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
"git.artlef.fr/bibliomane/internal/testutils"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestPutBookHandler_TitleChange(t *testing.T) {
|
|
bookId := "17"
|
|
bookJson :=
|
|
`{
|
|
"title": "Le coup de pistolaid"
|
|
}`
|
|
testPutBook(t, bookJson, bookId, 200)
|
|
modifiedBook := testGetBook(t, bookId, http.StatusOK)
|
|
assert.Equal(t, "Le coup de pistolaid", modifiedBook.Title)
|
|
}
|
|
|
|
func TestPutBookHandler_Author(t *testing.T) {
|
|
bookId := "17"
|
|
bookJson :=
|
|
`{
|
|
"author": "Alexander Pouchkine"
|
|
}`
|
|
testPutBook(t, bookJson, bookId, 200)
|
|
modifiedBook := testGetBook(t, bookId, http.StatusOK)
|
|
assert.Equal(t, "Alexander Pouchkine", modifiedBook.Author)
|
|
}
|
|
|
|
func TestPutBookHandler_MultipleFields(t *testing.T) {
|
|
bookId := "17"
|
|
bookJson :=
|
|
`{
|
|
"title": "Le pistolet",
|
|
"author": "Pouchkine",
|
|
"isbn": "978-2-07-036803-7",
|
|
"inventaireid": "isbn:9782070368037",
|
|
"openlibraryid": "OL8838048M",
|
|
"shortdescription": "Roman de Pouchkine",
|
|
"summary": "En garnison dans une petite ville, un officier de l'armée impériale russe rencontre Silvio, ancien soldat et tireur exceptionnel. Celui-ci fait forte impression sur lui, jusqu'au jour où il refuse, à la suite d'un affront, de se battre en duel."
|
|
}`
|
|
testPutBook(t, bookJson, bookId, 200)
|
|
modifiedBook := testGetBook(t, bookId, http.StatusOK)
|
|
assert.Equal(t, "Le pistolet", modifiedBook.Title)
|
|
assert.Equal(t, "Pouchkine", modifiedBook.Author)
|
|
assert.Equal(t, "978-2-07-036803-7", modifiedBook.ISBN)
|
|
assert.Equal(t, "OL8838048M", modifiedBook.OpenLibraryId)
|
|
assert.Equal(t, "Roman de Pouchkine", modifiedBook.ShortDescription)
|
|
assert.Equal(t, "En garnison dans une petite ville, un officier de l'armée impériale russe rencontre Silvio, ancien soldat et tireur exceptionnel. Celui-ci fait forte impression sur lui, jusqu'au jour où il refuse, à la suite d'un affront, de se battre en duel.", modifiedBook.Summary)
|
|
}
|
|
|
|
func testPutBook(t *testing.T, payload string, bookId string, expectedCode int) {
|
|
testutils.TestBookPutCallWithDemoPayload(t, payload, bookId, expectedCode, "/ws/book/edit/"+bookId)
|
|
}
|