From 10ecb6fd0d8533e73dd8a0792ed2ec52878c6966 Mon Sep 17 00:00:00 2001 From: keedosn Date: Mon, 14 Mar 2022 16:25:17 +0100 Subject: [PATCH] [fix] Fixed tests scenarios --- test/handler/create_article_test.go | 4 ---- test/handler/create_category_test.go | 8 +++----- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/test/handler/create_article_test.go b/test/handler/create_article_test.go index 4394b4a..815a337 100644 --- a/test/handler/create_article_test.go +++ b/test/handler/create_article_test.go @@ -18,9 +18,5 @@ func TestCreateArticleHandler(t *testing.T) { if responseRecorder.Code != http.StatusCreated { t.Errorf("Want status '%d', got '%d'", http.StatusCreated, responseRecorder.Code) } - - // if strings.TrimSpace(responseRecorder.Body.String()) != tc.want { - // t.Errorf("Want '%s', got '%s'", tc.want, responseRecorder.Body) - // } }) } diff --git a/test/handler/create_category_test.go b/test/handler/create_category_test.go index 2270150..7c1be57 100644 --- a/test/handler/create_category_test.go +++ b/test/handler/create_category_test.go @@ -3,6 +3,7 @@ package main import ( "net/http" "net/http/httptest" + "strings" "testing" "git.pbiernat.dev/golang/rest-api-prototype/internal/app/handler" @@ -10,7 +11,8 @@ import ( func TestCreateCategoryHandler(t *testing.T) { t.Run("test create category handler", func(t *testing.T) { - request := httptest.NewRequest(http.MethodPost, "/api/category", nil) + body := "{\"name\":\"Test Category\"}" + request := httptest.NewRequest(http.MethodPost, "/api/category", strings.NewReader(body)) responseRecorder := httptest.NewRecorder() handler.CreateCategoryHandler.ServeHTTP(responseRecorder, request) @@ -18,9 +20,5 @@ func TestCreateCategoryHandler(t *testing.T) { if responseRecorder.Code != http.StatusCreated { t.Errorf("Want status '%d', got '%d'", http.StatusCreated, responseRecorder.Code) } - - // if strings.TrimSpace(responseRecorder.Body.String()) != tc.want { - // t.Errorf("Want '%s', got '%s'", tc.want, responseRecorder.Body) - // } }) }