add userbook from searched book
This commit is contained in:
@@ -15,13 +15,28 @@ import (
|
||||
type bookSearchGet struct {
|
||||
Title string `json:"title" binding:"required,max=300"`
|
||||
Author string `json:"author" binding:"max=100"`
|
||||
Id uint `json:"id"`
|
||||
}
|
||||
|
||||
func TestSearchBook(t *testing.T) {
|
||||
func TestSearchBook_MultipleBooks(t *testing.T) {
|
||||
books := testSearchBook(t, "san")
|
||||
|
||||
assert.Equal(t, 2, len(books))
|
||||
}
|
||||
|
||||
func TestSearchBook_AllFields(t *testing.T) {
|
||||
books := testSearchBook(t, "de san")
|
||||
assert.Equal(t, 1, len(books))
|
||||
assert.Equal(t,
|
||||
[]bookSearchGet{{Title: "De sang-froid", Author: "Truman Capote", Id: 18}},
|
||||
books)
|
||||
}
|
||||
|
||||
func testSearchBook(t *testing.T, searchterm string) []bookSearchGet {
|
||||
router := testutils.TestSetup()
|
||||
|
||||
token := testutils.ConnectDemoUser(router)
|
||||
req, _ := http.NewRequest("GET", "/search/san", nil)
|
||||
req, _ := http.NewRequest("GET", "/search/"+searchterm, nil)
|
||||
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", token))
|
||||
w := httptest.NewRecorder()
|
||||
router.ServeHTTP(w, req)
|
||||
@@ -32,6 +47,5 @@ func TestSearchBook(t *testing.T) {
|
||||
log.Fatal(err)
|
||||
}
|
||||
assert.Equal(t, 200, w.Code)
|
||||
|
||||
assert.Equal(t, 2, len(books))
|
||||
return books
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user