Skip to content

Commit

Permalink
wip: unit test for milestone solution link
Browse files Browse the repository at this point in the history
  • Loading branch information
OddTomBrooks committed Dec 3, 2024
1 parent 45bd047 commit 9edd27b
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 11 deletions.
46 changes: 46 additions & 0 deletions pkg/graph/resolvers/mto_milestone_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
18 changes: 18 additions & 0 deletions pkg/graph/resolvers/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
18 changes: 12 additions & 6 deletions pkg/sqlqueries/mto_milestone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
}
22 changes: 17 additions & 5 deletions pkg/storage/mto_milestone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -102,13 +100,27 @@ 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)
}

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
}

0 comments on commit 9edd27b

Please sign in to comment.