add end read date
This commit is contained in:
@@ -19,6 +19,7 @@ type fetchedBook struct {
|
||||
Read bool `json:"read"`
|
||||
WantRead bool `json:"wantread"`
|
||||
StartReadDate string `json:"startReadDate"`
|
||||
EndReadDate string `json:"endReadDate"`
|
||||
}
|
||||
|
||||
func TestGetBook_Ok(t *testing.T) {
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user