Skip to content

Commit

Permalink
[EASI-4457] Dataloaders Refactor (#2727)
Browse files Browse the repository at this point in the history
* [EASI-4457] Funding sources dataloader and mapper refactor (#2692)

* add funding source dataloader and refactor helpers.OneToMany and Mapper interface

* fix store method, call dataloader version in resolver

* [EASI-4457] Add dataloader to TRB request form resolver (#2695)

add dataloader to trb request form resolver

* [EASI-4457] System intake notes dataloader (#2693)

update notes resolver to use dataloader, add tests for notes

* [EASI-4457] System Intake Actions dataloader (#2694)

add dataloader to system intake actions resolver

* [EASI 4457] - TRB Request Feedback dataloaders (#2700)

* add dataloaders to TRB Feedback

* convert slice to postgres array

* use dataloaders in status calls

* remove unnecessary no rows error check

* [EASI-4457] TRB Advice letter dataloader (#2702)

* add dataloaders to TRB Feedback

* convert slice to postgres array

* use dataloaders in status calls

* remove unnecessary no rows error check

* add dataloaders to advice letter and finish refactoring statuses

* sort mock users

* nil check statuses

* [EASI-4457] TRB attendees dataloaders (#2705)

* add dataloader to trb attendees

* add dataloader for attendees by EUA and TRB ID, update requester component resolver

* use ptr helper, add to resolver test

* [EASI-4457] Add closed requests for testing (#2709)

* refactor seed data to allow for closed request generation

* remove context value and just use a constant

* add regex to LCID test

* [EASI-4457] TRB documents dataloaders (#2706)

* add a dataloader for trb documents, use dataloaders in other resolvers

* semicolons and better error handling

* [EASI-4457] TRB Admin Notes dataloader (#2714)

add dataloaders for TRB admin notes

* [EASI-4457] TRB Request Funding Sources dataloader (#2715)

* add dataloader for trb funding sources

* fix test to allow for empty slice

* add TODO comment

* [EASI-4457] TRB Form System Intakes dataloader (#2722)

add dataloader for trb request form system intakes

* [EASI-4457] Add gov req feedback dataloader (#2731)

* add gov req feedback dataloader

* run gql gen

* [EASI-4457] intake documents dataloader (#2732)

* add dataloader for documents

* use resolver to create fake documents

* update seed script

* update seed script to not fetch users multiple times for closed requests

* add comments

* [EASI-4457] Business Case dataloaders (#2729)

* refactor business case legacy code to allow for biz case and cost line dataloaders with less friction

* cleanup comments

---------

Co-authored-by: samoddball <156127704+samoddball@users.noreply.github.com>

---------

Co-authored-by: samoddball <156127704+samoddball@users.noreply.github.com>
  • Loading branch information
mynar7 and samoddball authored Aug 1, 2024
1 parent 04fea4f commit bedaf2d
Show file tree
Hide file tree
Showing 175 changed files with 2,963 additions and 1,237 deletions.
356 changes: 212 additions & 144 deletions cmd/devdata/main.go

Large diffs are not rendered by default.

55 changes: 24 additions & 31 deletions cmd/devdata/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,23 @@ import (

"github.com/cms-enterprise/easi-app/pkg/appcontext"
"github.com/cms-enterprise/easi-app/pkg/authentication"
"github.com/cms-enterprise/easi-app/pkg/dataloaders"
"github.com/cms-enterprise/easi-app/pkg/local"
"github.com/cms-enterprise/easi-app/pkg/local/cedarcoremock"
"github.com/cms-enterprise/easi-app/pkg/models"
"github.com/cms-enterprise/easi-app/pkg/storage"
"github.com/cms-enterprise/easi-app/pkg/userhelpers"
)

// These represent some users who have mocked okta data
// corresponds to list in /pkg/local/okta_api.go
const (
// PrincipalUser is the "current user" when seeding the data (Adeline Aarons)
PrincipalUser = "ABCD"

// TestUser is the "TEST user" when seeding the data (Terry Thompson)
TestUser = "TEST"

// EndToEnd1User is the username of the user for some end to end testing
EndToEnd1User = "E2E1"

// EndToEnd2User is the username of the user for some end to end testing
EndToEnd2User = "E2E2"

AllyUser = "A11Y"
GaryUser = "GRTB"
AubryUser = "ADMI"
User1User = "USR1"
User2User = "USR2"
User3User = "USR3"
User4User = "USR4"
User5User = "USR5"
TheoUser = "CJRW"
PrincipalUser string = "USR1"
EndToEndUserOne string = "E2E1"
TestUser string = "TEST"
AccessibilityUser string = "A11Y"
Batman string = "BTMN"
)

var UserNamesForCedarSystemRoles = []string{
PrincipalUser, TestUser, EndToEnd1User, EndToEnd2User, AllyUser, GaryUser, AubryUser, User1User, User2User, User3User, User4User, User5User, TheoUser,
// Duplicate so we don't run out of users for roles
PrincipalUser, TestUser, EndToEnd1User, EndToEnd2User, AllyUser, GaryUser, AubryUser, User1User, User2User, User3User, User4User, User5User, TheoUser,
PrincipalUser, TestUser, EndToEnd1User, EndToEnd2User, AllyUser, GaryUser, AubryUser, User1User, User2User, User3User, User4User, User5User, TheoUser}

// FetchUserInfoMock mocks the fetch user info logic
func FetchUserInfoMock(ctx context.Context, username string) (*models.UserInfo, error) {
localOktaClient := local.NewOktaAPIClient()
Expand All @@ -58,14 +38,14 @@ func FetchUserInfosMock(ctx context.Context, usernames []string) ([]*models.User
}

// CtxWithLoggerAndPrincipal makes a context with a mocked logger and principal
func CtxWithLoggerAndPrincipal(logger *zap.Logger, store *storage.Store, username string) context.Context {
func CtxWithLoggerAndPrincipal(ctx context.Context, logger *zap.Logger, store *storage.Store, username string) context.Context {
//Future Enhancement: Consider adding this to the seederConfig, and also emb
if len(username) < 1 {
username = PrincipalUser
}

//Future Enhancement: consider passing the context with the seeder, and using the seeder.UserSearchClient to return mocked data instead of needing to initialize a client for each mock call
userAccount, err := userhelpers.GetOrCreateUserAccount(context.Background(), store, store, username, true, userhelpers.GetUserInfoAccountInfoWrapperFunc(FetchUserInfoMock))
userAccount, err := userhelpers.GetOrCreateUserAccount(ctx, store, store, username, true, userhelpers.GetUserInfoAccountInfoWrapperFunc(FetchUserInfoMock))
if err != nil {
panic(fmt.Errorf("failed to get or create user account for mock data: %w", err))
}
Expand All @@ -76,7 +56,20 @@ func CtxWithLoggerAndPrincipal(logger *zap.Logger, store *storage.Store, usernam
JobCodeGRT: true,
UserAccount: userAccount,
}
ctx := appcontext.WithLogger(context.Background(), logger)
ctx = appcontext.WithLogger(ctx, logger)
ctx = appcontext.WithPrincipal(ctx, princ)
return ctx
}

func CtxWithNewDataloaders(ctx context.Context, store *storage.Store) context.Context {
getCedarSystems := func(ctx context.Context) ([]*models.CedarSystem, error) {
return cedarcoremock.GetActiveSystems(), nil
}

buildDataloaders := func() *dataloaders.Dataloaders {
return dataloaders.NewDataloaders(store, local.NewOktaAPIClient().FetchUserInfos, getCedarSystems)
}

// Set up mocked dataloaders for the test context
return dataloaders.CTXWithLoaders(ctx, buildDataloaders)
}
Loading

0 comments on commit bedaf2d

Please sign in to comment.