Skip to content

Commit

Permalink
chore: fix test total
Browse files Browse the repository at this point in the history
  • Loading branch information
Lifosmin Simon authored and Lifosmin Simon committed Aug 29, 2023
1 parent 9cc9364 commit e220c2e
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 25 deletions.
1 change: 1 addition & 0 deletions api/handler/v1beta1/appeal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ func (s *GrpcHandlersSuite) TestListAppeals() {
UpdatedAt: timestamppb.New(timeNow),
},
},
Total: 1,
}
s.appealService.EXPECT().Find(mock.AnythingOfType("*context.emptyCtx"), expectedFilters).
Return(expectedAppeals, nil).Once()
Expand Down
1 change: 1 addition & 0 deletions api/handler/v1beta1/grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func (s *GrpcHandlersSuite) TestListGrants() {
},
},
},
Total: 1,
}
expectedFilter := domain.ListGrantsFilter{
Statuses: []string{"test-status"},
Expand Down
26 changes: 26 additions & 0 deletions core/appeal/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2871,6 +2871,32 @@ func (s *ServiceTestSuite) TestDeleteApprover() {
})
}

func (s *ServiceTestSuite) TestGetAppealsTotalCount() {
s.Run("should return error if got error from repository", func() {
expectedError := errors.New("repository error")
s.mockRepository.EXPECT().
GetAppealsTotalCount(mock.AnythingOfType("*context.emptyCtx"), mock.Anything).
Return(0, expectedError).Once()

actualCount, actualError := s.service.GetAppealsTotalCount(context.Background(), &domain.ListAppealsFilter{})

s.Zero(actualCount)
s.EqualError(actualError, expectedError.Error())
})

s.Run("should return appeals count from repository", func() {
expectedCount := int64(1)
s.mockRepository.EXPECT().
GetAppealsTotalCount(mock.AnythingOfType("*context.emptyCtx"), mock.Anything).
Return(expectedCount, nil).Once()

actualCount, actualError := s.service.GetAppealsTotalCount(context.Background(), &domain.ListAppealsFilter{})

s.Equal(expectedCount, actualCount)
s.NoError(actualError)
})
}

func TestService(t *testing.T) {
suite.Run(t, new(ServiceTestSuite))
}
50 changes: 25 additions & 25 deletions core/grant/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -990,28 +990,28 @@ func (s *ServiceTestSuite) TestDormancyCheck() {
})
}

// func (s *ServiceTestSuite) TestGetGrantsTotalCount() {
// s.Run("should return error if got error from repository", func() {
// expectedError := errors.New("repository error")
// s.mockRepository.EXPECT().
// GetGrantsTotalCount(mock.AnythingOfType("*context.emptyCtx"), mock.Anything).
// Return(0, expectedError).Once()

// actualCount, actualError := s.service.GetGrantsTotalCount(context.Background(), domain.ListGrantsFilter{})

// s.Zero(actualCount)
// s.EqualError(actualError, expectedError.Error())
// })

// s.Run("should return Grants count from repository", func() {
// expectedCount := int64(1)
// s.mockRepository.EXPECT().
// GetGrantsTotalCount(mock.AnythingOfType("*context.emptyCtx"), mock.Anything).
// Return(expectedCount, nil).Once()

// actualCount, actualError := s.service.GetGrantsTotalCount(context.Background(), domain.ListGrantsFilter{})

// s.Equal(expectedCount, actualCount)
// s.NoError(actualError)
// })
// }
func (s *ServiceTestSuite) TestGetGrantsTotalCount() {
s.Run("should return error if got error from repository", func() {
expectedError := errors.New("repository error")
s.mockRepository.EXPECT().
GetGrantsTotalCount(mock.AnythingOfType("*context.emptyCtx"), mock.Anything).
Return(0, expectedError).Once()

actualCount, actualError := s.service.GetGrantsTotalCount(context.Background(), domain.ListGrantsFilter{})

s.Zero(actualCount)
s.EqualError(actualError, expectedError.Error())
})

s.Run("should return Grants count from repository", func() {
expectedCount := int64(1)
s.mockRepository.EXPECT().
GetGrantsTotalCount(mock.AnythingOfType("*context.emptyCtx"), mock.Anything).
Return(expectedCount, nil).Once()

actualCount, actualError := s.service.GetGrantsTotalCount(context.Background(), domain.ListGrantsFilter{})

s.Equal(expectedCount, actualCount)
s.NoError(actualError)
})
}

0 comments on commit e220c2e

Please sign in to comment.