Skip to content

Commit

Permalink
[EASI-4635] Discussions API tests (#2908)
Browse files Browse the repository at this point in the history
add tests for discussion API
  • Loading branch information
mynar7 authored Dec 6, 2024
1 parent 589b70c commit 6b1363c
Show file tree
Hide file tree
Showing 6 changed files with 735 additions and 11 deletions.
18 changes: 12 additions & 6 deletions pkg/graph/resolvers/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (s *ResolverSuite) SetupTest() {
assert.NoError(s.T(), err)

// Get the user account from the DB fresh for each test
princ := s.getTestPrincipal(s.testConfigs.Context, s.testConfigs.Store, s.testConfigs.UserInfo.Username)
princ := s.getTestPrincipal(s.testConfigs.Context, s.testConfigs.Store, s.testConfigs.UserInfo.Username, true)
s.testConfigs.Principal = princ

// get new dataloaders to clear any existing cached data
Expand All @@ -62,6 +62,11 @@ func (s *ResolverSuite) SetupTest() {
s.testConfigs.Sender.Clear()
}

func (s *ResolverSuite) getTestContextWithPrincipal(euaID string, isAdmin bool) (context.Context, *authentication.EUAPrincipal) {
princ := s.getTestPrincipal(s.testConfigs.Context, s.testConfigs.Store, euaID, isAdmin)
return appcontext.WithPrincipal(s.testConfigs.Context, princ), princ
}

// TestResolverSuite runs the resolver test suite
func TestResolverSuite(t *testing.T) {
rs := new(ResolverSuite)
Expand Down Expand Up @@ -174,15 +179,16 @@ func NewEmailClient() (*email.Client, *mockSender) {
}

// getTestPrincipal gets a user principal from database
func (s *ResolverSuite) getTestPrincipal(ctx context.Context, store *storage.Store, userName string) *authentication.EUAPrincipal {
func (s *ResolverSuite) getTestPrincipal(ctx context.Context, store *storage.Store, userName string, isAdmin bool) *authentication.EUAPrincipal {

userAccount, _ := userhelpers.GetOrCreateUserAccount(ctx, store, store, userName, true, userhelpers.GetUserInfoAccountInfoWrapperFunc(s.testConfigs.UserSearchClient.FetchUserInfo))

princ := &authentication.EUAPrincipal{
EUAID: userName,
JobCodeEASi: true,
JobCodeGRT: true,
UserAccount: userAccount,
EUAID: userName,
JobCodeEASi: true,
JobCodeGRT: isAdmin,
JobCodeTRBAdmin: isAdmin,
UserAccount: userAccount,
}
return princ

Expand Down
Loading

0 comments on commit 6b1363c

Please sign in to comment.