Added start read date

This commit is contained in:
2025-11-20 22:55:26 +01:00
parent 4cbddfb15f
commit 0bfd0dc231
16 changed files with 263 additions and 33 deletions

View File

@@ -0,0 +1,53 @@
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, "/book/"+bookId+"/startread")
}