Use dto from code for unit tests
This commit is contained in:
@@ -7,33 +7,20 @@ import (
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"git.artlef.fr/PersonalLibraryManager/internal/dto"
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
type bookUserGet struct {
|
||||
Count int64 `json:"count"`
|
||||
Books []bookUserGetBook `json:"books"`
|
||||
}
|
||||
|
||||
type bookUserGetBook struct {
|
||||
BookId uint `json:"id"`
|
||||
Title string `json:"title" binding:"required,max=300"`
|
||||
Author string `json:"author" binding:"max=100"`
|
||||
Rating int `json:"rating" binding:"min=0,max=10"`
|
||||
Read bool `json:"read"`
|
||||
WantRead bool `json:"wantread"`
|
||||
}
|
||||
|
||||
func testGetbooksHandler(t *testing.T, router *gin.Engine, userToken string, expectedCode int, url string) bookUserGet {
|
||||
func testGetbooksHandler(t *testing.T, router *gin.Engine, userToken string, expectedCode int, url string) dto.BookUserGet {
|
||||
req, _ := http.NewRequest("GET", url, nil)
|
||||
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", userToken))
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
router.ServeHTTP(w, req)
|
||||
|
||||
var parsedResponse bookUserGet
|
||||
var parsedResponse dto.BookUserGet
|
||||
err := json.Unmarshal(w.Body.Bytes(), &parsedResponse)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
|
||||
Reference in New Issue
Block a user