Skip to content

Commit

Permalink
test: 테스트 범위 추가
Browse files Browse the repository at this point in the history
- user_util 코드의 모든 범위를 테스트합니다.
  • Loading branch information
YehyeokBang committed Sep 26, 2024
1 parent bb73e1e commit 691eea4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
14 changes: 4 additions & 10 deletions app/report/services/report_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand All @@ -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
}
Expand All @@ -125,15 +121,13 @@ 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 {
return types.ResponseAnalysis{}, err
}
defer response.Body.Close()

// 응답 바디 읽기
body, err := io.ReadAll(response.Body)
if err != nil {
return types.ResponseAnalysis{}, err
Expand Down
18 changes: 18 additions & 0 deletions global/utils/user_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 691eea4

Please sign in to comment.