Skip to content

Commit

Permalink
test: resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Lifosmin Simon authored and Lifosmin Simon committed Aug 31, 2023
1 parent 93cc1ba commit 2e4cd81
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 17 deletions.
Binary file removed __debug_bin1379664372
Binary file not shown.
10 changes: 8 additions & 2 deletions api/handler/v1beta1/appeal.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,19 @@ func (s *GRPCServer) listAppeals(ctx context.Context, filters *domain.ListAppeal

eg.Go(func() error {
appealRecords, err := s.appealService.Find(ctx, filters)
if err != nil {
return status.Errorf(codes.Internal, "failed to get appeal list: %s", err)
}
appeals = appealRecords
return err
return nil
})
eg.Go(func() error {
totalRecord, err := s.appealService.GetAppealsTotalCount(ctx, filters)
if err != nil {
return status.Errorf(codes.Internal, "failed to get appeal total count: %s", err)
}
total = totalRecord
return err
return nil
})

if err := eg.Wait(); err != nil {
Expand Down
22 changes: 14 additions & 8 deletions api/handler/v1beta1/appeal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package v1beta1_test
import (
"context"
"errors"
"fmt"
"time"

"github.com/google/uuid"
Expand Down Expand Up @@ -121,9 +122,9 @@ func (s *GrpcHandlersSuite) TestListUserAppeals() {
},
Total: 1,
}
s.appealService.EXPECT().Find(mock.AnythingOfType("*context.valueCtx"), expectedFilters).
s.appealService.EXPECT().Find(mock.AnythingOfType("*context.cancelCtx"), expectedFilters).
Return(expectedAppeals, nil).Once()
s.appealService.EXPECT().GetAppealsTotalCount(mock.AnythingOfType("*context.valueCtx"), expectedFilters).
s.appealService.EXPECT().GetAppealsTotalCount(mock.AnythingOfType("*context.cancelCtx"), expectedFilters).
Return(int64(1), nil).Once()

req := &guardianv1beta1.ListUserAppealsRequest{
Expand Down Expand Up @@ -163,13 +164,16 @@ func (s *GrpcHandlersSuite) TestListUserAppeals() {
s.setup()

expectedError := errors.New("random error")
s.appealService.EXPECT().Find(mock.AnythingOfType("*context.valueCtx"), mock.Anything).
s.appealService.EXPECT().Find(mock.AnythingOfType("*context.cancelCtx"), mock.Anything).
Return(nil, expectedError).Once()
s.appealService.EXPECT().GetAppealsTotalCount(mock.AnythingOfType("*context.cancelCtx"), mock.Anything).
Return(int64(0), nil).Once()

req := &guardianv1beta1.ListUserAppealsRequest{}
ctx := context.WithValue(context.Background(), authEmailTestContextKey{}, "test-user")
res, err := s.grpcServer.ListUserAppeals(ctx, req)

fmt.Println(status.Code(err))
s.Equal(codes.Internal, status.Code(err))
s.Nil(res)
s.appealService.AssertExpectations(s.T())
Expand All @@ -185,9 +189,9 @@ func (s *GrpcHandlersSuite) TestListUserAppeals() {
},
},
}
s.appealService.EXPECT().Find(mock.AnythingOfType("*context.valueCtx"), mock.Anything).
s.appealService.EXPECT().Find(mock.AnythingOfType("*context.cancelCtx"), mock.Anything).
Return(invalidAppeals, nil).Once()
s.appealService.EXPECT().GetAppealsTotalCount(mock.AnythingOfType("*context.valueCtx"), mock.Anything).
s.appealService.EXPECT().GetAppealsTotalCount(mock.AnythingOfType("*context.cancelCtx"), mock.Anything).
Return(int64(1), nil).Once()

req := &guardianv1beta1.ListUserAppealsRequest{}
Expand Down Expand Up @@ -325,8 +329,10 @@ func (s *GrpcHandlersSuite) TestListAppeals() {
s.setup()

expectedError := errors.New("random error")
s.appealService.EXPECT().Find(mock.AnythingOfType("*context.emptyCtx"), mock.Anything).
s.appealService.EXPECT().Find(mock.AnythingOfType("*context.cancelCtx"), mock.Anything).
Return(nil, expectedError).Once()
s.appealService.EXPECT().GetAppealsTotalCount(mock.AnythingOfType("*context.cancelCtx"), mock.Anything).
Return(int64(0), nil).Once()

req := &guardianv1beta1.ListAppealsRequest{}
res, err := s.grpcServer.ListAppeals(context.Background(), req)
Expand All @@ -346,9 +352,9 @@ func (s *GrpcHandlersSuite) TestListAppeals() {
},
},
}
s.appealService.EXPECT().Find(mock.AnythingOfType("*context.emptyCtx"), mock.Anything).
s.appealService.EXPECT().Find(mock.AnythingOfType("*context.cancelCtx"), mock.Anything).
Return(invalidAppeals, nil).Once()
s.appealService.EXPECT().GetAppealsTotalCount(mock.AnythingOfType("*context.emptyCtx"), mock.Anything).
s.appealService.EXPECT().GetAppealsTotalCount(mock.AnythingOfType("*context.cancelCtx"), mock.Anything).
Return(int64(1), nil).Once()

req := &guardianv1beta1.ListAppealsRequest{}
Expand Down
10 changes: 8 additions & 2 deletions api/handler/v1beta1/grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,19 @@ func (s *GRPCServer) listGrants(ctx context.Context, filter domain.ListGrantsFil

eg.Go(func() error {
grantRecords, err := s.grantService.List(ctx, filter)
if err != nil {
return status.Errorf(codes.Internal, "failed to get grant list: %s", err)
}
grants = grantRecords
return err
return nil
})
eg.Go(func() error {
totalRecord, err := s.grantService.GetGrantsTotalCount(ctx, filter)
if err != nil {
return status.Errorf(codes.Internal, "failed to get grant total count: %s", err)
}
total = totalRecord
return err
return nil
})

if err := eg.Wait(); err != nil {
Expand Down
13 changes: 8 additions & 5 deletions api/handler/v1beta1/grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ func (s *GrpcHandlersSuite) TestListGrants() {
ResourceIDs: []string{"test-resource-id"},
}
s.grantService.EXPECT().
List(mock.AnythingOfType("*context.emptyCtx"), expectedFilter).
List(mock.AnythingOfType("*context.cancelCtx"), expectedFilter).
Return(dummyGrants, nil).Once()
s.grantService.EXPECT().
GetGrantsTotalCount(mock.AnythingOfType("*context.emptyCtx"), expectedFilter).
GetGrantsTotalCount(mock.AnythingOfType("*context.cancelCtx"), expectedFilter).
Return(int64(1), nil).Once()

req := &guardianv1beta1.ListGrantsRequest{
Expand All @@ -99,8 +99,11 @@ func (s *GrpcHandlersSuite) TestListGrants() {

expectedError := errors.New("unexpected error")
s.grantService.EXPECT().
List(mock.AnythingOfType("*context.emptyCtx"), mock.AnythingOfType("domain.ListGrantsFilter")).
List(mock.AnythingOfType("*context.cancelCtx"), mock.AnythingOfType("domain.ListGrantsFilter")).
Return(nil, expectedError).Once()
s.grantService.EXPECT().
GetGrantsTotalCount(mock.AnythingOfType("*context.cancelCtx"), mock.AnythingOfType("domain.ListGrantsFilter")).
Return(int64(0), nil).Once()

req := &guardianv1beta1.ListGrantsRequest{}
res, err := s.grpcServer.ListGrants(context.Background(), req)
Expand All @@ -123,10 +126,10 @@ func (s *GrpcHandlersSuite) TestListGrants() {
},
}
s.grantService.EXPECT().
List(mock.AnythingOfType("*context.emptyCtx"), mock.AnythingOfType("domain.ListGrantsFilter")).
List(mock.AnythingOfType("*context.cancelCtx"), mock.AnythingOfType("domain.ListGrantsFilter")).
Return(expectedGrants, nil).Once()
s.grantService.EXPECT().
GetGrantsTotalCount(mock.AnythingOfType("*context.emptyCtx"), mock.AnythingOfType("domain.ListGrantsFilter")).
GetGrantsTotalCount(mock.AnythingOfType("*context.cancelCtx"), mock.AnythingOfType("domain.ListGrantsFilter")).
Return(int64(1), nil).Once()
req := &guardianv1beta1.ListGrantsRequest{}
res, err := s.grpcServer.ListGrants(context.Background(), req)
Expand Down

0 comments on commit 2e4cd81

Please sign in to comment.