Added start read date
This commit is contained in:
@@ -12,19 +12,20 @@ import (
|
||||
)
|
||||
|
||||
type fetchedBook struct {
|
||||
Title string `json:"title" binding:"required,max=300"`
|
||||
Author string `json:"author" binding:"max=100"`
|
||||
Summary string `json:"summary"`
|
||||
Rating int `json:"rating"`
|
||||
Read bool `json:"read"`
|
||||
WantRead bool `json:"wantread"`
|
||||
Title string `json:"title" binding:"required,max=300"`
|
||||
Author string `json:"author" binding:"max=100"`
|
||||
Summary string `json:"summary"`
|
||||
Rating int `json:"rating"`
|
||||
Read bool `json:"read"`
|
||||
WantRead bool `json:"wantread"`
|
||||
StartReadDate string `json:"startReadDate"`
|
||||
}
|
||||
|
||||
func TestGetBook_Ok(t *testing.T) {
|
||||
book := testGetBook(t, "5", http.StatusOK)
|
||||
book := testGetBook(t, "3", http.StatusOK)
|
||||
assert.Equal(t,
|
||||
fetchedBook{
|
||||
Title: "Rigodon",
|
||||
Title: "D'un château l'autre",
|
||||
Author: "Louis-Ferdinand Céline",
|
||||
Rating: 10,
|
||||
Read: true,
|
||||
|
||||
@@ -31,7 +31,7 @@ func TestGetReadBooksCountHandler_Demo(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
assert.Equal(t, 23, c.Count)
|
||||
assert.Equal(t, 22, c.Count)
|
||||
}
|
||||
|
||||
func TestGetWantReadBooksCountHandler_Demo(t *testing.T) {
|
||||
|
||||
@@ -14,7 +14,7 @@ func TestGetReadBooksHandler_Demo(t *testing.T) {
|
||||
|
||||
token := testutils.ConnectDemoUser(router)
|
||||
books := testGetReadBooksHandler(t, router, token, 200, "", "")
|
||||
assert.Equal(t, 23, len(books))
|
||||
assert.Equal(t, 22, len(books))
|
||||
}
|
||||
|
||||
func TestGetReadBooksHandler_DemoNoLimit(t *testing.T) {
|
||||
@@ -22,7 +22,7 @@ func TestGetReadBooksHandler_DemoNoLimit(t *testing.T) {
|
||||
|
||||
token := testutils.ConnectDemoUser(router)
|
||||
books := testGetReadBooksHandler(t, router, token, 200, "100", "")
|
||||
assert.Equal(t, 23, len(books))
|
||||
assert.Equal(t, 22, len(books))
|
||||
}
|
||||
|
||||
func TestGetReadBooksHandler_DemoLowerLimit(t *testing.T) {
|
||||
@@ -38,7 +38,7 @@ func TestGetReadBooksHandler_DemoOffset(t *testing.T) {
|
||||
|
||||
token := testutils.ConnectDemoUser(router)
|
||||
books := testGetReadBooksHandler(t, router, token, 200, "20", "10")
|
||||
assert.Equal(t, 13, len(books))
|
||||
assert.Equal(t, 12, len(books))
|
||||
}
|
||||
|
||||
func TestGetReadBooksHandler_Demo2(t *testing.T) {
|
||||
@@ -46,7 +46,7 @@ func TestGetReadBooksHandler_Demo2(t *testing.T) {
|
||||
|
||||
token := testutils.ConnectDemo2User(router)
|
||||
books := testGetReadBooksHandler(t, router, token, 200, "", "")
|
||||
assert.Equal(t, 2, len(books))
|
||||
assert.Equal(t, 3, len(books))
|
||||
}
|
||||
|
||||
func TestGetReadBooksHandler_CheckOneBook(t *testing.T) {
|
||||
|
||||
53
internal/apitest/put_userbook_startread_test.go
Normal file
53
internal/apitest/put_userbook_startread_test.go
Normal 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")
|
||||
}
|
||||
Reference in New Issue
Block a user