Skip to content

Commit

Permalink
remove unused action option from BE (#2764)
Browse files Browse the repository at this point in the history
* (no verify) remove what appears to be an unused rest route - checking. also, used `no-verify` because the go linter hangs. looking at that too

* bump linter

* remove unused param

* condense down to one func instead of the same one twice

* remove unneeded action

* remove unused `isFinal` prop
  • Loading branch information
samoddball authored Aug 19, 2024
1 parent e796344 commit 9f0b918
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 100 deletions.
55 changes: 13 additions & 42 deletions pkg/server/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ func (s *Server) routes(
businessCaseHandler := handlers.NewBusinessCaseHandler(
base,
services.NewFetchBusinessCaseByID(
serviceConfig,
store.FetchBusinessCaseByID,
services.AuthorizeHasEASiRole,
),
Expand All @@ -293,48 +292,20 @@ func (s *Server) routes(

actionHandler := handlers.NewActionHandler(
base,
services.NewTakeAction(
services.NewBusinessCaseTakeAction(
store.FetchSystemIntakeByID,
map[models.ActionType]services.ActionExecuter{
models.ActionTypeSUBMITBIZCASE: services.NewSubmitBusinessCase(
serviceConfig,
services.AuthorizeUserIsIntakeRequester,
store.FetchOpenBusinessCaseByIntakeID,
appvalidation.BusinessCaseForSubmit,
saveAction,
store.UpdateSystemIntake,
store.UpdateBusinessCase,
emailClient.SystemIntake.SendSubmitBizCaseRequesterNotification,
emailClient.SystemIntake.SendSubmitBizCaseReviewerNotification,
publisher.PublishBusinessCase,
),
models.ActionTypeSUBMITFINALBIZCASE: services.NewSubmitBusinessCase(
serviceConfig,
services.AuthorizeUserIsIntakeRequester,
store.FetchOpenBusinessCaseByIntakeID,
appvalidation.BusinessCaseForSubmit,
saveAction,
store.UpdateSystemIntake,
store.UpdateBusinessCase,
emailClient.SystemIntake.SendSubmitBizCaseRequesterNotification,
emailClient.SystemIntake.SendSubmitBizCaseReviewerNotification,
publisher.PublishBusinessCase,
),
models.ActionTypeSUBMITINTAKE: services.NewSubmitSystemIntake(
serviceConfig,
services.AuthorizeUserIsIntakeRequester,
store.UpdateSystemIntake,
// quick adapter to retrofit the new interface to take the place
// of the old interface
func(ctx context.Context, si *models.SystemIntake) (string, error) {
err := publisher.PublishSystemIntake(ctx, *si)
return "", err
},
saveAction,
emailClient.SystemIntake.SendSubmitInitialFormRequesterNotification,
emailClient.SystemIntake.SendSubmitInitialFormReviewerNotification,
),
},
services.NewSubmitBusinessCase(
serviceConfig,
services.AuthorizeUserIsIntakeRequester,
store.FetchOpenBusinessCaseByIntakeID,
appvalidation.BusinessCaseForSubmit,
saveAction,
store.UpdateSystemIntake,
store.UpdateBusinessCase,
emailClient.SystemIntake.SendSubmitBizCaseRequesterNotification,
emailClient.SystemIntake.SendSubmitBizCaseReviewerNotification,
publisher.PublishBusinessCase,
),
),
)
api.Handle("/system_intake/{intake_id}/actions", actionHandler.Handle())
Expand Down
15 changes: 4 additions & 11 deletions pkg/services/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import (
// ActionExecuter is a function that can execute an action
type ActionExecuter func(context.Context, *models.SystemIntake, *models.Action) error

// NewTakeAction is a service to create and execute an action
func NewTakeAction(
// NewBusinessCaseTakeAction is a service to create and execute an action
func NewBusinessCaseTakeAction(
fetch func(context.Context, uuid.UUID) (*models.SystemIntake, error),
actionTypeMap map[models.ActionType]ActionExecuter,
submitBusinessCase ActionExecuter,
) func(context.Context, *models.Action) error {
return func(ctx context.Context, action *models.Action) error {
intake, fetchErr := fetch(ctx, *action.IntakeID)
Expand All @@ -31,14 +31,7 @@ func NewTakeAction(
}
}

if executeAction, ok := actionTypeMap[action.ActionType]; ok {
return executeAction(ctx, intake, action)
}
return &apperrors.ResourceConflictError{
Err: errors.New("invalid action type"),
Resource: intake,
ResourceID: intake.ID.String(),
}
return submitBusinessCase(ctx, intake, action)
}
}

Expand Down
29 changes: 2 additions & 27 deletions pkg/services/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,45 +18,20 @@ func (s *ServicesTestSuite) TestNewTakeAction() {
return &models.SystemIntake{ID: id}, nil
}

s.Run("returns QueryError if fetch fails", func() {
failFetch := func(ctx context.Context, id uuid.UUID) (*models.SystemIntake, error) {
return nil, errors.New("error")
}
createAction := NewTakeAction(failFetch, map[models.ActionType]ActionExecuter{})
id := uuid.New()
action := models.Action{
IntakeID: &id,
ActionType: models.ActionTypeSUBMITINTAKE,
}
err := createAction(ctx, &action)
s.IsType(&apperrors.QueryError{}, err)
})

s.Run("returns error from an action service", func() {
submitError := errors.New("test")
failSubmit := func(ctx context.Context, intake *models.SystemIntake, action *models.Action) error {
return submitError
}
createAction := NewTakeAction(fetch, map[models.ActionType]ActionExecuter{models.ActionTypeSUBMITINTAKE: failSubmit})
createAction := NewBusinessCaseTakeAction(fetch, failSubmit)
id := uuid.New()
action := models.Action{
IntakeID: &id,
ActionType: models.ActionTypeSUBMITINTAKE,
ActionType: models.ActionTypeSUBMITBIZCASE,
}
err := createAction(ctx, &action)
s.Equal(submitError, err)
})

s.Run("returns ResourceConflictError if invalid action type", func() {
createAction := NewTakeAction(fetch, map[models.ActionType]ActionExecuter{})
id := uuid.New()
action := models.Action{
IntakeID: &id,
ActionType: "INVALID",
}
err := createAction(ctx, &action)
s.IsType(&apperrors.ResourceConflictError{}, err)
})
}

func (s *ServicesTestSuite) TestNewSubmitSystemIntake() {
Expand Down
1 change: 0 additions & 1 deletion pkg/services/business_case.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (

// NewFetchBusinessCaseByID is a service to fetch the business case by id
func NewFetchBusinessCaseByID(
config Config,
fetch func(c context.Context, id uuid.UUID) (*models.BusinessCaseWithCosts, error),
authorized func(context.Context) bool,
) func(c context.Context, id uuid.UUID) (*models.BusinessCaseWithCosts, error) {
Expand Down
7 changes: 2 additions & 5 deletions pkg/services/business_case_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ import (
)

func (s *ServicesTestSuite) TestBusinessCaseByIDFetcher() {
logger := zap.NewNop()
fakeID := uuid.New()
serviceConfig := NewConfig(logger, nil)
serviceConfig.clock = clock.NewMock()
authorized := func(context context.Context) bool { return true }

s.Run("successfully fetches Business Case by ID without an error", func() {
Expand All @@ -29,7 +26,7 @@ func (s *ServicesTestSuite) TestBusinessCaseByIDFetcher() {
},
}, nil
}
fetchBusinessCaseByID := NewFetchBusinessCaseByID(serviceConfig, fetch, authorized)
fetchBusinessCaseByID := NewFetchBusinessCaseByID(fetch, authorized)
businessCase, err := fetchBusinessCaseByID(context.Background(), fakeID)
s.NoError(err)

Expand All @@ -40,7 +37,7 @@ func (s *ServicesTestSuite) TestBusinessCaseByIDFetcher() {
fetch := func(ctx context.Context, id uuid.UUID) (*models.BusinessCaseWithCosts, error) {
return &models.BusinessCaseWithCosts{}, errors.New("fetch failed")
}
fetchBusinessCaseByID := NewFetchBusinessCaseByID(serviceConfig, fetch, authorized)
fetchBusinessCaseByID := NewFetchBusinessCaseByID(fetch, authorized)

businessCase, err := fetchBusinessCaseByID(context.Background(), uuid.New())

Expand Down
1 change: 0 additions & 1 deletion src/types/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export type ActionType =
*/
export type CreateActionPayload = {
intakeId: string;
actionType: ActionType;
feedback?: string;
};

Expand Down
12 changes: 2 additions & 10 deletions src/views/BusinessCase/Review/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ import './index.scss';

type ReviewProps = {
businessCase: BusinessCaseModel;
isFinal: boolean;
};

const Review = ({ businessCase, isFinal }: ReviewProps) => {
const Review = ({ businessCase }: ReviewProps) => {
const { t } = useTranslation('businessCase');

const history = useHistory();
Expand Down Expand Up @@ -56,14 +55,7 @@ const Review = ({ businessCase, isFinal }: ReviewProps) => {
type="submit"
disabled={isSubmitting}
onClick={() => {
dispatch(
postAction({
intakeId: businessCase.systemIntakeId,
actionType: isFinal
? 'SUBMIT_FINAL_BIZ_CASE'
: 'SUBMIT_BIZ_CASE'
})
);
dispatch(postAction({ intakeId: businessCase.systemIntakeId }));
}}
>
{t('sendBusinessCase')}
Expand Down
4 changes: 1 addition & 3 deletions src/views/BusinessCase/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,7 @@ export const BusinessCase = () => {
/>
<Route
path="/business/:businessCaseId/review"
render={() => (
<Review businessCase={businessCase} isFinal={isFinal} />
)}
render={() => <Review businessCase={businessCase} />}
/>
<Route
path="/business/:businessCaseId/view"
Expand Down

0 comments on commit 9f0b918

Please sign in to comment.