Skip to content

Commit

Permalink
test: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bsushmith committed Jun 1, 2023
1 parent a7c130e commit fff3d5f
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions core/appeal/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func (s *ServiceTestSuite) TestCreate() {
appeal.TimeNow = func() time.Time {
return timeNow
}

s.Run("should return error if got error from resource service", func() {
expectedError := errors.New("resource service error")
s.mockResourceService.On("Find", mock.Anything, mock.Anything).Return(nil, expectedError).Once()
Expand Down Expand Up @@ -2360,6 +2361,37 @@ func (s *ServiceTestSuite) TestCancel() {
s.EqualError(actualErr, expectedErr.Error())
})

s.Run("should return error if appeal is not found", func() {
id := uuid.New().String()
expectedErr := appeal.ErrAppealNotFound

s.mockRepository.EXPECT().GetByID(mock.AnythingOfType("*context.emptyCtx"), id).Return(nil, expectedErr).Once()

actualResult, actualErr := s.service.Cancel(context.Background(), id)
s.Nil(actualResult)
s.EqualError(actualErr, expectedErr.Error())
})

s.Run("should return cancelled appeal", func() {
id := uuid.New().String()
a := &domain.Appeal{
ID: id,
Status: domain.AppealStatusPending,
}
expectedResult := &domain.Appeal{
ID: id,
Status: domain.AppealStatusCanceled,
}
s.mockRepository.EXPECT().GetByID(mock.AnythingOfType("*context.emptyCtx"), id).Return(a, nil).Once()

s.mockRepository.EXPECT().Update(mock.AnythingOfType("*context.emptyCtx"), expectedResult).Return(nil).Once()
s.mockAuditLogger.EXPECT().Log(mock.Anything, appeal.AuditKeyCancel, map[string]interface{}{"appeal_id": id}).Return(nil).Once()

actualResult, actualErr := s.service.Cancel(context.Background(), id)
s.Nil(actualErr)
s.Equal(expectedResult, actualResult)
})

}

func (s *ServiceTestSuite) TestAddApprover() {
Expand Down

0 comments on commit fff3d5f

Please sign in to comment.