From 691eea4110c208efc84b76efda5528f5b66c3717 Mon Sep 17 00:00:00 2001 From: Yehyeok Bang Date: Thu, 26 Sep 2024 19:39:43 +0900 Subject: [PATCH] =?UTF-8?q?test:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EB=B2=94?= =?UTF-8?q?=EC=9C=84=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - user_util 코드의 모든 범위를 테스트합니다. --- app/report/services/report_service.go | 14 ++++---------- global/utils/user_util_test.go | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/app/report/services/report_service.go b/app/report/services/report_service.go index cc1386e..aafcbce 100644 --- a/app/report/services/report_service.go +++ b/app/report/services/report_service.go @@ -55,10 +55,6 @@ func (service *ReportService) Analysis(c *gin.Context, input types.RequestAnalys u, _ := url.Parse(REQUEST_URL) - q := u.Query() - q.Add("video_url", input.VideoURL) - u.RawQuery = q.Encode() - message := "Video submitted successfully" errCh := make(chan error, 1) @@ -81,8 +77,6 @@ func Predict(service ReportService, url string, user usermodel.User, input types return err } - fmt.Println("응답: ", response) - result, scores, nomalRatio, statusFrequencies, distances, landmarksInfo := ParseAnalysis(&response) score := CalculateScores(result, scores) @@ -98,12 +92,14 @@ func Predict(service ReportService, url string, user usermodel.User, input types Distances: distances, NeckAngles: landmarksInfo, } - savedReport, _ := service.ReportRepository.Save(&report) title, body, _ := GenerateMessage(savedReport.CreatedAt.String()) + return _SendPushNotification(user, title, body) +} - err = fcm.SendPushNotification(user.FcmToken, title, body) +func _SendPushNotification(user usermodel.User, title string, body string) error { + err := fcm.SendPushNotification(user.FcmToken, title, body) if err != nil { return err } @@ -125,7 +121,6 @@ func HandleRequest(url string, videoURL string) (types.ResponseAnalysis, error) } req.Header.Set("Content-Type", "application/json") - // HTTP 클라이언트 요청 보내기 client := &http.Client{} response, err := client.Do(req) if err != nil { @@ -133,7 +128,6 @@ func HandleRequest(url string, videoURL string) (types.ResponseAnalysis, error) } defer response.Body.Close() - // 응답 바디 읽기 body, err := io.ReadAll(response.Body) if err != nil { return types.ResponseAnalysis{}, err diff --git a/global/utils/user_util_test.go b/global/utils/user_util_test.go index 2c00d17..0d6f238 100644 --- a/global/utils/user_util_test.go +++ b/global/utils/user_util_test.go @@ -85,6 +85,24 @@ func TestUserUtil_FindCurrentUser(t *testing.T) { assert.Equal(t, expectedUser, user) } +func TestUserUtil_FindCurrentUser_NoUserID(t *testing.T) { + // Create a new instance of the mock repository + mockRepo := new(MockUserRepository) + + // Create an instance of UserUtil with the mock repository + userUtil := utils.NewUserUtil(mockRepo) + + // Create a sample gin.Context without the user ID + ctx := &gin.Context{} + + // Call the method under test + user, err := userUtil.FindCurrentUser(ctx) + + // Validate the result + assert.NotNil(t, err) + assert.Nil(t, user) +} + func TestUserUtil_FindCurrentUser_UserNotFound(t *testing.T) { // Create a new instance of the mock repository mockRepo := new(MockUserRepository)