Skip to content

Commit

Permalink
chore: fix test coverage 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Lifosmin Simon authored and Lifosmin Simon committed Aug 30, 2023
1 parent 79b1e6c commit dd33abf
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 11 deletions.
4 changes: 4 additions & 0 deletions api/handler/v1beta1/appeal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ func (s *GrpcHandlersSuite) TestListUserAppeals() {
ResourceTypes: []string{"test-resource-type"},
ResourceURNs: []string{"test-resource-urn"},
OrderBy: []string{"test-order"},
AccountTypes: []string{"test-account-type"},
Q: "test",
}
expectedAppeals := []*domain.Appeal{
{
Expand Down Expand Up @@ -132,6 +134,8 @@ func (s *GrpcHandlersSuite) TestListUserAppeals() {
ResourceTypes: []string{"test-resource-type"},
ResourceUrns: []string{"test-resource-urn"},
OrderBy: []string{"test-order"},
AccountTypes: []string{"test-account-type"},
Q: "test",
}
ctx := context.WithValue(context.Background(), authEmailTestContextKey{}, expectedUser)
res, err := s.grpcServer.ListUserAppeals(ctx, req)
Expand Down
53 changes: 42 additions & 11 deletions internal/store/postgres/appeal_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,36 @@ func (s *AppealRepositoryTestSuite) TestGetByID() {
})

s.Run("should run query based on filters", func() {
dummyAppeal := &domain.Appeal{
ResourceID: s.dummyResource.ID,
PolicyID: s.dummyPolicy.ID,
PolicyVersion: s.dummyPolicy.Version,
AccountID: "[email protected]",
AccountType: domain.DefaultAppealAccountType,
Role: "role_test",
Permissions: []string{"permission_test"},
CreatedBy: "[email protected]",
timeNowPlusAnHour := time.Now().Add(time.Hour)
dummyAppeals := []*domain.Appeal{
{
ResourceID: s.dummyResource.ID,
PolicyID: s.dummyPolicy.ID,
PolicyVersion: s.dummyPolicy.Version,
AccountID: "[email protected]",
AccountType: domain.DefaultAppealAccountType,
Role: "role_test",
Status: domain.AppealStatusApproved,
Permissions: []string{"permission_test"},
CreatedBy: "[email protected]",
Options: &domain.AppealOptions{
ExpirationDate: &time.Time{},
},
},
{
ResourceID: s.dummyResource.ID,
PolicyID: s.dummyPolicy.ID,
PolicyVersion: s.dummyPolicy.Version,
AccountID: "[email protected]",
AccountType: domain.DefaultAppealAccountType,
Status: domain.AppealStatusCanceled,
Role: "role_test",
Permissions: []string{"permission_test_2"},
CreatedBy: "[email protected]",
Options: &domain.AppealOptions{
ExpirationDate: &timeNowPlusAnHour,
},
},
}
testCases := []struct {
filters *domain.ListAppealsFilter
Expand All @@ -149,13 +170,13 @@ func (s *AppealRepositoryTestSuite) TestGetByID() {
filters: &domain.ListAppealsFilter{
Q: "user",
},
expectedResult: []*domain.Appeal{dummyAppeal},
expectedResult: []*domain.Appeal{dummyAppeals[0], dummyAppeals[1]},
},
{
filters: &domain.ListAppealsFilter{
AccountTypes: []string{"x-account-type"},
},
expectedResult: []*domain.Appeal{dummyAppeal},
expectedResult: []*domain.Appeal{dummyAppeals[0], dummyAppeals[1]},
},
}

Expand All @@ -166,6 +187,16 @@ func (s *AppealRepositoryTestSuite) TestGetByID() {
})
}

func (s *AppealRepositoryTestSuite) TestGetAppealsTotalCount() {

s.Run("should return 0", func() {
actualResult, actualError := s.repository.GetAppealsTotalCount(context.Background(), &domain.ListAppealsFilter{})

s.Equal(int64(0), actualResult)
s.Nil(actualError)
})
}

func (s *AppealRepositoryTestSuite) TestFind() {
timeNowPlusAnHour := time.Now().Add(time.Hour)
dummyAppeals := []*domain.Appeal{
Expand Down
10 changes: 10 additions & 0 deletions internal/store/postgres/approval_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ func (s *ApprovalRepositoryTestSuite) TearDownSuite() {
}
}

func (s *ApprovalRepositoryTestSuite) TestGetApprovalsTotalCount() {

s.Run("should return 0", func() {
actualResult, actualError := s.repository.GetApprovalsTotalCount(context.Background(), &domain.ListApprovalsFilter{})

s.Equal(int64(0), actualResult)
s.Nil(actualError)
})
}

func (s *ApprovalRepositoryTestSuite) TestListApprovals() {
pendingAppeal := &domain.Appeal{
ResourceID: s.dummyResource.ID,
Expand Down
9 changes: 9 additions & 0 deletions internal/store/postgres/grant_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ func (s *GrantRepositoryTestSuite) TearDownSuite() {
}
}

func (s *GrantRepositoryTestSuite) TestGetGrantsTotalCount() {

s.Run("should return 0", func() {
actualResult, actualError := s.repository.GetGrantsTotalCount(context.Background(), domain.ListGrantsFilter{})

s.Equal(int64(0), actualResult)
s.Nil(actualError)
})
}
func (s *GrantRepositoryTestSuite) TestList() {
expDate := time.Now()
dummyGrants := []*domain.Grant{
Expand Down

0 comments on commit dd33abf

Please sign in to comment.