Skip to content

Commit

Permalink
bugfix for ppm shipments failing on counseling office
Browse files Browse the repository at this point in the history
  • Loading branch information
paulstonebraker committed Mar 4, 2025
1 parent dc3fd38 commit 7475bf4
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 32 deletions.
10 changes: 10 additions & 0 deletions pkg/gen/ghcapi/embedded_spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions pkg/gen/ghcmessages/create_p_p_m_shipment.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/handlers/ghcapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ func NewGhcAPIHandler(handlerConfig handlers.HandlerConfig) *ghcops.MymoveAPI {
handlerConfig,
shipmentCreator,
shipmentSITStatus,
closeoutOfficeUpdater,
}

ghcAPI.MtoShipmentListMTOShipmentsHandler = ListMTOShipmentsHandler{
Expand Down
19 changes: 19 additions & 0 deletions pkg/handlers/ghcapi/mto_shipment.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ type CreateMTOShipmentHandler struct {
handlers.HandlerConfig
shipmentCreator services.ShipmentCreator
shipmentStatus services.ShipmentSITStatus
services.MoveCloseoutOfficeUpdater
}

// Handle creates the mto shipment
Expand Down Expand Up @@ -265,6 +266,24 @@ func (h CreateMTOShipmentHandler) Handle(params mtoshipmentops.CreateMTOShipment
return handleError(err)
}

if payload.PpmShipment != nil && payload.PpmShipment.CloseoutOfficeID != "" {
move, err := models.FetchMoveByMoveID(appCtx.DB(), mtoShipment.MoveTaskOrderID)
if err != nil {
moveFetchError := apperror.NewInternalServerError("Unable to fetch the move associated with this shipment")
appCtx.Logger().Error(moveFetchError.Error())
return mtoshipmentops.NewCreateMTOShipmentInternalServerError(), moveFetchError
}

moveEtag := etag.GenerateEtag(move.UpdatedAt)
closeoutOfficeID := uuid.FromStringOrNil(payload.PpmShipment.CloseoutOfficeID.String())
_, err = h.MoveCloseoutOfficeUpdater.UpdateCloseoutOffice(appCtx, move.Locator, closeoutOfficeID, moveEtag)
if err != nil {
updateCloseoutOfficeError := apperror.NewInternalServerError("Unable to update the move with a closeout office")
appCtx.Logger().Error(updateCloseoutOfficeError.Error())
return mtoshipmentops.NewCreateMTOShipmentInternalServerError(), updateCloseoutOfficeError
}
}

if mtoShipment == nil {
shipmentNotCreatedError := apperror.NewInternalServerError("Unexpected nil shipment from CreateMTOShipment")
appCtx.Logger().Error(shipmentNotCreatedError.Error())
Expand Down
33 changes: 32 additions & 1 deletion pkg/handlers/ghcapi/mto_shipment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/transcom/mymove/pkg/services/query"
sitextension "github.com/transcom/mymove/pkg/services/sit_extension"
sitstatus "github.com/transcom/mymove/pkg/services/sit_status"
transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office"
"github.com/transcom/mymove/pkg/swagger/nullable"
"github.com/transcom/mymove/pkg/trace"
"github.com/transcom/mymove/pkg/unit"
Expand Down Expand Up @@ -3683,15 +3684,21 @@ func (suite *HandlerSuite) TestCreateMTOShipmentHandler() {
)
shipmentCreator := shipmentorchestrator.NewShipmentCreator(creator, ppmCreator, boatCreator, mobileHomeCreator, shipmentRouter, moveTaskOrderUpdater)
sitStatus := sitstatus.NewShipmentSITStatus()
closeoutOfficeUpdater := moveservices.NewCloseoutOfficeUpdater(moveservices.NewMoveFetcher(), transportationoffice.NewTransportationOfficesFetcher())
handler := CreateMTOShipmentHandler{
handlerConfig,
shipmentCreator,
sitStatus,
closeoutOfficeUpdater,
}

// Validate incoming payload
suite.NoError(params.Body.Validate(strfmt.Default))

fmt.Println("params.Body")
fmt.Println(params.Body)
fmt.Println("params.Body.PpmShipment")
fmt.Println(params.Body.PpmShipment)
response := handler.Handle(params)
suite.IsType(&mtoshipmentops.CreateMTOShipmentOK{}, response)
okResponse := response.(*mtoshipmentops.CreateMTOShipmentOK)
Expand All @@ -3715,10 +3722,12 @@ func (suite *HandlerSuite) TestCreateMTOShipmentHandler() {

shipmentCreator := mocks.ShipmentCreator{}
sitStatus := sitstatus.NewShipmentSITStatus()
closeoutOfficeUpdater := moveservices.NewCloseoutOfficeUpdater(moveservices.NewMoveFetcher(), transportationoffice.NewTransportationOfficesFetcher())
handler := CreateMTOShipmentHandler{
handlerConfig,
&shipmentCreator,
sitStatus,
closeoutOfficeUpdater,
}

err := errors.New("ServerError")
Expand Down Expand Up @@ -3767,11 +3776,14 @@ func (suite *HandlerSuite) TestCreateMTOShipmentHandler() {
moveRouter, setUpSignedCertificationCreatorMock(nil, nil), setUpSignedCertificationUpdaterMock(nil, nil), &ppmEstimator,
)
shipmentCreator := shipmentorchestrator.NewShipmentCreator(creator, ppmCreator, boatCreator, mobileHomeCreator, shipmentRouter, moveTaskOrderUpdater)
closeoutOfficeUpdater := moveservices.NewCloseoutOfficeUpdater(moveservices.NewMoveFetcher(), transportationoffice.NewTransportationOfficesFetcher())

sitStatus := sitstatus.NewShipmentSITStatus()
handler := CreateMTOShipmentHandler{
handlerConfig,
shipmentCreator,
sitStatus,
closeoutOfficeUpdater,
}

badID := params.Body.MoveTaskOrderID
Expand Down Expand Up @@ -3825,10 +3837,12 @@ func (suite *HandlerSuite) TestCreateMTOShipmentHandler() {
)
shipmentCreator := shipmentorchestrator.NewShipmentCreator(creator, ppmCreator, boatCreator, mobileHomeCreator, shipmentRouter, moveTaskOrderUpdater)
sitStatus := sitstatus.NewShipmentSITStatus()
closeoutOfficeUpdater := moveservices.NewCloseoutOfficeUpdater(moveservices.NewMoveFetcher(), transportationoffice.NewTransportationOfficesFetcher())
handler := CreateMTOShipmentHandler{
handlerConfig,
shipmentCreator,
sitStatus,
closeoutOfficeUpdater,
}

badParams := params
Expand Down Expand Up @@ -3878,10 +3892,12 @@ func (suite *HandlerSuite) TestCreateMTOShipmentHandler() {
)
shipmentCreator := shipmentorchestrator.NewShipmentCreator(creator, ppmCreator, boatCreator, mobileHomeCreator, shipmentRouter, moveTaskOrderUpdater)
sitStatus := sitstatus.NewShipmentSITStatus()
closeoutOfficeUpdater := moveservices.NewCloseoutOfficeUpdater(moveservices.NewMoveFetcher(), transportationoffice.NewTransportationOfficesFetcher())
handler := CreateMTOShipmentHandler{
handlerConfig,
shipmentCreator,
sitStatus,
closeoutOfficeUpdater,
}

uuidString := "d874d002-5582-4a91-97d3-786e8f66c763"
Expand Down Expand Up @@ -3926,10 +3942,12 @@ func (suite *HandlerSuite) TestCreateMTOShipmentHandler() {
)
shipmentCreator := shipmentorchestrator.NewShipmentCreator(creator, ppmCreator, boatCreator, mobileHomeCreator, shipmentRouter, moveTaskOrderUpdater)
sitStatus := sitstatus.NewShipmentSITStatus()
closeoutOfficeUpdater := moveservices.NewCloseoutOfficeUpdater(moveservices.NewMoveFetcher(), transportationoffice.NewTransportationOfficesFetcher())
handler := CreateMTOShipmentHandler{
handlerConfig,
shipmentCreator,
sitStatus,
closeoutOfficeUpdater,
}

req := httptest.NewRequest("POST", "/mto-shipments", nil)
Expand Down Expand Up @@ -4012,10 +4030,12 @@ func (suite *HandlerSuite) TestCreateMTOShipmentHandlerUsingPPM() {
)
shipmentCreator := shipmentorchestrator.NewShipmentCreator(creator, ppmCreator, boatCreator, mobileHomeCreator, shipmentRouter, moveTaskOrderUpdater)
sitStatus := sitstatus.NewShipmentSITStatus()
closeoutOfficeUpdater := moveservices.NewCloseoutOfficeUpdater(moveservices.NewMoveFetcher(), transportationoffice.NewTransportationOfficesFetcher())
handler := CreateMTOShipmentHandler{
handlerConfig,
shipmentCreator,
sitStatus,
closeoutOfficeUpdater,
}

shipmentType := ghcmessages.MTOShipmentTypePPM
Expand All @@ -4031,7 +4051,13 @@ func (suite *HandlerSuite) TestCreateMTOShipmentHandlerUsingPPM() {
spouseProGearWeight := unit.Pound(200)
estimatedIncentive := 654321
sitEstimatedCost := 67500

transportationOffice := factory.BuildTransportationOffice(suite.DB(), []factory.Customization{
{
Model: models.TransportationOffice{
ProvidesCloseout: true,
},
},
}, nil)
req := httptest.NewRequest("POST", "/mto-shipments", nil)

var pickupAddress ghcmessages.Address
Expand Down Expand Up @@ -4125,6 +4151,7 @@ func (suite *HandlerSuite) TestCreateMTOShipmentHandlerUsingPPM() {
HasProGear: &hasProGear,
ProGearWeight: handlers.FmtPoundPtr(&proGearWeight),
SpouseProGearWeight: handlers.FmtPoundPtr(&spouseProGearWeight),
CloseoutOfficeID: *handlers.FmtUUIDPtr(&transportationOffice.ID),
},
},
}
Expand Down Expand Up @@ -4222,10 +4249,12 @@ func (suite *HandlerSuite) TestCreateMTOShipmentHandlerUsingPPM() {
moveservices.NewMoveRouter(), setUpSignedCertificationCreatorMock(nil, nil), setUpSignedCertificationUpdaterMock(nil, nil), &ppmEstimator,
)
shipmentCreator := shipmentorchestrator.NewShipmentCreator(creator, ppmshipment.NewPPMShipmentCreator(&ppmEstimator, addressCreator), boatCreator, mobileHomeCreator, shipmentRouter, moveTaskOrderUpdater)
closeoutOfficeUpdater := moveservices.NewCloseoutOfficeUpdater(moveservices.NewMoveFetcher(), transportationoffice.NewTransportationOfficesFetcher())
handler := CreateMTOShipmentHandler{
handlerConfig,
shipmentCreator,
sitstatus.NewShipmentSITStatus(),
closeoutOfficeUpdater,
}

shipmentType := ghcmessages.MTOShipmentTypePPM
Expand Down Expand Up @@ -4373,10 +4402,12 @@ func (suite *HandlerSuite) TestCreateMTOShipmentHandlerUsingPPM() {
moveservices.NewMoveRouter(), setUpSignedCertificationCreatorMock(nil, nil), setUpSignedCertificationUpdaterMock(nil, nil), &ppmEstimator,
)
shipmentCreator := shipmentorchestrator.NewShipmentCreator(creator, ppmshipment.NewPPMShipmentCreator(&ppmEstimator, addressCreator), boatCreator, mobileHomeCreator, shipmentRouter, moveTaskOrderUpdater)
closeoutOfficeUpdater := moveservices.NewCloseoutOfficeUpdater(moveservices.NewMoveFetcher(), transportationoffice.NewTransportationOfficesFetcher())
handler := CreateMTOShipmentHandler{
handlerConfig,
shipmentCreator,
sitstatus.NewShipmentSITStatus(),
closeoutOfficeUpdater,
}

shipmentType := ghcmessages.MTOShipmentTypePPM
Expand Down
35 changes: 4 additions & 31 deletions src/components/Office/ShipmentForm/ShipmentForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -395,38 +395,11 @@ const ShipmentForm = (props) => {
moveCode,
shipmentId: newMTOShipment.id,
});
if (formValues.closeoutOffice.id) {
mutateMoveCloseoutOffice(
{
locator: moveCode,
ifMatchETag: move.eTag,
body: { closeoutOfficeId: formValues.closeoutOffice.id },
},
{
onSuccess: () => {
actions.setSubmitting(false);
navigate(currentPath, { replace: true });
if (isTOO) {
navigate(moveViewPath);
} else {
navigate(advancePath);
}
setErrorMessage(null);
onUpdate('success');
},
onError: (error) => {
actions.setSubmitting(false);
handleSetError(error, `Something went wrong, and your changes were not saved. Please try again.`);
},
},
);
navigate(currentPath, { replace: true });
if (isTOO) {
navigate(moveViewPath);
} else {
navigate(currentPath, { replace: true });
if (isTOO) {
navigate(moveViewPath);
} else {
navigate(advancePath);
}
navigate(advancePath);
}
},
onError: (error) => {
Expand Down
1 change: 1 addition & 0 deletions src/utils/formatMtoShipment.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ export function formatPpmShipmentForAPI(formValues) {
hasTertiaryPickupAddress: formValues.hasTertiaryPickup === 'true',
hasTertiaryDestinationAddress: formValues.hasTertiaryDestination === 'true',
isActualExpenseReimbursement: formValues.isActualExpenseReimbursement === 'true',
closeoutOfficeID: formValues.closeoutOffice.id,
};

if (ppmShipmentValues.hasSecondaryPickupAddress) {
Expand Down
4 changes: 4 additions & 0 deletions swagger-def/ghc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7144,6 +7144,10 @@ definitions:
example: false
x-omitempty: false
x-nullable: true
closeoutOfficeID:
example: 1f2270c7-7166-40ae-981e-b200ebdf3054
format: uuid
type: string
required:
- expectedDepartureDate
- pickupAddress
Expand Down
4 changes: 4 additions & 0 deletions swagger/ghc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7476,6 +7476,10 @@ definitions:
example: false
x-omitempty: false
x-nullable: true
closeoutOfficeID:
example: 1f2270c7-7166-40ae-981e-b200ebdf3054
format: uuid
type: string
required:
- expectedDepartureDate
- pickupAddress
Expand Down

0 comments on commit 7475bf4

Please sign in to comment.