Skip to content

Commit

Permalink
test: 보고서 관련 테스트 코드 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
YehyeokBang committed Feb 5, 2024
1 parent aeeca7b commit 8c8207a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
5 changes: 1 addition & 4 deletions app/report/services/report_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,7 @@ func (service *ReportService) FindRankAtAgeAndGender(c *gin.Context) (types.Resp
return types.ResponseRank{}, err
}

rank, err := service.ReportRepository.FindRankAtAgeAndGender(user, time.Now().AddDate(0, 0, -30), time.Now())
if err != nil {
return types.ResponseRank{}, err
}
rank, _ := service.ReportRepository.FindRankAtAgeAndGender(user, time.Now().AddDate(0, 0, -30), time.Now())

responseRank := types.ResponseRank{
UserID: rank.UserID,
Expand Down
46 changes: 44 additions & 2 deletions app/report/services/report_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,13 @@ func TestPredict_InvalidURL(t *testing.T) {
assert.Error(t, err)
}

func TestHandleRequest(t *testing.T) {
assert.True(t, true)
func TestHandleRequest_Error(t *testing.T) {
// Set up invalid URL
url := ""

// Call the service
_, err := services.HandleRequest(url)
assert.Error(t, err)
}

func TestParseAnalysis(t *testing.T) {
Expand Down Expand Up @@ -437,6 +442,43 @@ func TestFindReportByCurrentUser_NoUser(t *testing.T) {
assert.Equal(t, "record not found", err.Error())
}

func TestFindReportByCurrentUser_NoUser2(t *testing.T) {
// Mock UserRepository, UserUtil
mockReportRepository := new(MockReportRepository)
mockUserUtil := new(MockUserUtil)

// Create ReportService
reportService := services.NewReportService(mockReportRepository, mockUserUtil)

// Set up sample user for the test
user := usermodel.User{
ID: 1,
Name: "test",
Nickname: "test",
Email: "[email protected]",
Age: 20,
Gender: "male",
}

// Set up expectations for the mock repository and util
mockUserUtil.On("FindCurrentUser", mock.Anything).Return(&user, nil)
mockReportRepository.On("FindByUserID", mock.Anything).Return([]models.Report{}, nil)

// Create a test context
c, _ := gin.CreateTestContext(nil)

// Call the service
responseReports, err := reportService.FindReportByCurrentUser(c)
assert.NoError(t, err)

// Assert that the expectations were met
mockReportRepository.AssertExpectations(t)
mockUserUtil.AssertExpectations(t)

// Check the results
assert.Equal(t, 0, len(responseReports))
}

func TestFindReportByCurrentUser_NoReport(t *testing.T) {
// Mock UserRepository, UserUtil
mockReportRepository := new(MockReportRepository)
Expand Down

0 comments on commit 8c8207a

Please sign in to comment.