From 9edd27b35afca0b6cd3015aa4c3d5631c0f17d68 Mon Sep 17 00:00:00 2001 From: Tom Brooks Date: Tue, 3 Dec 2024 09:48:16 -0500 Subject: [PATCH] wip: unit test for milestone solution link --- pkg/graph/resolvers/mto_milestone_test.go | 46 +++++++++++++++++++ pkg/graph/resolvers/resolver_test.go | 18 ++++++++ ...lestone_solution_links_by_milestone_id.sql | 10 ++++ pkg/sqlqueries/mto_milestone.go | 18 +++++--- pkg/storage/mto_milestone.go | 22 +++++++-- 5 files changed, 103 insertions(+), 11 deletions(-) create mode 100644 pkg/graph/resolvers/mto_milestone_test.go create mode 100644 pkg/sqlqueries/SQL/mto/milestone/get_milestone_solution_links_by_milestone_id.sql diff --git a/pkg/graph/resolvers/mto_milestone_test.go b/pkg/graph/resolvers/mto_milestone_test.go new file mode 100644 index 0000000000..aee7c883ce --- /dev/null +++ b/pkg/graph/resolvers/mto_milestone_test.go @@ -0,0 +1,46 @@ +package resolvers + +import ( + "github.com/cms-enterprise/mint-app/pkg/models" + "github.com/cms-enterprise/mint-app/pkg/storage" + "github.com/samber/lo" +) + +func (suite *ResolverSuite) TestCreateMilestoneSolutionLinks() { + plan := suite.createModelPlan("plan for testing MTO create milestone solution links") + commonMilestoneKey := models.MTOCommonMilestoneKeyAppSupportCon + + // create a milestone + _ = suite.createMilestoneCommon(plan.ID, commonMilestoneKey, []models.MTOCommonSolutionKey{ + models.MTOCSKCcw, + models.MTOCSKApps, + }) + + // validate the created solutions + solutions, err := storage.MTOCommonSolutionGetByCommonMilestoneKeyLoader( + suite.testConfigs.Store, + suite.testConfigs.Logger, + []models.MTOCommonMilestoneKey{commonMilestoneKey}, + ) + suite.NoError(err) + + // select the common solution keys from the common solutions using lo map + commonSolutionKeys := lo.Map(solutions, func(s *models.MTOCommonSolution, index int) models.MTOCommonSolutionKey { + return s.Key + }) + + // validate that the common solution keys are created + suite.Len(commonSolutionKeys, 2) + suite.Contains(commonSolutionKeys, models.MTOCSKCcw) + suite.Contains(commonSolutionKeys, models.MTOCSKApps) + + // validate that the milestone links are created + milestoneSolutionLinks, err := storage.MTOMilestoneSolutionLinkGetByMilestoneID( + suite.testConfigs.Store, + suite.testConfigs.Logger, + plan.ID, + ) + + suite.NoError(err) + suite.Len(milestoneSolutionLinks, 2) +} diff --git a/pkg/graph/resolvers/resolver_test.go b/pkg/graph/resolvers/resolver_test.go index 373d0b437f..38be2025ce 100644 --- a/pkg/graph/resolvers/resolver_test.go +++ b/pkg/graph/resolvers/resolver_test.go @@ -390,6 +390,24 @@ func (suite *ResolverSuite) createDefaultTestAnalyzedAudit(mp *models.ModelPlan, } +func (suite *ResolverSuite) createMilestoneCommon( + planID uuid.UUID, + commonMilestoneKey models.MTOCommonMilestoneKey, + commonSolutions []models.MTOCommonSolutionKey, +) *models.MTOMilestone { + milestone, err := MTOMilestoneCreateCommon( + suite.testConfigs.Context, + suite.testConfigs.Logger, + suite.testConfigs.Principal, + suite.testConfigs.Store, + planID, + commonMilestoneKey, + commonSolutions, + ) + suite.NoError(err) + return milestone +} + // TestResolverSuite runs the resolver test suite func TestResolverSuite(t *testing.T) { rs := new(ResolverSuite) diff --git a/pkg/sqlqueries/SQL/mto/milestone/get_milestone_solution_links_by_milestone_id.sql b/pkg/sqlqueries/SQL/mto/milestone/get_milestone_solution_links_by_milestone_id.sql new file mode 100644 index 0000000000..8c5e480196 --- /dev/null +++ b/pkg/sqlqueries/SQL/mto/milestone/get_milestone_solution_links_by_milestone_id.sql @@ -0,0 +1,10 @@ +SELECT + id, + milestone_id, + solution_id, + created_by, + created_dts, + modified_by, + modified_dts +FROM mto_milestone_solution_link +WHERE milestone_id = :milestone_id; \ No newline at end of file diff --git a/pkg/sqlqueries/mto_milestone.go b/pkg/sqlqueries/mto_milestone.go index 9a6e9d72d6..99d5d212d8 100644 --- a/pkg/sqlqueries/mto_milestone.go +++ b/pkg/sqlqueries/mto_milestone.go @@ -20,6 +20,9 @@ var mtoMilestoneGetByModelPlanIDAndCategoryIDLoaderSQL string //go:embed SQL/mto/milestone/create_milestone_solution_link.sql var mtoMilestoneCreateMilestoneSolutionLinkSQL string +//go:embed SQL/mto/milestone/get_milestone_solution_links_by_milestone_id.sql +var mtoMilestoneGetMilestoneSolutionLinksByMilestoneIDSQL string + type mtoMilestoneScripts struct { Create string Update string @@ -30,13 +33,16 @@ type mtoMilestoneScripts struct { GetByModelPlanIDAndCategoryIDLoader string // creates a link between a milestone and a solution and returns the link ID CreateMilestoneSolutionLink string + // returns all milestone-solution links for a given milestone by ID + GetMilestoneSolutionLinksByMilestoneID string } var MTOMilestone = mtoMilestoneScripts{ - Create: mtoMilestoneCreateSQL, - Update: mtoMilestoneUpdateSQL, - GetByID: mtoMilestoneGetByIDSQL, - GetByModelPlanIDLoader: mtoMilestoneGetByModelPlanIDLoaderSQL, - GetByModelPlanIDAndCategoryIDLoader: mtoMilestoneGetByModelPlanIDAndCategoryIDLoaderSQL, - CreateMilestoneSolutionLink: mtoMilestoneCreateMilestoneSolutionLinkSQL, + Create: mtoMilestoneCreateSQL, + Update: mtoMilestoneUpdateSQL, + GetByID: mtoMilestoneGetByIDSQL, + GetByModelPlanIDLoader: mtoMilestoneGetByModelPlanIDLoaderSQL, + GetByModelPlanIDAndCategoryIDLoader: mtoMilestoneGetByModelPlanIDAndCategoryIDLoaderSQL, + CreateMilestoneSolutionLink: mtoMilestoneCreateMilestoneSolutionLinkSQL, + GetMilestoneSolutionLinksByMilestoneID: mtoMilestoneGetMilestoneSolutionLinksByMilestoneIDSQL, } diff --git a/pkg/storage/mto_milestone.go b/pkg/storage/mto_milestone.go index 7f6e6cba0a..81855dcb53 100644 --- a/pkg/storage/mto_milestone.go +++ b/pkg/storage/mto_milestone.go @@ -3,8 +3,6 @@ package storage import ( "fmt" - "github.com/davecgh/go-spew/spew" - "github.com/google/uuid" "github.com/lib/pq" "go.uber.org/zap" @@ -102,9 +100,6 @@ func MTOMilestoneSolutionLinkCreate( mtoMilestoneSolutionLink.ID = uuid.New() } - println("--- CREATING MTO MILESTONE SOLUTION LINK ---") - spew.Dump(mtoMilestoneSolutionLink) - link, procErr := sqlutils.GetProcedure[models.MTOMilestoneSolutionLink](np, sqlqueries.MTOMilestone.CreateMilestoneSolutionLink, mtoMilestoneSolutionLink) if procErr != nil { return nil, fmt.Errorf("issue creating new MTO Milestone-Solution link: %w", procErr) @@ -112,3 +107,20 @@ func MTOMilestoneSolutionLinkCreate( return link, nil } + +// MTOMilestoneSolutionLinkGetByMilestoneID returns all MTO Milestone-Solution links for a given Milestone ID +func MTOMilestoneSolutionLinkGetByMilestoneID( + np sqlutils.NamedPreparer, + _ *zap.Logger, + milestoneID uuid.UUID, +) ([]*models.MTOMilestoneSolutionLink, error) { + + arg := map[string]interface{}{"milestone_id": milestoneID} + + returned, procErr := sqlutils.SelectProcedure[models.MTOMilestoneSolutionLink](np, sqlqueries.MTOMilestone.GetMilestoneSolutionLinksByMilestoneID, arg) + if procErr != nil { + return nil, fmt.Errorf("issue retrieving MTO Milestone-Solution links: %w", procErr) + } + + return returned, nil +}