add end read date

This commit is contained in:
2025-11-21 18:13:09 +01:00
parent 3191a97ce8
commit 8c0a9fe431
13 changed files with 266 additions and 109 deletions

View File

@@ -20,6 +20,44 @@ func TestPutReadUserBooks_NewReadOk(t *testing.T) {
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, "/book/"+bookId+"/read")
}