Skip to content

Commit 691eea4

Browse files
committedSep 26, 2024·
test: 테스트 범위 추가
- user_util 코드의 모든 범위를 테스트합니다.
1 parent bb73e1e commit 691eea4

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed
 

‎app/report/services/report_service.go

+4-10
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ func (service *ReportService) Analysis(c *gin.Context, input types.RequestAnalys
5555

5656
u, _ := url.Parse(REQUEST_URL)
5757

58-
q := u.Query()
59-
q.Add("video_url", input.VideoURL)
60-
u.RawQuery = q.Encode()
61-
6258
message := "Video submitted successfully"
6359

6460
errCh := make(chan error, 1)
@@ -81,8 +77,6 @@ func Predict(service ReportService, url string, user usermodel.User, input types
8177
return err
8278
}
8379

84-
fmt.Println("응답: ", response)
85-
8680
result, scores, nomalRatio, statusFrequencies, distances, landmarksInfo := ParseAnalysis(&response)
8781
score := CalculateScores(result, scores)
8882

@@ -98,12 +92,14 @@ func Predict(service ReportService, url string, user usermodel.User, input types
9892
Distances: distances,
9993
NeckAngles: landmarksInfo,
10094
}
101-
10295
savedReport, _ := service.ReportRepository.Save(&report)
10396

10497
title, body, _ := GenerateMessage(savedReport.CreatedAt.String())
98+
return _SendPushNotification(user, title, body)
99+
}
105100

106-
err = fcm.SendPushNotification(user.FcmToken, title, body)
101+
func _SendPushNotification(user usermodel.User, title string, body string) error {
102+
err := fcm.SendPushNotification(user.FcmToken, title, body)
107103
if err != nil {
108104
return err
109105
}
@@ -125,15 +121,13 @@ func HandleRequest(url string, videoURL string) (types.ResponseAnalysis, error)
125121
}
126122
req.Header.Set("Content-Type", "application/json")
127123

128-
// HTTP 클라이언트 요청 보내기
129124
client := &http.Client{}
130125
response, err := client.Do(req)
131126
if err != nil {
132127
return types.ResponseAnalysis{}, err
133128
}
134129
defer response.Body.Close()
135130

136-
// 응답 바디 읽기
137131
body, err := io.ReadAll(response.Body)
138132
if err != nil {
139133
return types.ResponseAnalysis{}, err

‎global/utils/user_util_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,24 @@ func TestUserUtil_FindCurrentUser(t *testing.T) {
8585
assert.Equal(t, expectedUser, user)
8686
}
8787

88+
func TestUserUtil_FindCurrentUser_NoUserID(t *testing.T) {
89+
// Create a new instance of the mock repository
90+
mockRepo := new(MockUserRepository)
91+
92+
// Create an instance of UserUtil with the mock repository
93+
userUtil := utils.NewUserUtil(mockRepo)
94+
95+
// Create a sample gin.Context without the user ID
96+
ctx := &gin.Context{}
97+
98+
// Call the method under test
99+
user, err := userUtil.FindCurrentUser(ctx)
100+
101+
// Validate the result
102+
assert.NotNil(t, err)
103+
assert.Nil(t, user)
104+
}
105+
88106
func TestUserUtil_FindCurrentUser_UserNotFound(t *testing.T) {
89107
// Create a new instance of the mock repository
90108
mockRepo := new(MockUserRepository)

0 commit comments

Comments
 (0)
Please sign in to comment.