added validation when adding a book
This commit is contained in:
20
api_test.go
20
api_test.go
@@ -63,6 +63,26 @@ func TestPostBookHandler_WrongRating(t *testing.T) {
|
||||
testPostBookHandler(t, bookJson, 400)
|
||||
}
|
||||
|
||||
func TestPostBookHandler_TitleTooLong(t *testing.T) {
|
||||
bookJson :=
|
||||
`{
|
||||
"title": "Noisy outlaws, unfriendly blobs, and some other things that aren't as scary, maybe, depending on how you feel about lost lands, stray cellphones, creatures from the sky, parents who disappear in Peru, a man named Lars Farf, and one other story we couldn't quite finish, so maybe you could help us out.",
|
||||
"author": "Eli Horowitz",
|
||||
"rating": 2
|
||||
}`
|
||||
testPostBookHandler(t, bookJson, 400)
|
||||
}
|
||||
|
||||
func TestPostBookHandler_AuthorTooLong(t *testing.T) {
|
||||
bookJson :=
|
||||
`{
|
||||
"title": "something",
|
||||
"author": "Wolfeschlegelsteinhausenbergerdorffwelchevoralternwarengewissenhaftschaferswessenschafewarenwohlgepflegeundsorgfaltigkeitbeschutzenvonangreifendurchihrraubgierigfeindewelchevoralternzwolftausendjahresvorandieerscheinenvanderersteerdemenschderraumschiffgebrauchlichtalsseinursprungvonkraftgestartseinlangefahrthinzwischensternartigraumaufdersuchenachdiesternwelchegehabtbewohnbarplanetenkreisedrehensichundwohinderneurassevonverstandigmenschlichkeitkonntefortpflanzenundsicherfreuenanlebenslanglichfreudeundruhemitnichteinfurchtvorangreifenvonandererintelligentgeschopfsvonhinzwischensternartigraum",
|
||||
"rating": 2
|
||||
}`
|
||||
testPostBookHandler(t, bookJson, 400)
|
||||
}
|
||||
|
||||
func testPostBookHandler(t *testing.T, bookJson string, expectedCode int) {
|
||||
router := testSetup()
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
Reference in New Issue
Block a user