Rename test file
This commit is contained in:
74
internal/apitest/put_userbook_rate_test.go
Normal file
74
internal/apitest/put_userbook_rate_test.go
Normal file
@@ -0,0 +1,74 @@
|
||||
package apitest
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"git.artlef.fr/PersonalLibraryManager/internal/testutils"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestPutRatingUserBooksHandler_UpdateRating(t *testing.T) {
|
||||
payload :=
|
||||
`{
|
||||
"rating": 5
|
||||
}`
|
||||
bookId := "17"
|
||||
testPutRateUserBooks(t, payload, bookId, http.StatusOK)
|
||||
book := testGetBook(t, bookId, http.StatusOK)
|
||||
assert.Equal(t, 5, book.Rating)
|
||||
assert.Equal(t, true, book.Read)
|
||||
}
|
||||
|
||||
func TestPutRatingUserBooksHandler_RateNewBookMakeItRead(t *testing.T) {
|
||||
payload :=
|
||||
`{
|
||||
"rating": 7
|
||||
}`
|
||||
bookId := "18"
|
||||
testPutRateUserBooks(t, payload, bookId, http.StatusOK)
|
||||
book := testGetBook(t, bookId, http.StatusOK)
|
||||
assert.Equal(t, 7, book.Rating)
|
||||
assert.Equal(t, true, book.Read)
|
||||
assert.Equal(t, false, book.WantRead)
|
||||
}
|
||||
|
||||
func TestPutRatingUserBooksHandler_RatingTypeWrong(t *testing.T) {
|
||||
payload :=
|
||||
`{
|
||||
"rating": "bad"
|
||||
}`
|
||||
bookId := "18"
|
||||
testPutRateUserBooks(t, payload, bookId, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
func TestPutRatingUserBooksHandler_RatingMin(t *testing.T) {
|
||||
payload :=
|
||||
`{
|
||||
"rating": -3
|
||||
}`
|
||||
bookId := "18"
|
||||
testPutRateUserBooks(t, payload, bookId, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
func TestPutRatingUserBooksHandler_RatingMax(t *testing.T) {
|
||||
payload :=
|
||||
`{
|
||||
"rating": 15
|
||||
}`
|
||||
bookId := "18"
|
||||
testPutRateUserBooks(t, payload, bookId, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
func TestPutRatingUserBooksHandler_BadBookId(t *testing.T) {
|
||||
payload :=
|
||||
`{
|
||||
"rating": 15
|
||||
}`
|
||||
bookId := "18574"
|
||||
testPutRateUserBooks(t, payload, bookId, http.StatusNotFound)
|
||||
}
|
||||
|
||||
func testPutRateUserBooks(t *testing.T, payload string, bookId string, expectedCode int) {
|
||||
testutils.TestBookPutCallWithDemoPayload(t, payload, bookId, expectedCode, "/book/"+bookId+"/rate")
|
||||
}
|
||||
Reference in New Issue
Block a user