64 lines
1.5 KiB
Go
64 lines
1.5 KiB
Go
package apitest
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
"git.artlef.fr/bibliomane/internal/testutils"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestPutReadUserBooks_NewReadOk(t *testing.T) {
|
|
payload :=
|
|
`{
|
|
"read": true
|
|
}`
|
|
bookId := "21"
|
|
testPutReadUserBooks(t, payload, bookId, http.StatusOK)
|
|
book := testGetBook(t, bookId, http.StatusOK)
|
|
assert.Equal(t, true, book.Read)
|
|
assert.Equal(t, false, book.WantRead)
|
|
}
|
|
|
|
func TestPutReadUserBooks_NewReadDateOk(t *testing.T) {
|
|
payload :=
|
|
`{
|
|
"read": true,
|
|
"endDate": "2025-10-20"
|
|
}`
|
|
bookId := "9"
|
|
testPutReadUserBooks(t, payload, bookId, http.StatusOK)
|
|
book := testGetBook(t, bookId, http.StatusOK)
|
|
assert.Equal(t, true, book.Read)
|
|
assert.Equal(t, "2025-10-20", book.EndReadDate)
|
|
}
|
|
|
|
func TestPutReadUserBooks_UnsetEndDate(t *testing.T) {
|
|
payload :=
|
|
`{
|
|
"read": true,
|
|
"endDate": "null"
|
|
}`
|
|
bookId := "9"
|
|
testPutReadUserBooks(t, payload, bookId, http.StatusOK)
|
|
book := testGetBook(t, bookId, http.StatusOK)
|
|
assert.Equal(t, true, book.Read)
|
|
assert.Equal(t, "", book.EndReadDate)
|
|
}
|
|
|
|
func TestPutReadUserBooks_UnsetReadOk(t *testing.T) {
|
|
payload :=
|
|
`{
|
|
"read": false
|
|
}`
|
|
bookId := "9"
|
|
testPutReadUserBooks(t, payload, bookId, http.StatusOK)
|
|
book := testGetBook(t, bookId, http.StatusOK)
|
|
assert.Equal(t, false, book.Read)
|
|
assert.Equal(t, "", book.EndReadDate)
|
|
}
|
|
|
|
func testPutReadUserBooks(t *testing.T, payload string, bookId string, expectedCode int) {
|
|
testutils.TestBookPutCallWithDemoPayload(t, payload, bookId, expectedCode, "/ws/book/"+bookId+"/read")
|
|
}
|