54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
package apitest
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
"git.artlef.fr/PersonalLibraryManager/internal/testutils"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestPutStartReadUserBooks_NoDate(t *testing.T) {
|
|
payload :=
|
|
`{
|
|
"date": "2025-11-19"
|
|
}`
|
|
bookId := "6"
|
|
testPutStartReadUserBooks(t, payload, bookId, http.StatusBadRequest)
|
|
}
|
|
|
|
func TestPutStartReadUserBooks_WrongDateFormat(t *testing.T) {
|
|
payload :=
|
|
`{
|
|
"startDate": "19/11/2025"
|
|
}`
|
|
bookId := "6"
|
|
testPutStartReadUserBooks(t, payload, bookId, http.StatusInternalServerError)
|
|
}
|
|
|
|
func TestPutStartReadUserBooks_NewReadOk(t *testing.T) {
|
|
payload :=
|
|
`{
|
|
"startDate": "2025-11-19"
|
|
}`
|
|
bookId := "6"
|
|
testPutStartReadUserBooks(t, payload, bookId, http.StatusOK)
|
|
book := testGetBook(t, bookId, http.StatusOK)
|
|
assert.Equal(t, "2025-11-19", book.StartReadDate)
|
|
}
|
|
|
|
func TestPutStartReadUserBooks_Unset(t *testing.T) {
|
|
payload :=
|
|
`{
|
|
"startDate": "null"
|
|
}`
|
|
bookId := "6"
|
|
testPutStartReadUserBooks(t, payload, bookId, http.StatusOK)
|
|
book := testGetBook(t, bookId, http.StatusOK)
|
|
assert.Equal(t, "", book.StartReadDate)
|
|
}
|
|
|
|
func testPutStartReadUserBooks(t *testing.T, payload string, bookId string, expectedCode int) {
|
|
testutils.TestBookPutCallWithDemoPayload(t, payload, bookId, expectedCode, "/ws/book/"+bookId+"/startread")
|
|
}
|