From 7e9693ae4d85bad5d465256c34b7e452d3379045 Mon Sep 17 00:00:00 2001 From: Elizabeth Perkins Date: Mon, 16 Dec 2024 15:04:03 +0000 Subject: [PATCH 01/28] Disables counseling checkbox --- pkg/services/move/move_router.go | 10 ++++++++++ .../RequestedShipments/SubmittedRequestedShipments.jsx | 10 ++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/pkg/services/move/move_router.go b/pkg/services/move/move_router.go index c44f3756de0..d06994bed41 100644 --- a/pkg/services/move/move_router.go +++ b/pkg/services/move/move_router.go @@ -188,6 +188,16 @@ func (router moveRouter) sendToServiceCounselor(appCtx appcontext.AppContext, mo } } + // if move.IsPPMOnly() && !orders.OriginDutyLocation.ProvidesServicesCounseling { + // originLocationID := uuid.FromStringOrNil(orders.OriginDutyLocationID.String()) + + // officeList, err := ShowCounselingOfficesHandler.TransportationOfficesFetcher.GetCounselingOffices(appCtx, originLocationID) + // if err != nil { + + // } + + // } + if move.Status == models.MoveStatusNeedsServiceCounseling { return nil } diff --git a/src/components/Office/RequestedShipments/SubmittedRequestedShipments.jsx b/src/components/Office/RequestedShipments/SubmittedRequestedShipments.jsx index 7359b232780..5b50fe94a87 100644 --- a/src/components/Office/RequestedShipments/SubmittedRequestedShipments.jsx +++ b/src/components/Office/RequestedShipments/SubmittedRequestedShipments.jsx @@ -255,9 +255,11 @@ const SubmittedRequestedShipments = ({ const dutyLocationPostal = { postalCode: ordersInfo.newDutyLocation?.address?.postalCode }; - // Hide counseling line item if prime counseling is already in the service items, if service counseling has been applied, or if full PPM move - const hideCounselingCheckbox = - hasCounseling(mtoServiceItems) || moveTaskOrder?.serviceCounselingCompletedAt || isPPMOnly(mtoShipments); + // Hide counseling line item if prime counseling is already in the service items or if service counseling has been applied + const hideCounselingCheckbox = hasCounseling(mtoServiceItems) || moveTaskOrder?.serviceCounselingCompletedAt; + + // Disable counseling checkbox if full PPM shipment + const disableCounselingCheckbox = isPPMOnly(mtoShipments); // Hide move management line item if it is already in the service items or for PPM only moves const hideMoveManagementCheckbox = hasMoveManagement(mtoServiceItems) || isPPMOnly(mtoShipments); @@ -373,7 +375,7 @@ const SubmittedRequestedShipments = ({ name="counselingFee" onChange={formik.handleChange} data-testid="counselingFee" - disabled={isMoveLocked} + disabled={isMoveLocked || disableCounselingCheckbox} /> )} From 945cf219f57fd944733878ab03822b4d86fa3411 Mon Sep 17 00:00:00 2001 From: Elizabeth Perkins Date: Tue, 24 Dec 2024 16:46:03 +0000 Subject: [PATCH 02/28] Changes moveRouter struct to add transportationOfficesFetcher --- pkg/handlers/adminapi/api.go | 2 +- pkg/handlers/adminapi/moves_test.go | 3 +- pkg/handlers/ghcapi/api.go | 2 +- pkg/handlers/ghcapi/move_task_order_test.go | 9 +-- pkg/handlers/ghcapi/mto_service_items_test.go | 9 +-- pkg/handlers/ghcapi/mto_shipment_test.go | 51 ++++++++-------- pkg/handlers/ghcapi/orders_test.go | 19 +++--- pkg/handlers/internalapi/api.go | 2 +- pkg/handlers/internalapi/moves_test.go | 8 +-- pkg/handlers/internalapi/mto_shipment_test.go | 3 +- pkg/handlers/internalapi/office_test.go | 13 ++-- pkg/handlers/internalapi/orders_test.go | 3 +- .../internalapi/service_members_test.go | 3 +- pkg/handlers/primeapi/api.go | 3 +- pkg/handlers/primeapi/move_task_order_test.go | 5 +- .../primeapi/mto_service_item_test.go | 39 ++++++------ pkg/handlers/primeapi/mto_shipment_test.go | 5 +- pkg/handlers/primeapi/sit_extension_test.go | 3 +- pkg/handlers/primeapiv2/api.go | 3 +- .../primeapiv2/mto_service_item_test.go | 35 +++++------ pkg/handlers/primeapiv2/mto_shipment_test.go | 3 +- pkg/handlers/primeapiv3/api.go | 3 +- .../primeapiv3/mto_service_item_test.go | 35 +++++------ pkg/handlers/primeapiv3/mto_shipment_test.go | 3 +- pkg/handlers/supportapi/api.go | 3 +- .../supportapi/move_task_order_test.go | 5 +- .../supportapi/mto_service_item_test.go | 7 ++- pkg/handlers/supportapi/mto_shipment_test.go | 3 +- .../mocks/TransportationOfficesFetcher.go | 6 ++ pkg/services/move/move_router.go | 26 ++++---- pkg/services/move/move_router_test.go | 13 ++-- .../move_history/move_history_fetcher_test.go | 7 ++- .../move_task_order_updater_test.go | 29 ++++----- .../mto_service_item_creator_test.go | 23 +++---- .../mto_service_item_updater_test.go | 5 +- .../mto_shipment/mto_shipment_creator_test.go | 5 +- .../mto_shipment/mto_shipment_updater_test.go | 15 ++--- .../mto_shipment/shipment_approver_test.go | 3 +- .../shipment_cancellation_requester_test.go | 7 ++- .../mto_shipment/shipment_deleter_test.go | 15 ++--- .../shipment_diversion_approver_test.go | 3 +- .../order/excess_weight_risk_manager_test.go | 43 ++++++------- pkg/services/order/order_updater_test.go | 61 ++++++++++--------- .../shipment_address_update_requester_test.go | 7 ++- .../sit_extension_approver_test.go | 3 +- .../sit_extension_creator_test.go | 3 +- .../sit_extension_denier_test.go | 3 +- pkg/services/transportation_office.go | 1 + .../transportation_office_fetcher.go | 12 ++++ pkg/testdatagen/scenario/devseed.go | 3 +- pkg/testdatagen/scenario/e2ebasic.go | 3 +- pkg/testdatagen/testharness/make_move.go | 11 ++-- 52 files changed, 327 insertions(+), 262 deletions(-) diff --git a/pkg/handlers/adminapi/api.go b/pkg/handlers/adminapi/api.go index 34d6729a0f2..39132e12843 100644 --- a/pkg/handlers/adminapi/api.go +++ b/pkg/handlers/adminapi/api.go @@ -209,7 +209,7 @@ func NewAdminAPI(handlerConfig handlers.HandlerConfig) *adminops.MymoveAPI { pagination.NewPagination, } - moveRouter := move.NewMoveRouter() + moveRouter := move.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) signedCertificationCreator := signedcertification.NewSignedCertificationCreator() signedCertificationUpdater := signedcertification.NewSignedCertificationUpdater() adminAPI.MovesUpdateMoveHandler = UpdateMoveHandler{ diff --git a/pkg/handlers/adminapi/moves_test.go b/pkg/handlers/adminapi/moves_test.go index 81e166a35e8..222c396d434 100644 --- a/pkg/handlers/adminapi/moves_test.go +++ b/pkg/handlers/adminapi/moves_test.go @@ -22,6 +22,7 @@ import ( mtoserviceitem "github.com/transcom/mymove/pkg/services/mto_service_item" "github.com/transcom/mymove/pkg/services/pagination" "github.com/transcom/mymove/pkg/services/query" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" ) func (suite *HandlerSuite) TestIndexMovesHandler() { @@ -111,7 +112,7 @@ func (suite *HandlerSuite) TestUpdateMoveHandler() { ppmEstimator := &mocks.PPMEstimator{} setupHandler := func() UpdateMoveHandler { builder := query.NewQueryBuilder() - moveRouter := move.NewMoveRouter() + moveRouter := move.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), diff --git a/pkg/handlers/ghcapi/api.go b/pkg/handlers/ghcapi/api.go index 5edc3f7e3ee..d8d4edc1d01 100644 --- a/pkg/handlers/ghcapi/api.go +++ b/pkg/handlers/ghcapi/api.go @@ -64,7 +64,7 @@ func NewGhcAPIHandler(handlerConfig handlers.HandlerConfig) *ghcops.MymoveAPI { } ghcAPI := ghcops.NewMymoveAPI(ghcSpec) queryBuilder := query.NewQueryBuilder() - moveRouter := move.NewMoveRouter() + moveRouter := move.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) moveLocker := movelocker.NewMoveLocker() addressCreator := address.NewAddressCreator() shipmentFetcher := mtoshipment.NewMTOShipmentFetcher() diff --git a/pkg/handlers/ghcapi/move_task_order_test.go b/pkg/handlers/ghcapi/move_task_order_test.go index 10e9630fc44..0ecbb0e9741 100644 --- a/pkg/handlers/ghcapi/move_task_order_test.go +++ b/pkg/handlers/ghcapi/move_task_order_test.go @@ -36,6 +36,7 @@ import ( movetaskorder "github.com/transcom/mymove/pkg/services/move_task_order" mtoserviceitem "github.com/transcom/mymove/pkg/services/mto_service_item" "github.com/transcom/mymove/pkg/services/query" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" "github.com/transcom/mymove/pkg/testdatagen" "github.com/transcom/mymove/pkg/trace" ) @@ -183,7 +184,7 @@ func (suite *HandlerSuite) TestUpdateMoveTaskOrderHandlerIntegrationSuccess() { handlerConfig := suite.HandlerConfig() handlerConfig.SetNotificationSender(notifications.NewStubNotificationSender("milmovelocal")) queryBuilder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -306,7 +307,7 @@ func (suite *HandlerSuite) TestUpdateMoveTaskOrderHandlerIntegrationWithIncomple } handlerConfig := suite.HandlerConfig() queryBuilder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) ppmEstimator := &mocks.PPMEstimator{} planner := &routemocks.Planner{} planner.On("ZipTransitDistance", @@ -395,7 +396,7 @@ func (suite *HandlerSuite) TestUpdateMTOStatusServiceCounselingCompletedHandler( setupTestData := func() UpdateMTOStatusServiceCounselingCompletedHandlerFunc { handlerConfig := suite.HandlerConfig() queryBuilder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -614,7 +615,7 @@ func (suite *HandlerSuite) TestUpdateMoveTIORemarksHandler() { requestUser := factory.BuildUser(nil, nil, nil) handlerConfig := suite.HandlerConfig() queryBuilder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), diff --git a/pkg/handlers/ghcapi/mto_service_items_test.go b/pkg/handlers/ghcapi/mto_service_items_test.go index 16bd37da126..21d6ad52d17 100644 --- a/pkg/handlers/ghcapi/mto_service_items_test.go +++ b/pkg/handlers/ghcapi/mto_service_items_test.go @@ -32,6 +32,7 @@ import ( ppmshipment "github.com/transcom/mymove/pkg/services/ppmshipment" "github.com/transcom/mymove/pkg/services/query" sitstatus "github.com/transcom/mymove/pkg/services/sit_status" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" "github.com/transcom/mymove/pkg/testdatagen" "github.com/transcom/mymove/pkg/trace" ) @@ -322,7 +323,7 @@ func (suite *HandlerSuite) TestUpdateMTOServiceItemStatusHandler() { mockSender := suite.TestNotificationSender() addressUpdater := address.NewAddressUpdater() addressCreator := address.NewAddressCreator() - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) noCheckUpdater := mtoshipment.NewMTOShipmentUpdater(builder, fetcher, planner, moveRouter, moveWeights, mockSender, paymentRequestShipmentRecalculator, addressUpdater, addressCreator) ppmEstimator := mocks.PPMEstimator{} @@ -554,7 +555,7 @@ func (suite *HandlerSuite) TestUpdateMTOServiceItemStatusHandler() { } fetcher := fetch.NewFetcher(queryBuilder) - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) shipmentFetcher := mtoshipment.NewMTOShipmentFetcher() addressCreator := address.NewAddressCreator() planner := &routemocks.Planner{} @@ -593,7 +594,7 @@ func (suite *HandlerSuite) TestUpdateMTOServiceItemStatusHandler() { // by the handler is working as expected. suite.Run("Successful status update of MTO service item and event trigger", func() { queryBuilder := query.NewQueryBuilder() - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) shipmentFetcher := mtoshipment.NewMTOShipmentFetcher() mtoServiceItem, availableMove := suite.createServiceItem() requestUser := factory.BuildUser(nil, nil, nil) @@ -767,7 +768,7 @@ func (suite *HandlerSuite) TestUpdateServiceItemSitEntryDateHandler() { mockSender := suite.TestNotificationSender() addressUpdater := address.NewAddressUpdater() addressCreator := address.NewAddressCreator() - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) noCheckUpdater := mtoshipment.NewMTOShipmentUpdater(builder, fetcher, planner, moveRouter, moveWeights, mockSender, paymentRequestShipmentRecalculator, addressUpdater, addressCreator) ppmEstimator := mocks.PPMEstimator{} diff --git a/pkg/handlers/ghcapi/mto_shipment_test.go b/pkg/handlers/ghcapi/mto_shipment_test.go index 1fb84918cc7..381c2ca8623 100644 --- a/pkg/handlers/ghcapi/mto_shipment_test.go +++ b/pkg/handlers/ghcapi/mto_shipment_test.go @@ -38,6 +38,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" @@ -595,7 +596,7 @@ func (suite *HandlerSuite) TestApproveShipmentHandler() { eTag := etag.GenerateEtag(shipment.UpdatedAt) officeUser := factory.BuildOfficeUserWithRoles(nil, nil, []roles.RoleType{roles.RoleTypeTOO}) builder := query.NewQueryBuilder() - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} moveWeights := moveservices.NewMoveWeights(mtoshipment.NewShipmentReweighRequester()) planner.On("ZipTransitDistance", @@ -1195,7 +1196,7 @@ func (suite *HandlerSuite) TestApproveShipmentDiversionHandler() { officeUser := factory.BuildOfficeUserWithRoles(nil, nil, []roles.RoleType{roles.RoleTypeTOO}) approver := mtoshipment.NewShipmentDiversionApprover( mtoshipment.NewShipmentRouter(), - moveservices.NewMoveRouter(), + moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()), ) req := httptest.NewRequest("POST", fmt.Sprintf("/shipments/%s/approve-diversion", shipment.ID.String()), nil) @@ -1821,7 +1822,7 @@ func (suite *HandlerSuite) TestRequestShipmentCancellationHandler() { officeUser := factory.BuildOfficeUserWithRoles(nil, nil, []roles.RoleType{roles.RoleTypeTOO}) canceler := mtoshipment.NewShipmentCancellationRequester( mtoshipment.NewShipmentRouter(), - moveservices.NewMoveRouter(), + moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()), ) req := httptest.NewRequest("POST", fmt.Sprintf("/shipments/%s/request-cancellation", shipment.ID.String()), nil) @@ -2123,7 +2124,7 @@ func (suite *HandlerSuite) TestRequestShipmentReweighHandler() { mock.Anything, mock.Anything, ).Return(400, nil) - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) moveWeights := moveservices.NewMoveWeights(mtoshipment.NewShipmentReweighRequester()) // Get shipment payment request recalculator service @@ -2181,7 +2182,7 @@ func (suite *HandlerSuite) TestRequestShipmentReweighHandler() { mock.Anything, mock.Anything, ).Return(400, nil) - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) moveWeights := moveservices.NewMoveWeights(mtoshipment.NewShipmentReweighRequester()) // Get shipment payment request recalculator service @@ -2236,7 +2237,7 @@ func (suite *HandlerSuite) TestRequestShipmentReweighHandler() { mock.Anything, mock.Anything, ).Return(400, nil) - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) moveWeights := moveservices.NewMoveWeights(mtoshipment.NewShipmentReweighRequester()) // Get shipment payment request recalculator service @@ -2292,7 +2293,7 @@ func (suite *HandlerSuite) TestRequestShipmentReweighHandler() { mock.Anything, mock.Anything, ).Return(400, nil) - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) moveWeights := moveservices.NewMoveWeights(mtoshipment.NewShipmentReweighRequester()) // Get shipment payment request recalculator service @@ -2349,7 +2350,7 @@ func (suite *HandlerSuite) TestRequestShipmentReweighHandler() { mock.Anything, mock.Anything, ).Return(400, nil) - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) moveWeights := moveservices.NewMoveWeights(mtoshipment.NewShipmentReweighRequester()) // Get shipment payment request recalculator service @@ -2405,7 +2406,7 @@ func (suite *HandlerSuite) TestRequestShipmentReweighHandler() { mock.Anything, mock.Anything, ).Return(400, nil) - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) moveWeights := moveservices.NewMoveWeights(mtoshipment.NewShipmentReweighRequester()) // Get shipment payment request recalculator service @@ -2729,7 +2730,7 @@ func (suite *HandlerSuite) TestApproveSITExtensionHandler() { }, nil) eTag := etag.GenerateEtag(mtoShipment.UpdatedAt) officeUser := factory.BuildOfficeUserWithRoles(nil, nil, []roles.RoleType{roles.RoleTypeTOO}) - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) sitExtensionApprover := sitextension.NewSITExtensionApprover(moveRouter) req := httptest.NewRequest("PATCH", fmt.Sprintf("/shipments/%s/sit-extension/%s/approve", mtoShipment.ID.String(), sitExtension.ID.String()), nil) req = suite.AuthenticateOfficeRequest(req, officeUser) @@ -2826,7 +2827,7 @@ func (suite *HandlerSuite) TestDenySITExtensionHandler() { }, nil) eTag := etag.GenerateEtag(mtoShipment.UpdatedAt) officeUser := factory.BuildOfficeUserWithRoles(nil, nil, []roles.RoleType{roles.RoleTypeTOO}) - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) sitExtensionDenier := sitextension.NewSITExtensionDenier(moveRouter) req := httptest.NewRequest("PATCH", fmt.Sprintf("/shipments/%s/sit-extension/%s/deny", mtoShipment.ID.String(), sitExtension.ID.String()), nil) req = suite.AuthenticateOfficeRequest(req, officeUser) @@ -2893,7 +2894,7 @@ func (suite *HandlerSuite) CreateApprovedSITDurationUpdate() { mockSender := suite.TestNotificationSender() addressUpdater := address.NewAddressUpdater() addressCreator := address.NewAddressCreator() - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) noCheckUpdater := mtoshipment.NewMTOShipmentUpdater(builder, fetcher, planner, moveRouter, moveWeights, mockSender, paymentRequestShipmentRecalculator, addressUpdater, addressCreator) ppmEstimator := mocks.PPMEstimator{} @@ -2976,7 +2977,7 @@ func (suite *HandlerSuite) CreateApprovedSITDurationUpdate() { mockSender := suite.TestNotificationSender() addressUpdater := address.NewAddressUpdater() addressCreator := address.NewAddressCreator() - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) noCheckUpdater := mtoshipment.NewMTOShipmentUpdater(builder, fetcher, planner, moveRouter, moveWeights, mockSender, paymentRequestShipmentRecalculator, addressUpdater, addressCreator) ppmEstimator := mocks.PPMEstimator{} @@ -3091,7 +3092,7 @@ func (suite *HandlerSuite) makeCreateMTOShipmentSubtestData() (subtestData *crea } func (suite *HandlerSuite) TestCreateMTOShipmentHandler() { - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) addressCreator := address.NewAddressCreator() setUpSignedCertificationCreatorMock := func(returnValue ...interface{}) services.SignedCertificationCreator { @@ -3450,7 +3451,7 @@ func (suite *HandlerSuite) TestCreateMTOShipmentHandlerUsingPPM() { handlerConfig := suite.HandlerConfig() builder := query.NewQueryBuilder() fetcher := fetch.NewFetcher(builder) - creator := mtoshipment.NewMTOShipmentCreatorV1(builder, fetcher, moveservices.NewMoveRouter(), addressCreator) + creator := mtoshipment.NewMTOShipmentCreatorV1(builder, fetcher, moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()), addressCreator) ppmEstimator := mocks.PPMEstimator{} ppmCreator := ppmshipment.NewPPMShipmentCreator(&ppmEstimator, addressCreator) boatCreator := boatshipment.NewBoatShipmentCreator() @@ -3465,8 +3466,8 @@ func (suite *HandlerSuite) TestCreateMTOShipmentHandlerUsingPPM() { moveTaskOrderUpdater := movetaskorder.NewMoveTaskOrderUpdater( builder, - mtoserviceitem.NewMTOServiceItemCreator(planner, builder, moveservices.NewMoveRouter(), ghcrateengine.NewDomesticUnpackPricer(), ghcrateengine.NewDomesticPackPricer(), ghcrateengine.NewDomesticLinehaulPricer(), ghcrateengine.NewDomesticShorthaulPricer(), ghcrateengine.NewDomesticOriginPricer(), ghcrateengine.NewDomesticDestinationPricer(), ghcrateengine.NewFuelSurchargePricer()), - moveservices.NewMoveRouter(), setUpSignedCertificationCreatorMock(nil, nil), setUpSignedCertificationUpdaterMock(nil, nil), &ppmEstimator, + mtoserviceitem.NewMTOServiceItemCreator(planner, builder, moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()), ghcrateengine.NewDomesticUnpackPricer(), ghcrateengine.NewDomesticPackPricer(), ghcrateengine.NewDomesticLinehaulPricer(), ghcrateengine.NewDomesticShorthaulPricer(), ghcrateengine.NewDomesticOriginPricer(), ghcrateengine.NewDomesticDestinationPricer(), ghcrateengine.NewFuelSurchargePricer()), + moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()), setUpSignedCertificationCreatorMock(nil, nil), setUpSignedCertificationUpdaterMock(nil, nil), &ppmEstimator, ) shipmentCreator := shipmentorchestrator.NewShipmentCreator(creator, ppmCreator, boatCreator, mobileHomeCreator, shipmentRouter, moveTaskOrderUpdater) sitStatus := sitstatus.NewShipmentSITStatus() @@ -3662,7 +3663,7 @@ func (suite *HandlerSuite) TestCreateMTOShipmentHandlerUsingPPM() { handlerConfig := suite.HandlerConfig() builder := query.NewQueryBuilder() fetcher := fetch.NewFetcher(builder) - creator := mtoshipment.NewMTOShipmentCreatorV1(builder, fetcher, moveservices.NewMoveRouter(), addressCreator) + creator := mtoshipment.NewMTOShipmentCreatorV1(builder, fetcher, moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()), addressCreator) ppmEstimator := mocks.PPMEstimator{} boatCreator := boatshipment.NewBoatShipmentCreator() mobileHomeCreator := mobilehomeshipment.NewMobileHomeShipmentCreator() @@ -3675,8 +3676,8 @@ func (suite *HandlerSuite) TestCreateMTOShipmentHandlerUsingPPM() { ).Return(400, nil) moveTaskOrderUpdater := movetaskorder.NewMoveTaskOrderUpdater( builder, - mtoserviceitem.NewMTOServiceItemCreator(planner, builder, moveservices.NewMoveRouter(), ghcrateengine.NewDomesticUnpackPricer(), ghcrateengine.NewDomesticPackPricer(), ghcrateengine.NewDomesticLinehaulPricer(), ghcrateengine.NewDomesticShorthaulPricer(), ghcrateengine.NewDomesticOriginPricer(), ghcrateengine.NewDomesticDestinationPricer(), ghcrateengine.NewFuelSurchargePricer()), - moveservices.NewMoveRouter(), setUpSignedCertificationCreatorMock(nil, nil), setUpSignedCertificationUpdaterMock(nil, nil), &ppmEstimator, + mtoserviceitem.NewMTOServiceItemCreator(planner, builder, moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()), ghcrateengine.NewDomesticUnpackPricer(), ghcrateengine.NewDomesticPackPricer(), ghcrateengine.NewDomesticLinehaulPricer(), ghcrateengine.NewDomesticShorthaulPricer(), ghcrateengine.NewDomesticOriginPricer(), ghcrateengine.NewDomesticDestinationPricer(), ghcrateengine.NewFuelSurchargePricer()), + moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()), setUpSignedCertificationCreatorMock(nil, nil), setUpSignedCertificationUpdaterMock(nil, nil), &ppmEstimator, ) shipmentCreator := shipmentorchestrator.NewShipmentCreator(creator, ppmshipment.NewPPMShipmentCreator(&ppmEstimator, addressCreator), boatCreator, mobileHomeCreator, shipmentRouter, moveTaskOrderUpdater) handler := CreateMTOShipmentHandler{ @@ -3812,7 +3813,7 @@ func (suite *HandlerSuite) TestCreateMTOShipmentHandlerUsingPPM() { handlerConfig := suite.HandlerConfig() builder := query.NewQueryBuilder() fetcher := fetch.NewFetcher(builder) - creator := mtoshipment.NewMTOShipmentCreatorV1(builder, fetcher, moveservices.NewMoveRouter(), addressCreator) + creator := mtoshipment.NewMTOShipmentCreatorV1(builder, fetcher, moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()), addressCreator) ppmEstimator := mocks.PPMEstimator{} boatCreator := boatshipment.NewBoatShipmentCreator() mobileHomeCreator := mobilehomeshipment.NewMobileHomeShipmentCreator() @@ -3825,8 +3826,8 @@ func (suite *HandlerSuite) TestCreateMTOShipmentHandlerUsingPPM() { ).Return(400, nil) moveTaskOrderUpdater := movetaskorder.NewMoveTaskOrderUpdater( builder, - mtoserviceitem.NewMTOServiceItemCreator(planner, builder, moveservices.NewMoveRouter(), ghcrateengine.NewDomesticUnpackPricer(), ghcrateengine.NewDomesticPackPricer(), ghcrateengine.NewDomesticLinehaulPricer(), ghcrateengine.NewDomesticShorthaulPricer(), ghcrateengine.NewDomesticOriginPricer(), ghcrateengine.NewDomesticDestinationPricer(), ghcrateengine.NewFuelSurchargePricer()), - moveservices.NewMoveRouter(), setUpSignedCertificationCreatorMock(nil, nil), setUpSignedCertificationUpdaterMock(nil, nil), &ppmEstimator, + mtoserviceitem.NewMTOServiceItemCreator(planner, builder, moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()), ghcrateengine.NewDomesticUnpackPricer(), ghcrateengine.NewDomesticPackPricer(), ghcrateengine.NewDomesticLinehaulPricer(), ghcrateengine.NewDomesticShorthaulPricer(), ghcrateengine.NewDomesticOriginPricer(), ghcrateengine.NewDomesticDestinationPricer(), ghcrateengine.NewFuelSurchargePricer()), + moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()), setUpSignedCertificationCreatorMock(nil, nil), setUpSignedCertificationUpdaterMock(nil, nil), &ppmEstimator, ) shipmentCreator := shipmentorchestrator.NewShipmentCreator(creator, ppmshipment.NewPPMShipmentCreator(&ppmEstimator, addressCreator), boatCreator, mobileHomeCreator, shipmentRouter, moveTaskOrderUpdater) handler := CreateMTOShipmentHandler{ @@ -4028,7 +4029,7 @@ func (suite *HandlerSuite) TestUpdateShipmentHandler() { mock.Anything, mock.Anything, ).Return(400, nil) - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) moveWeights := moveservices.NewMoveWeights(mtoshipment.NewShipmentReweighRequester()) // Get shipment payment request recalculator service @@ -4650,7 +4651,7 @@ func (suite *HandlerSuite) TestUpdateShipmentHandler() { }) } func (suite *HandlerSuite) TestUpdateSITServiceItemCustomerExpenseHandler() { - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) builder := query.NewQueryBuilder() shipmentFetcher := mtoshipment.NewMTOShipmentFetcher() addressCreator := address.NewAddressCreator() diff --git a/pkg/handlers/ghcapi/orders_test.go b/pkg/handlers/ghcapi/orders_test.go index 93fdc901600..e40efd4ea7f 100644 --- a/pkg/handlers/ghcapi/orders_test.go +++ b/pkg/handlers/ghcapi/orders_test.go @@ -29,6 +29,7 @@ import ( mtoserviceitem "github.com/transcom/mymove/pkg/services/mto_service_item" orderservice "github.com/transcom/mymove/pkg/services/order" "github.com/transcom/mymove/pkg/services/query" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" storageTest "github.com/transcom/mymove/pkg/storage/test" "github.com/transcom/mymove/pkg/swagger/nullable" "github.com/transcom/mymove/pkg/trace" @@ -392,7 +393,7 @@ func (suite *HandlerSuite) makeUpdateOrderHandlerAmendedUploadSubtestData() (sub func (suite *HandlerSuite) TestUpdateOrderHandlerWithAmendedUploads() { queryBuilder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -725,7 +726,7 @@ func (suite *HandlerSuite) TestUpdateOrderHandler() { } moveTaskOrderUpdater := mocks.MoveTaskOrderUpdater{} - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) handler := UpdateOrderHandler{ handlerConfig, orderservice.NewOrderUpdater(moveRouter), @@ -1017,7 +1018,7 @@ func (suite *HandlerSuite) TestCounselingUpdateOrderHandler() { Body: body, } - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) handler := CounselingUpdateOrderHandler{ handlerConfig, orderservice.NewOrderUpdater(moveRouter), @@ -1265,7 +1266,7 @@ func (suite *HandlerSuite) TestUpdateAllowanceHandler() { Body: body, } - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) handler := UpdateAllowanceHandler{ handlerConfig, orderservice.NewOrderUpdater(moveRouter), @@ -1493,7 +1494,7 @@ func (suite *HandlerSuite) TestCounselingUpdateAllowanceHandler() { Body: body, } - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) handler := CounselingUpdateAllowanceHandler{ handlerConfig, orderservice.NewOrderUpdater(moveRouter), @@ -1651,7 +1652,7 @@ func (suite *HandlerSuite) TestUpdateMaxBillableWeightAsTIOHandler() { Body: body, } - router := moverouter.NewMoveRouter() + router := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) handler := UpdateMaxBillableWeightAsTIOHandler{ handlerConfig, orderservice.NewExcessWeightRiskManager(router), @@ -1814,7 +1815,7 @@ func (suite *HandlerSuite) TestUpdateBillableWeightHandler() { Body: body, } - router := moverouter.NewMoveRouter() + router := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) handler := UpdateBillableWeightHandler{ handlerConfig, orderservice.NewExcessWeightRiskManager(router), @@ -2030,7 +2031,7 @@ func (suite *HandlerSuite) TestAcknowledgeExcessWeightRiskHandler() { IfMatch: etag.GenerateEtag(move.UpdatedAt), } - router := moverouter.NewMoveRouter() + router := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) handler := AcknowledgeExcessWeightRiskHandler{ handlerConfig, orderservice.NewExcessWeightRiskManager(router), @@ -2440,7 +2441,7 @@ func (suite *HandlerSuite) TestUploadAmendedOrdersHandlerUnit() { } func (suite *HandlerSuite) TestUploadAmendedOrdersHandlerIntegration() { - orderUpdater := orderservice.NewOrderUpdater(moverouter.NewMoveRouter()) + orderUpdater := orderservice.NewOrderUpdater(moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher())) setUpRequestAndParams := func(orders models.Order) *orderop.UploadAmendedOrdersParams { endpoint := fmt.Sprintf("/orders/%v/upload_amended_orders", orders.ID.String()) diff --git a/pkg/handlers/internalapi/api.go b/pkg/handlers/internalapi/api.go index eb5386c4356..f843b5a9179 100644 --- a/pkg/handlers/internalapi/api.go +++ b/pkg/handlers/internalapi/api.go @@ -56,7 +56,7 @@ func NewInternalAPI(handlerConfig handlers.HandlerConfig) *internalops.MymoveAPI internalAPI.ServeError = handlers.ServeCustomError builder := query.NewQueryBuilder() fetcher := fetch.NewFetcher(builder) - moveRouter := move.NewMoveRouter() + moveRouter := move.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) uploadCreator := upload.NewUploadCreator(handlerConfig.FileStorer()) ppmEstimator := ppmshipment.NewEstimatePPM(handlerConfig.DTODPlanner(), &paymentrequesthelper.RequestPaymentHelper{}) ppmCloseoutFetcher := ppmcloseout.NewPPMCloseoutFetcher(handlerConfig.DTODPlanner(), &paymentrequesthelper.RequestPaymentHelper{}, ppmEstimator) diff --git a/pkg/handlers/internalapi/moves_test.go b/pkg/handlers/internalapi/moves_test.go index 40e2e9283f5..abd154aa95c 100644 --- a/pkg/handlers/internalapi/moves_test.go +++ b/pkg/handlers/internalapi/moves_test.go @@ -281,7 +281,7 @@ func (suite *HandlerSuite) TestSubmitMoveForApprovalHandler() { // When: a move is submitted handlerConfig := suite.HandlerConfig() handlerConfig.SetNotificationSender(notifications.NewStubNotificationSender("milmovelocal")) - handler := SubmitMoveHandler{handlerConfig, moverouter.NewMoveRouter()} + handler := SubmitMoveHandler{handlerConfig, moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher())} response := handler.Handle(params) // Then: expect a 200 status code @@ -332,7 +332,7 @@ func (suite *HandlerSuite) TestSubmitMoveForApprovalHandler() { // And: a move is submitted handlerConfig := suite.HandlerConfig() handlerConfig.SetNotificationSender(notifications.NewStubNotificationSender("milmovelocal")) - handler := SubmitMoveHandler{handlerConfig, moverouter.NewMoveRouter()} + handler := SubmitMoveHandler{handlerConfig, moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher())} response := handler.Handle(params) // Then: expect a 200 status code @@ -385,7 +385,7 @@ func (suite *HandlerSuite) TestSubmitMoveForServiceCounselingHandler() { // When: a move is submitted handlerConfig := suite.HandlerConfig() handlerConfig.SetNotificationSender(notifications.NewStubNotificationSender("milmovelocal")) - handler := SubmitMoveHandler{handlerConfig, moverouter.NewMoveRouter()} + handler := SubmitMoveHandler{handlerConfig, moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher())} response := handler.Handle(params) // Then: expect a 200 status code @@ -435,7 +435,7 @@ func (suite *HandlerSuite) TestSubmitAmendedOrdersHandler() { // And: a move is submitted handlerConfig := suite.HandlerConfig() - handler := SubmitAmendedOrdersHandler{handlerConfig, moverouter.NewMoveRouter()} + handler := SubmitAmendedOrdersHandler{handlerConfig, moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher())} response := handler.Handle(params) // Then: expect a 200 status code diff --git a/pkg/handlers/internalapi/mto_shipment_test.go b/pkg/handlers/internalapi/mto_shipment_test.go index 4d2b557286f..f034d5cd72f 100644 --- a/pkg/handlers/internalapi/mto_shipment_test.go +++ b/pkg/handlers/internalapi/mto_shipment_test.go @@ -34,6 +34,7 @@ import ( paymentrequest "github.com/transcom/mymove/pkg/services/payment_request" "github.com/transcom/mymove/pkg/services/ppmshipment" "github.com/transcom/mymove/pkg/services/query" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" "github.com/transcom/mymove/pkg/testdatagen" "github.com/transcom/mymove/pkg/unit" ) @@ -47,7 +48,7 @@ type mtoShipmentObjects struct { func (suite *HandlerSuite) setUpMTOShipmentObjects() *mtoShipmentObjects { builder := query.NewQueryBuilder() fetcher := fetch.NewFetcher(builder) - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) return &mtoShipmentObjects{ builder: builder, diff --git a/pkg/handlers/internalapi/office_test.go b/pkg/handlers/internalapi/office_test.go index 9370fb0c76f..f7e7101f388 100644 --- a/pkg/handlers/internalapi/office_test.go +++ b/pkg/handlers/internalapi/office_test.go @@ -12,6 +12,7 @@ import ( "github.com/transcom/mymove/pkg/models" "github.com/transcom/mymove/pkg/models/roles" moverouter "github.com/transcom/mymove/pkg/services/move" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" "github.com/transcom/mymove/pkg/testdatagen" ) @@ -31,7 +32,7 @@ func (suite *HandlerSuite) TestApproveMoveHandler() { }, nil) // Given: an office User officeUser := factory.BuildOfficeUserWithRoles(suite.DB(), nil, []roles.RoleType{roles.RoleTypeTOO}) - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) // Move is submitted and saved newSignedCertification := factory.BuildSignedCertification(nil, []factory.Customization{ @@ -73,7 +74,7 @@ func (suite *HandlerSuite) TestApproveMoveHandlerIncompleteOrders() { move := factory.BuildMove(suite.DB(), nil, nil) // Given: an office User officeUser := factory.BuildOfficeUserWithRoles(suite.DB(), nil, []roles.RoleType{roles.RoleTypeTOO}) - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) // Move is submitted and saved newSignedCertification := factory.BuildSignedCertification(nil, []factory.Customization{ @@ -116,7 +117,7 @@ func (suite *HandlerSuite) TestApproveMoveHandlerForbidden() { move := factory.BuildMove(suite.DB(), nil, nil) // Given: an non-office User user := factory.BuildServiceMember(suite.DB(), nil, nil) - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) // And: the context contains the auth values req := httptest.NewRequest("POST", "/moves/some_id/approve", nil) @@ -141,7 +142,7 @@ func (suite *HandlerSuite) TestCancelMoveHandler() { suite.Run("Successfully cancels move", func() { // Given: a set of orders, a move, and office user // Orders has service member with transportation office and phone nums - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) // Given: a set of orders, a move, user and servicemember move := factory.BuildMove(suite.DB(), nil, nil) @@ -171,7 +172,7 @@ func (suite *HandlerSuite) TestCancelMoveHandler() { suite.Run("Fails to cancel someone elses move", func() { // Given: a set of orders, a move, and office user // Orders has service member with transportation office and phone nums - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) // Given: a set of orders, a move, user and servicemember move := factory.BuildMove(suite.DB(), nil, nil) @@ -198,7 +199,7 @@ func (suite *HandlerSuite) TestCancelMoveHandler() { suite.Run("Fails to cancel submitted move", func() { // Given: a set of orders, a move, and office user // Orders has service member with transportation office and phone nums - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) // Given: a set of orders, a move, user and servicemember move := factory.BuildMove(suite.DB(), []factory.Customization{ diff --git a/pkg/handlers/internalapi/orders_test.go b/pkg/handlers/internalapi/orders_test.go index a4a74bb81e0..477ff06ff09 100644 --- a/pkg/handlers/internalapi/orders_test.go +++ b/pkg/handlers/internalapi/orders_test.go @@ -20,6 +20,7 @@ import ( "github.com/transcom/mymove/pkg/services/mocks" "github.com/transcom/mymove/pkg/services/move" orderservice "github.com/transcom/mymove/pkg/services/order" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" storageTest "github.com/transcom/mymove/pkg/storage/test" "github.com/transcom/mymove/pkg/uploader" ) @@ -487,7 +488,7 @@ func (suite *HandlerSuite) TestUploadAmendedOrdersHandlerUnit() { } func (suite *HandlerSuite) TestUploadAmendedOrdersHandlerIntegration() { - orderUpdater := orderservice.NewOrderUpdater(move.NewMoveRouter()) + orderUpdater := orderservice.NewOrderUpdater(move.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher())) setUpRequestAndParams := func(orders models.Order) *ordersop.UploadAmendedOrdersParams { endpoint := fmt.Sprintf("/orders/%v/upload_amended_orders", orders.ID.String()) diff --git a/pkg/handlers/internalapi/service_members_test.go b/pkg/handlers/internalapi/service_members_test.go index 9764091a4e6..4041faeb9f3 100644 --- a/pkg/handlers/internalapi/service_members_test.go +++ b/pkg/handlers/internalapi/service_members_test.go @@ -23,6 +23,7 @@ import ( "github.com/transcom/mymove/pkg/handlers" "github.com/transcom/mymove/pkg/models" moverouter "github.com/transcom/mymove/pkg/services/move" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" storageTest "github.com/transcom/mymove/pkg/storage/test" ) @@ -392,7 +393,7 @@ func (suite *HandlerSuite) TestPatchServiceMemberHandlerSubmittedMove() { move.Orders.OrdersTypeDetail = nil suite.MustSave(&move.Orders) - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) newSignedCertification := factory.BuildSignedCertification(nil, []factory.Customization{ { Model: move, diff --git a/pkg/handlers/primeapi/api.go b/pkg/handlers/primeapi/api.go index 40da37ee4dc..5d9b6a9331a 100644 --- a/pkg/handlers/primeapi/api.go +++ b/pkg/handlers/primeapi/api.go @@ -27,6 +27,7 @@ import ( shipmentaddressupdate "github.com/transcom/mymove/pkg/services/shipment_address_update" signedcertification "github.com/transcom/mymove/pkg/services/signed_certification" sitextension "github.com/transcom/mymove/pkg/services/sit_extension" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" "github.com/transcom/mymove/pkg/services/upload" "github.com/transcom/mymove/pkg/uploader" ) @@ -42,7 +43,7 @@ func NewPrimeAPI(handlerConfig handlers.HandlerConfig) *primeoperations.MymoveAP } primeAPI := primeoperations.NewMymoveAPI(primeSpec) queryBuilder := query.NewQueryBuilder() - moveRouter := move.NewMoveRouter() + moveRouter := move.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) addressCreator := address.NewAddressCreator() shipmentFetcher := mtoshipment.NewMTOShipmentFetcher() moveWeights := move.NewMoveWeights(mtoshipment.NewShipmentReweighRequester()) diff --git a/pkg/handlers/primeapi/move_task_order_test.go b/pkg/handlers/primeapi/move_task_order_test.go index 2bfa5abfbcc..870c4acf10c 100644 --- a/pkg/handlers/primeapi/move_task_order_test.go +++ b/pkg/handlers/primeapi/move_task_order_test.go @@ -28,6 +28,7 @@ import ( movetaskorder "github.com/transcom/mymove/pkg/services/move_task_order" mtoserviceitem "github.com/transcom/mymove/pkg/services/mto_service_item" "github.com/transcom/mymove/pkg/services/query" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" "github.com/transcom/mymove/pkg/services/upload" storageTest "github.com/transcom/mymove/pkg/storage/test" "github.com/transcom/mymove/pkg/testdatagen" @@ -1704,7 +1705,7 @@ func (suite *HandlerSuite) TestUpdateMTOPostCounselingInfo() { queryBuilder := query.NewQueryBuilder() fetcher := fetch.NewFetcher(queryBuilder) - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -1787,7 +1788,7 @@ func (suite *HandlerSuite) TestUpdateMTOPostCounselingInfo() { mtoChecker := movetaskorder.NewMoveTaskOrderChecker() queryBuilder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) fetcher := fetch.NewFetcher(queryBuilder) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", diff --git a/pkg/handlers/primeapi/mto_service_item_test.go b/pkg/handlers/primeapi/mto_service_item_test.go index c3e8b9daef6..44d6f84ef47 100644 --- a/pkg/handlers/primeapi/mto_service_item_test.go +++ b/pkg/handlers/primeapi/mto_service_item_test.go @@ -29,6 +29,7 @@ import ( mtoshipment "github.com/transcom/mymove/pkg/services/mto_shipment" "github.com/transcom/mymove/pkg/services/query" sitstatus "github.com/transcom/mymove/pkg/services/sit_status" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" "github.com/transcom/mymove/pkg/unit" ) @@ -87,7 +88,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemHandler() { suite.Run("Successful POST - Integration Test", func() { subtestData := makeSubtestData() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -145,7 +146,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemHandler() { Body: payloads.MTOServiceItem(&mtoServiceItem), } - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -283,7 +284,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemHandler() { suite.Run("POST failure - 404 - MTO is not available to Prime", func() { subtestData := makeSubtestData() mtoNotAvailable := factory.BuildMove(suite.DB(), nil, nil) - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -327,7 +328,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemHandler() { LinkOnly: true, }, }, nil) - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -478,7 +479,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemDomesticCratingHandler() { suite.Run("Successful POST - Integration Test - Domestic Crating", func() { subtestData := makeSubtestData() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -515,7 +516,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemDomesticCratingHandler() { suite.Run("Successful POST - Integration Test - Domestic Uncrating", func() { subtestData := makeSubtestData() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -638,7 +639,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemOriginSITHandler() { requestApprovalRequestedStatus := false subtestData.mtoServiceItem.RequestedApprovalsRequestedStatus = &requestApprovalRequestedStatus subtestData.mtoServiceItem.ReService.Code = models.ReServiceCodeDOPSIT - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -684,7 +685,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemOriginSITHandler() { requestApprovalRequestedStatus := false subtestData.mtoServiceItem.RequestedApprovalsRequestedStatus = &requestApprovalRequestedStatus - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -753,7 +754,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemOriginSITHandler() { }, nil) subtestData.mtoServiceItem.ReService.Code = models.ReServiceCodeDOASIT - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -837,7 +838,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemOriginSITHandlerWithDOFSITNoA requstedApprovalsRequestedStatus := false subtestData.mtoServiceItem.RequestedApprovalsRequestedStatus = &requstedApprovalsRequestedStatus subtestData.mtoServiceItem.ReService.Code = models.ReServiceCodeDOFSIT - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -947,7 +948,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemOriginSITHandlerWithDOFSITWit requestedApprovalsRequestedStatus := false subtestData.mtoServiceItem.RequestedApprovalsRequestedStatus = &requestedApprovalsRequestedStatus subtestData.mtoServiceItem.ReService.Code = models.ReServiceCodeDOFSIT - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -1120,7 +1121,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemDestSITHandler() { suite.Run("Successful POST - Integration Test", func() { subtestData := makeSubtestData() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -1194,7 +1195,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemDestSITHandler() { SITEntryDate: &sitEntryDate, Reason: models.StringPointer("lorem ipsum"), } - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -1227,7 +1228,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemDestSITHandler() { suite.Run("Failure POST - Integration Test - Missing reason", func() { subtestData := makeSubtestData() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -1283,7 +1284,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemDestSITHandler() { HTTPRequest: subtestData.params.HTTPRequest, Body: payloads.MTOServiceItem(&subtestData.mtoServiceItem), } - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -1337,7 +1338,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemDestSITHandler() { HTTPRequest: subtestData.params.HTTPRequest, Body: payloads.MTOServiceItem(&subtestData.mtoServiceItem), } - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -1373,7 +1374,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemDestSITHandler() { // SETUP // Create the payload subtestData.mtoServiceItem.ReService.Code = models.ReServiceCodeDDDSIT - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} creator := mtoserviceitem.NewMTOServiceItemCreator(planner, builder, moveRouter, ghcrateengine.NewDomesticUnpackPricer(), ghcrateengine.NewDomesticPackPricer(), ghcrateengine.NewDomesticLinehaulPricer(), ghcrateengine.NewDomesticShorthaulPricer(), ghcrateengine.NewDomesticOriginPricer(), ghcrateengine.NewDomesticDestinationPricer(), ghcrateengine.NewFuelSurchargePricer()) handler := CreateMTOServiceItemHandler{ @@ -1532,7 +1533,7 @@ func (suite *HandlerSuite) TestUpdateMTOServiceItemDDDSIT() { // Create the handler queryBuilder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) shipmentFetcher := mtoshipment.NewMTOShipmentFetcher() addressCreator := address.NewAddressCreator() planner := &routemocks.Planner{} @@ -1712,7 +1713,7 @@ func (suite *HandlerSuite) TestUpdateMTOServiceItemDOPSIT() { // Create the service item in the db for dofsit and DOPSIT // Create the handler queryBuilder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) shipmentFetcher := mtoshipment.NewMTOShipmentFetcher() addressCreator := address.NewAddressCreator() sitStatusService := sitstatus.NewShipmentSITStatus() diff --git a/pkg/handlers/primeapi/mto_shipment_test.go b/pkg/handlers/primeapi/mto_shipment_test.go index 5b602de7873..3fa3bfa8824 100644 --- a/pkg/handlers/primeapi/mto_shipment_test.go +++ b/pkg/handlers/primeapi/mto_shipment_test.go @@ -31,6 +31,7 @@ import ( mtoshipment "github.com/transcom/mymove/pkg/services/mto_shipment" paymentrequest "github.com/transcom/mymove/pkg/services/payment_request" "github.com/transcom/mymove/pkg/services/query" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" ) func (suite *HandlerSuite) TestUpdateShipmentDestinationAddressHandler() { @@ -204,7 +205,7 @@ func (suite *HandlerSuite) TestUpdateMTOShipmentStatusHandler() { mock.Anything, mock.Anything, ).Return(400, nil) - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) addressUpdater := address.NewAddressUpdater() addressCreator := address.NewAddressCreator() moveWeights := moveservices.NewMoveWeights(mtoshipment.NewShipmentReweighRequester()) @@ -408,7 +409,7 @@ func (suite *HandlerSuite) TestUpdateMTOShipmentStatusHandler() { func (suite *HandlerSuite) TestDeleteMTOShipmentHandler() { setupTestData := func() DeleteMTOShipmentHandler { builder := query.NewQueryBuilder() - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), diff --git a/pkg/handlers/primeapi/sit_extension_test.go b/pkg/handlers/primeapi/sit_extension_test.go index 2e30b6f4576..dfd6052d67a 100644 --- a/pkg/handlers/primeapi/sit_extension_test.go +++ b/pkg/handlers/primeapi/sit_extension_test.go @@ -14,6 +14,7 @@ import ( "github.com/transcom/mymove/pkg/models" moverouter "github.com/transcom/mymove/pkg/services/move" sitextensionservice "github.com/transcom/mymove/pkg/services/sit_extension" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" ) func (suite *HandlerSuite) CreateSITExtensionHandler() { @@ -30,7 +31,7 @@ func (suite *HandlerSuite) CreateSITExtensionHandler() { } // Create move router for SitExtension Createor - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) setupTestData := func() (CreateSITExtensionHandler, models.MTOShipment) { // Make an available move diff --git a/pkg/handlers/primeapiv2/api.go b/pkg/handlers/primeapiv2/api.go index dedf3e218ac..b0a6b4dfda2 100644 --- a/pkg/handlers/primeapiv2/api.go +++ b/pkg/handlers/primeapiv2/api.go @@ -23,6 +23,7 @@ import ( "github.com/transcom/mymove/pkg/services/ppmshipment" "github.com/transcom/mymove/pkg/services/query" signedcertification "github.com/transcom/mymove/pkg/services/signed_certification" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" ) // NewPrimeAPI returns the Prime API @@ -30,7 +31,7 @@ func NewPrimeAPI(handlerConfig handlers.HandlerConfig) *primev2operations.Mymove builder := query.NewQueryBuilder() fetcher := fetch.NewFetcher(builder) queryBuilder := query.NewQueryBuilder() - moveRouter := move.NewMoveRouter() + moveRouter := move.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) primeSpec, err := loads.Analyzed(primev2api.SwaggerJSON, "") if err != nil { diff --git a/pkg/handlers/primeapiv2/mto_service_item_test.go b/pkg/handlers/primeapiv2/mto_service_item_test.go index ffe960ba4f4..f18475b09b1 100644 --- a/pkg/handlers/primeapiv2/mto_service_item_test.go +++ b/pkg/handlers/primeapiv2/mto_service_item_test.go @@ -25,6 +25,7 @@ import ( movetaskorder "github.com/transcom/mymove/pkg/services/move_task_order" mtoserviceitem "github.com/transcom/mymove/pkg/services/mto_service_item" "github.com/transcom/mymove/pkg/services/query" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" ) func (suite *HandlerSuite) TestCreateMTOServiceItemHandler() { @@ -82,7 +83,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemHandler() { suite.Run("Successful POST - Integration Test", func() { subtestData := makeSubtestData() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -140,7 +141,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemHandler() { Body: payloads.MTOServiceItem(&mtoServiceItem), } - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -278,7 +279,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemHandler() { suite.Run("POST failure - 404 - MTO is not available to Prime", func() { subtestData := makeSubtestData() mtoNotAvailable := factory.BuildMove(suite.DB(), nil, nil) - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -322,7 +323,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemHandler() { LinkOnly: true, }, }, nil) - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -473,7 +474,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemDomesticCratingHandler() { suite.Run("Successful POST - Integration Test - Domestic Crating", func() { subtestData := makeSubtestData() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -510,7 +511,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemDomesticCratingHandler() { suite.Run("Successful POST - Integration Test - Domestic Uncrating", func() { subtestData := makeSubtestData() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -633,7 +634,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemOriginSITHandler() { requestApprovalRequestedStatus := false subtestData.mtoServiceItem.RequestedApprovalsRequestedStatus = &requestApprovalRequestedStatus subtestData.mtoServiceItem.ReService.Code = models.ReServiceCodeDOPSIT - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -679,7 +680,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemOriginSITHandler() { requestApprovalRequestedStatus := false subtestData.mtoServiceItem.RequestedApprovalsRequestedStatus = &requestApprovalRequestedStatus - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -748,7 +749,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemOriginSITHandler() { }, nil) subtestData.mtoServiceItem.ReService.Code = models.ReServiceCodeDOASIT - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -832,7 +833,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemOriginSITHandlerWithDOFSITNoA requstedApprovalsRequestedStatus := false subtestData.mtoServiceItem.RequestedApprovalsRequestedStatus = &requstedApprovalsRequestedStatus subtestData.mtoServiceItem.ReService.Code = models.ReServiceCodeDOFSIT - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -940,7 +941,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemOriginSITHandlerWithDOFSITWit requestedApprovalsRequestedStatus := false subtestData.mtoServiceItem.RequestedApprovalsRequestedStatus = &requestedApprovalsRequestedStatus subtestData.mtoServiceItem.ReService.Code = models.ReServiceCodeDOFSIT - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -1107,7 +1108,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemDestSITHandler() { suite.Run("Successful POST - Integration Test", func() { subtestData := makeSubtestData() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -1181,7 +1182,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemDestSITHandler() { SITEntryDate: &sitEntryDate, Reason: models.StringPointer("lorem ipsum"), } - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -1214,7 +1215,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemDestSITHandler() { suite.Run("Failure POST - Integration Test - Missing reason", func() { subtestData := makeSubtestData() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -1270,7 +1271,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemDestSITHandler() { HTTPRequest: subtestData.params.HTTPRequest, Body: payloads.MTOServiceItem(&subtestData.mtoServiceItem), } - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -1334,7 +1335,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemDestSITHandler() { HTTPRequest: subtestData.params.HTTPRequest, Body: payloads.MTOServiceItem(&subtestData.mtoServiceItem), } - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -1370,7 +1371,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemDestSITHandler() { // SETUP // Create the payload subtestData.mtoServiceItem.ReService.Code = models.ReServiceCodeDDDSIT - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} creator := mtoserviceitem.NewMTOServiceItemCreator(planner, builder, moveRouter, ghcrateengine.NewDomesticUnpackPricer(), ghcrateengine.NewDomesticPackPricer(), ghcrateengine.NewDomesticLinehaulPricer(), ghcrateengine.NewDomesticShorthaulPricer(), ghcrateengine.NewDomesticOriginPricer(), ghcrateengine.NewDomesticDestinationPricer(), ghcrateengine.NewFuelSurchargePricer()) handler := CreateMTOServiceItemHandler{ diff --git a/pkg/handlers/primeapiv2/mto_shipment_test.go b/pkg/handlers/primeapiv2/mto_shipment_test.go index 314dc9c3a5f..e6aa5916a17 100644 --- a/pkg/handlers/primeapiv2/mto_shipment_test.go +++ b/pkg/handlers/primeapiv2/mto_shipment_test.go @@ -31,6 +31,7 @@ import ( shipmentorchestrator "github.com/transcom/mymove/pkg/services/orchestrators/shipment" "github.com/transcom/mymove/pkg/services/ppmshipment" "github.com/transcom/mymove/pkg/services/query" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" "github.com/transcom/mymove/pkg/unit" ) @@ -38,7 +39,7 @@ func (suite *HandlerSuite) TestCreateMTOShipmentHandler() { builder := query.NewQueryBuilder() mtoChecker := movetaskorder.NewMoveTaskOrderChecker() - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) fetcher := fetch.NewFetcher(builder) addressCreator := address.NewAddressCreator() mtoShipmentCreator := mtoshipment.NewMTOShipmentCreatorV2(builder, fetcher, moveRouter, addressCreator) diff --git a/pkg/handlers/primeapiv3/api.go b/pkg/handlers/primeapiv3/api.go index e9c522f8d42..a61ecb63b21 100644 --- a/pkg/handlers/primeapiv3/api.go +++ b/pkg/handlers/primeapiv3/api.go @@ -23,6 +23,7 @@ import ( "github.com/transcom/mymove/pkg/services/ppmshipment" "github.com/transcom/mymove/pkg/services/query" signedcertification "github.com/transcom/mymove/pkg/services/signed_certification" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" ) // NewPrimeAPI returns the Prime API @@ -30,7 +31,7 @@ func NewPrimeAPI(handlerConfig handlers.HandlerConfig) *primev3operations.Mymove builder := query.NewQueryBuilder() fetcher := fetch.NewFetcher(builder) queryBuilder := query.NewQueryBuilder() - moveRouter := move.NewMoveRouter() + moveRouter := move.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) primeSpec, err := loads.Analyzed(primev3api.SwaggerJSON, "") if err != nil { diff --git a/pkg/handlers/primeapiv3/mto_service_item_test.go b/pkg/handlers/primeapiv3/mto_service_item_test.go index 1bc9362127c..f2253acd24b 100644 --- a/pkg/handlers/primeapiv3/mto_service_item_test.go +++ b/pkg/handlers/primeapiv3/mto_service_item_test.go @@ -25,6 +25,7 @@ import ( movetaskorder "github.com/transcom/mymove/pkg/services/move_task_order" mtoserviceitem "github.com/transcom/mymove/pkg/services/mto_service_item" "github.com/transcom/mymove/pkg/services/query" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" ) func (suite *HandlerSuite) TestCreateMTOServiceItemHandler() { @@ -89,7 +90,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemHandler() { mock.Anything, ).Return(400, nil) subtestData := makeSubtestData() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) creator := mtoserviceitem.NewMTOServiceItemCreator(planner, builder, moveRouter, ghcrateengine.NewDomesticUnpackPricer(), ghcrateengine.NewDomesticPackPricer(), ghcrateengine.NewDomesticLinehaulPricer(), ghcrateengine.NewDomesticShorthaulPricer(), ghcrateengine.NewDomesticOriginPricer(), ghcrateengine.NewDomesticDestinationPricer(), ghcrateengine.NewFuelSurchargePricer()) handler := CreateMTOServiceItemHandler{ suite.HandlerConfig(), @@ -141,7 +142,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemHandler() { Body: payloads.MTOServiceItem(&mtoServiceItem), } - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -279,7 +280,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemHandler() { suite.Run("POST failure - 404 - MTO is not available to Prime", func() { subtestData := makeSubtestData() mtoNotAvailable := factory.BuildMove(suite.DB(), nil, nil) - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -323,7 +324,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemHandler() { LinkOnly: true, }, }, nil) - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -474,7 +475,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemDomesticCratingHandler() { suite.Run("Successful POST - Integration Test - Domestic Crating", func() { subtestData := makeSubtestData() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -511,7 +512,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemDomesticCratingHandler() { suite.Run("Successful POST - Integration Test - Domestic Uncrating", func() { subtestData := makeSubtestData() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -634,7 +635,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemOriginSITHandler() { requestApprovalRequestedStatus := false subtestData.mtoServiceItem.RequestedApprovalsRequestedStatus = &requestApprovalRequestedStatus subtestData.mtoServiceItem.ReService.Code = models.ReServiceCodeDOPSIT - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -680,7 +681,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemOriginSITHandler() { requestApprovalRequestedStatus := false subtestData.mtoServiceItem.RequestedApprovalsRequestedStatus = &requestApprovalRequestedStatus - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -749,7 +750,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemOriginSITHandler() { }, nil) subtestData.mtoServiceItem.ReService.Code = models.ReServiceCodeDOASIT - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -833,7 +834,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemOriginSITHandlerWithDOFSITNoA requstedApprovalsRequestedStatus := false subtestData.mtoServiceItem.RequestedApprovalsRequestedStatus = &requstedApprovalsRequestedStatus subtestData.mtoServiceItem.ReService.Code = models.ReServiceCodeDOFSIT - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -941,7 +942,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemOriginSITHandlerWithDOFSITWit requestedApprovalsRequestedStatus := false subtestData.mtoServiceItem.RequestedApprovalsRequestedStatus = &requestedApprovalsRequestedStatus subtestData.mtoServiceItem.ReService.Code = models.ReServiceCodeDOFSIT - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -1108,7 +1109,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemDestSITHandler() { suite.Run("Successful POST - Integration Test", func() { subtestData := makeSubtestData() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -1182,7 +1183,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemDestSITHandler() { SITEntryDate: &sitEntryDate, Reason: models.StringPointer("lorem ipsum"), } - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -1215,7 +1216,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemDestSITHandler() { suite.Run("Failure POST - Integration Test - Missing reason", func() { subtestData := makeSubtestData() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -1271,7 +1272,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemDestSITHandler() { HTTPRequest: subtestData.params.HTTPRequest, Body: payloads.MTOServiceItem(&subtestData.mtoServiceItem), } - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -1335,7 +1336,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemDestSITHandler() { HTTPRequest: subtestData.params.HTTPRequest, Body: payloads.MTOServiceItem(&subtestData.mtoServiceItem), } - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -1371,7 +1372,7 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemDestSITHandler() { // SETUP // Create the payload subtestData.mtoServiceItem.ReService.Code = models.ReServiceCodeDDDSIT - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), diff --git a/pkg/handlers/primeapiv3/mto_shipment_test.go b/pkg/handlers/primeapiv3/mto_shipment_test.go index c0443c77eb2..a46c0f0a90c 100644 --- a/pkg/handlers/primeapiv3/mto_shipment_test.go +++ b/pkg/handlers/primeapiv3/mto_shipment_test.go @@ -36,6 +36,7 @@ import ( paymentrequest "github.com/transcom/mymove/pkg/services/payment_request" "github.com/transcom/mymove/pkg/services/ppmshipment" "github.com/transcom/mymove/pkg/services/query" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" "github.com/transcom/mymove/pkg/unit" ) @@ -43,7 +44,7 @@ func (suite *HandlerSuite) TestCreateMTOShipmentHandler() { builder := query.NewQueryBuilder() mtoChecker := movetaskorder.NewMoveTaskOrderChecker() - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) fetcher := fetch.NewFetcher(builder) addressCreator := address.NewAddressCreator() addressUpdater := address.NewAddressUpdater() diff --git a/pkg/handlers/supportapi/api.go b/pkg/handlers/supportapi/api.go index ea5aaf3ae8b..fa858b2140c 100644 --- a/pkg/handlers/supportapi/api.go +++ b/pkg/handlers/supportapi/api.go @@ -26,12 +26,13 @@ import ( signedcertification "github.com/transcom/mymove/pkg/services/signed_certification" internalmovetaskorder "github.com/transcom/mymove/pkg/services/support/move_task_order" transportationaccountingcode "github.com/transcom/mymove/pkg/services/transportation_accounting_code" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" ) // NewSupportAPIHandler returns a handler for the Prime API func NewSupportAPIHandler(handlerConfig handlers.HandlerConfig) http.Handler { queryBuilder := query.NewQueryBuilder() - moveRouter := move.NewMoveRouter() + moveRouter := move.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) shipmentFetcher := mtoshipment.NewMTOShipmentFetcher() addressCreator := address.NewAddressCreator() supportSpec, err := loads.Analyzed(supportapi.SwaggerJSON, "") diff --git a/pkg/handlers/supportapi/move_task_order_test.go b/pkg/handlers/supportapi/move_task_order_test.go index f10fde1438e..ebbfa9ea193 100644 --- a/pkg/handlers/supportapi/move_task_order_test.go +++ b/pkg/handlers/supportapi/move_task_order_test.go @@ -26,6 +26,7 @@ import ( "github.com/transcom/mymove/pkg/services/query" supportMocks "github.com/transcom/mymove/pkg/services/support/mocks" internalmovetaskorder "github.com/transcom/mymove/pkg/services/support/move_task_order" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" ) func (suite *HandlerSuite) TestListMTOsHandler() { @@ -167,7 +168,7 @@ func (suite *HandlerSuite) TestMakeMoveAvailableHandlerIntegrationSuccess() { } handlerConfig := suite.HandlerConfig() queryBuilder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -382,7 +383,7 @@ func (suite *HandlerSuite) TestCreateMoveTaskOrderRequestHandler() { IfMatch: createdMTO.ETag, } queryBuilder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), diff --git a/pkg/handlers/supportapi/mto_service_item_test.go b/pkg/handlers/supportapi/mto_service_item_test.go index 44a56716688..ad6177e8ea0 100644 --- a/pkg/handlers/supportapi/mto_service_item_test.go +++ b/pkg/handlers/supportapi/mto_service_item_test.go @@ -26,6 +26,7 @@ import ( mtoserviceitem "github.com/transcom/mymove/pkg/services/mto_service_item" mtoshipment "github.com/transcom/mymove/pkg/services/mto_shipment" "github.com/transcom/mymove/pkg/services/query" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" ) // Create a service item on a Move with Approvals Requested status @@ -75,7 +76,7 @@ func (suite *HandlerSuite) TestUpdateMTOServiceItemStatusHandlerApproveSuccess() handlerConfig := suite.HandlerConfig() queryBuilder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) shipmentFetcher := mtoshipment.NewMTOShipmentFetcher() addressCreator := address.NewAddressCreator() planner := &routemocks.Planner{} @@ -131,7 +132,7 @@ func (suite *HandlerSuite) TestUpdateMTOServiceItemStatusHandlerRejectSuccess() handlerConfig := suite.HandlerConfig() queryBuilder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) shipmentFetcher := mtoshipment.NewMTOShipmentFetcher() addressCreator := address.NewAddressCreator() planner := &routemocks.Planner{} @@ -187,7 +188,7 @@ func (suite *HandlerSuite) TestUpdateMTOServiceItemStatusHandlerRejectionFailedN handlerConfig := suite.HandlerConfig() queryBuilder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) shipmentFetcher := mtoshipment.NewMTOShipmentFetcher() addressCreator := address.NewAddressCreator() planner := &routemocks.Planner{} diff --git a/pkg/handlers/supportapi/mto_shipment_test.go b/pkg/handlers/supportapi/mto_shipment_test.go index c1a9bb7018b..c111449d875 100644 --- a/pkg/handlers/supportapi/mto_shipment_test.go +++ b/pkg/handlers/supportapi/mto_shipment_test.go @@ -23,6 +23,7 @@ import ( mtoserviceitem "github.com/transcom/mymove/pkg/services/mto_service_item" mtoshipment "github.com/transcom/mymove/pkg/services/mto_shipment" "github.com/transcom/mymove/pkg/services/query" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" ) func (suite *HandlerSuite) TestUpdateMTOShipmentStatusHandler() { @@ -91,7 +92,7 @@ func (suite *HandlerSuite) TestUpdateMTOShipmentStatusHandler() { // Used for all tests except 500 error: queryBuilder := query.NewQueryBuilder() fetcher := fetch.NewFetcher(queryBuilder) - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), diff --git a/pkg/services/mocks/TransportationOfficesFetcher.go b/pkg/services/mocks/TransportationOfficesFetcher.go index eed32753594..754823af361 100644 --- a/pkg/services/mocks/TransportationOfficesFetcher.go +++ b/pkg/services/mocks/TransportationOfficesFetcher.go @@ -136,6 +136,12 @@ func (_m *TransportationOfficesFetcher) GetTransportationOffices(appCtx appconte return r0, r1 } +func (_m *TransportationOfficesFetcher) FindClosestCounselingOffice(appCtx appcontext.AppContext, dutyLocationID uuid.UUID) (models.TransportationOffice, error) { + _m.GetCounselingOffices(appCtx, dutyLocationID) + //TODO: Fix + return models.TransportationOffice{}, nil +} + // NewTransportationOfficesFetcher creates a new instance of TransportationOfficesFetcher. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. // The first argument is typically a *testing.T value. func NewTransportationOfficesFetcher(t interface { diff --git a/pkg/services/move/move_router.go b/pkg/services/move/move_router.go index d06994bed41..9e3f35a7483 100644 --- a/pkg/services/move/move_router.go +++ b/pkg/services/move/move_router.go @@ -17,11 +17,14 @@ import ( ) type moveRouter struct { + transportationOfficesFetcher services.TransportationOfficesFetcher } // NewMoveRouter creates a new moveRouter service -func NewMoveRouter() services.MoveRouter { - return &moveRouter{} +func NewMoveRouter(transportationOfficeFetcher services.TransportationOfficesFetcher) services.MoveRouter { + return &moveRouter{ + transportationOfficesFetcher: transportationOfficeFetcher, + } } // Submit is called when the customer submits amended orders or submits their move. It determines whether @@ -188,16 +191,6 @@ func (router moveRouter) sendToServiceCounselor(appCtx appcontext.AppContext, mo } } - // if move.IsPPMOnly() && !orders.OriginDutyLocation.ProvidesServicesCounseling { - // originLocationID := uuid.FromStringOrNil(orders.OriginDutyLocationID.String()) - - // officeList, err := ShowCounselingOfficesHandler.TransportationOfficesFetcher.GetCounselingOffices(appCtx, originLocationID) - // if err != nil { - - // } - - // } - if move.Status == models.MoveStatusNeedsServiceCounseling { return nil } @@ -228,6 +221,15 @@ func (router moveRouter) sendToServiceCounselor(appCtx appcontext.AppContext, mo move.MTOShipments[i].PPMShipment.Status = models.PPMShipmentStatusSubmitted // actual expense reimbursement is always true for civilian moves move.MTOShipments[i].PPMShipment.IsActualExpenseReimbursement = models.BoolPointer(isCivilian) + if move.IsPPMOnly() && !orders.OriginDutyLocation.ProvidesServicesCounseling { + closestCounselingOffice, err := router.transportationOfficesFetcher.FindClosestCounselingOffice(appCtx, *move.Orders.OriginDutyLocationID) + if err != nil { + msg := "Failure setting PPM counseling office to closest service counseling office" + appCtx.Logger().Error(msg, zap.Error(err)) + return apperror.NewQueryError("Closest Counseling Office", err, "Failed to find counseling office that provides counseling") + } + move.CounselingOffice = &closestCounselingOffice + } if verrs, err := appCtx.DB().ValidateAndUpdate(&move.MTOShipments[i]); verrs.HasAny() || err != nil { msg := "failure saving shipment when routing move submission" diff --git a/pkg/services/move/move_router_test.go b/pkg/services/move/move_router_test.go index 7b1e21f0d2f..89d6d6f351d 100644 --- a/pkg/services/move/move_router_test.go +++ b/pkg/services/move/move_router_test.go @@ -9,13 +9,14 @@ import ( "github.com/transcom/mymove/pkg/apperror" "github.com/transcom/mymove/pkg/factory" "github.com/transcom/mymove/pkg/models" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" storageTest "github.com/transcom/mymove/pkg/storage/test" "github.com/transcom/mymove/pkg/testdatagen" "github.com/transcom/mymove/pkg/uploader" ) func (suite *MoveServiceSuite) TestMoveApproval() { - moveRouter := NewMoveRouter() + moveRouter := NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) suite.Run("from valid statuses", func() { move := factory.BuildMove(nil, nil, nil) @@ -61,7 +62,7 @@ func (suite *MoveServiceSuite) TestMoveApproval() { } func (suite *MoveServiceSuite) TestMoveSubmission() { - moveRouter := NewMoveRouter() + moveRouter := NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) suite.Run("returns error when needsServicesCounseling cannot find move", func() { // Under test: MoveRouter.Submit @@ -992,7 +993,7 @@ func (suite *MoveServiceSuite) TestMoveSubmission() { } func (suite *MoveServiceSuite) TestMoveCancellation() { - moveRouter := NewMoveRouter() + moveRouter := NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) suite.Run("Cancel move with no shipments", func() { move := factory.BuildMove(suite.DB(), nil, nil) @@ -1056,7 +1057,7 @@ func (suite *MoveServiceSuite) TestMoveCancellation() { } func (suite *MoveServiceSuite) TestSendToOfficeUser() { - moveRouter := NewMoveRouter() + moveRouter := NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) suite.Run("from valid statuses", func() { move := factory.BuildMove(suite.DB(), nil, nil) @@ -1114,7 +1115,7 @@ func (suite *MoveServiceSuite) TestSendToOfficeUser() { } func (suite *MoveServiceSuite) TestApproveOrRequestApproval() { - moveRouter := NewMoveRouter() + moveRouter := NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) suite.Run("approves the move if TOO no longer has actions to perform", func() { move := factory.BuildApprovalsRequestedMove(suite.DB(), nil, nil) @@ -1273,7 +1274,7 @@ func (suite *MoveServiceSuite) TestApproveOrRequestApproval() { } func (suite *MoveServiceSuite) TestCompleteServiceCounseling() { - moveRouter := NewMoveRouter() + moveRouter := NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) suite.Run("status changed to service counseling completed", func() { move := factory.BuildStubbedMoveWithStatus(models.MoveStatusNeedsServiceCounseling) diff --git a/pkg/services/move_history/move_history_fetcher_test.go b/pkg/services/move_history/move_history_fetcher_test.go index f84af138e33..11e26fdd421 100644 --- a/pkg/services/move_history/move_history_fetcher_test.go +++ b/pkg/services/move_history/move_history_fetcher_test.go @@ -24,6 +24,7 @@ import ( mtoshipment "github.com/transcom/mymove/pkg/services/mto_shipment" "github.com/transcom/mymove/pkg/services/query" "github.com/transcom/mymove/pkg/services/reweigh" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" "github.com/transcom/mymove/pkg/testdatagen" "github.com/transcom/mymove/pkg/unit" ) @@ -365,7 +366,7 @@ func (suite *MoveHistoryServiceSuite) TestMoveHistoryFetcherScenarios() { suite.Run("has audit history records for service item", func() { builder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) shipmentFetcher := mtoshipment.NewMTOShipmentFetcher() addressCreator := address.NewAddressCreator() planner := &routemocks.Planner{} @@ -542,7 +543,7 @@ func (suite *MoveHistoryServiceSuite) TestMoveHistoryFetcherScenarios() { }, }, nil) builder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -615,7 +616,7 @@ func (suite *MoveHistoryServiceSuite) TestMoveHistoryFetcherScenarios() { }, }, nil) builder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), diff --git a/pkg/services/move_task_order/move_task_order_updater_test.go b/pkg/services/move_task_order/move_task_order_updater_test.go index bd1e001e494..9c82b65fc51 100644 --- a/pkg/services/move_task_order/move_task_order_updater_test.go +++ b/pkg/services/move_task_order/move_task_order_updater_test.go @@ -21,11 +21,12 @@ import ( mtoserviceitem "github.com/transcom/mymove/pkg/services/mto_service_item" "github.com/transcom/mymove/pkg/services/query" signedcertification "github.com/transcom/mymove/pkg/services/signed_certification" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" "github.com/transcom/mymove/pkg/testdatagen" ) func (suite *MoveTaskOrderServiceSuite) TestMoveTaskOrderUpdater_UpdateStatusServiceCounselingCompleted() { - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) queryBuilder := query.NewQueryBuilder() planner := &routemocks.Planner{} ppmEstimator := &mocks.PPMEstimator{} @@ -339,7 +340,7 @@ func (suite *MoveTaskOrderServiceSuite) TestMoveTaskOrderUpdater_UpdateStatusSer func (suite *MoveTaskOrderServiceSuite) TestMoveTaskOrderUpdater_UpdatePostCounselingInfo() { queryBuilder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} ppmEstimator := &mocks.PPMEstimator{} planner.On("ZipTransitDistance", @@ -506,7 +507,7 @@ func (suite *MoveTaskOrderServiceSuite) TestMoveTaskOrderUpdater_ShowHide() { // Set up the necessary updater objects: queryBuilder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} ppmEstimator := &mocks.PPMEstimator{} planner.On("ZipTransitDistance", @@ -713,7 +714,7 @@ func (suite *MoveTaskOrderServiceSuite) TestMoveTaskOrderUpdater_MakeAvailableTo suite.Run("Service item creator is not called if move fails to get approved", func() { mockserviceItemCreator := &mocks.MTOServiceItemCreator{} queryBuilder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) mtoUpdater := mt.NewMoveTaskOrderUpdater(queryBuilder, mockserviceItemCreator, moveRouter, setUpSignedCertificationCreatorMock(nil, nil), setUpSignedCertificationUpdaterMock(nil, nil), ppmEstimator) // Create move in DRAFT status, which should fail to get approved move := factory.BuildMove(suite.DB(), nil, nil) @@ -733,7 +734,7 @@ func (suite *MoveTaskOrderServiceSuite) TestMoveTaskOrderUpdater_MakeAvailableTo suite.Run("When ETag is stale", func() { mockserviceItemCreator := &mocks.MTOServiceItemCreator{} queryBuilder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) mtoUpdater := mt.NewMoveTaskOrderUpdater(queryBuilder, mockserviceItemCreator, moveRouter, setUpSignedCertificationCreatorMock(nil, nil), setUpSignedCertificationUpdaterMock(nil, nil), ppmEstimator) move := factory.BuildSubmittedMove(suite.DB(), nil, nil) @@ -748,7 +749,7 @@ func (suite *MoveTaskOrderServiceSuite) TestMoveTaskOrderUpdater_MakeAvailableTo suite.Run("Makes move available to Prime and creates Move management and Service counseling service items when both are specified", func() { queryBuilder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -786,7 +787,7 @@ func (suite *MoveTaskOrderServiceSuite) TestMoveTaskOrderUpdater_MakeAvailableTo suite.Run("Makes move available to Prime and only creates Move management when it's the only one specified", func() { queryBuilder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -820,7 +821,7 @@ func (suite *MoveTaskOrderServiceSuite) TestMoveTaskOrderUpdater_MakeAvailableTo suite.Run("Makes move available to Prime and only creates CS service item when it's the only one specified", func() { queryBuilder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} serviceItemCreator := mtoserviceitem.NewMTOServiceItemCreator(planner, queryBuilder, moveRouter, ghcrateengine.NewDomesticUnpackPricer(), ghcrateengine.NewDomesticPackPricer(), ghcrateengine.NewDomesticLinehaulPricer(), ghcrateengine.NewDomesticShorthaulPricer(), ghcrateengine.NewDomesticOriginPricer(), ghcrateengine.NewDomesticDestinationPricer(), ghcrateengine.NewFuelSurchargePricer()) mtoUpdater := mt.NewMoveTaskOrderUpdater(queryBuilder, serviceItemCreator, moveRouter, setUpSignedCertificationCreatorMock(nil, nil), setUpSignedCertificationUpdaterMock(nil, nil), ppmEstimator) @@ -849,7 +850,7 @@ func (suite *MoveTaskOrderServiceSuite) TestMoveTaskOrderUpdater_MakeAvailableTo suite.Run("Does not create service items if neither CS nor MS are requested", func() { queryBuilder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) mockserviceItemCreator := &mocks.MTOServiceItemCreator{} mtoUpdater := mt.NewMoveTaskOrderUpdater(queryBuilder, mockserviceItemCreator, moveRouter, setUpSignedCertificationCreatorMock(nil, nil), setUpSignedCertificationUpdaterMock(nil, nil), ppmEstimator) @@ -873,7 +874,7 @@ func (suite *MoveTaskOrderServiceSuite) TestMoveTaskOrderUpdater_MakeAvailableTo suite.Run("Does not make move available to prime if Order is missing required fields", func() { mockserviceItemCreator := &mocks.MTOServiceItemCreator{} queryBuilder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) mtoUpdater := mt.NewMoveTaskOrderUpdater(queryBuilder, mockserviceItemCreator, moveRouter, setUpSignedCertificationCreatorMock(nil, nil), setUpSignedCertificationUpdaterMock(nil, nil), ppmEstimator) orderWithoutDefaults := factory.BuildOrderWithoutDefaults(suite.DB(), nil, nil) @@ -928,7 +929,7 @@ func (suite *MoveTaskOrderServiceSuite) TestMoveTaskOrderUpdater_BillableWeights suite.Run("Service item creator is not called if move fails to get approved", func() { mockserviceItemCreator := &mocks.MTOServiceItemCreator{} queryBuilder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) mtoUpdater := mt.NewMoveTaskOrderUpdater(queryBuilder, mockserviceItemCreator, moveRouter, setUpSignedCertificationCreatorMock(nil, nil), setUpSignedCertificationUpdaterMock(nil, nil), ppmEstimator) move := factory.BuildMove(suite.DB(), nil, nil) eTag := etag.GenerateEtag(move.UpdatedAt) @@ -942,7 +943,7 @@ func (suite *MoveTaskOrderServiceSuite) TestMoveTaskOrderUpdater_BillableWeights suite.Run("When ETag is stale", func() { mockserviceItemCreator := &mocks.MTOServiceItemCreator{} queryBuilder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) mtoUpdater := mt.NewMoveTaskOrderUpdater(queryBuilder, mockserviceItemCreator, moveRouter, setUpSignedCertificationCreatorMock(nil, nil), setUpSignedCertificationUpdaterMock(nil, nil), ppmEstimator) move := factory.BuildSubmittedMove(suite.DB(), nil, nil) @@ -959,7 +960,7 @@ func (suite *MoveTaskOrderServiceSuite) TestMoveTaskOrderUpdater_TIORemarks() { mockserviceItemCreator := &mocks.MTOServiceItemCreator{} ppmEstimator := &mocks.PPMEstimator{} queryBuilder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) setUpSignedCertificationCreatorMock := func(returnValue ...interface{}) services.SignedCertificationCreator { mockCreator := &mocks.SignedCertificationCreator{} @@ -1034,7 +1035,7 @@ func (suite *MoveTaskOrderServiceSuite) TestMoveTaskOrderUpdater_UpdatePPMType() // Set up the necessary updater objects: queryBuilder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} ppmEstimator := &mocks.PPMEstimator{} planner.On("ZipTransitDistance", diff --git a/pkg/services/mto_service_item/mto_service_item_creator_test.go b/pkg/services/mto_service_item/mto_service_item_creator_test.go index e9799db0278..8f160a508bf 100644 --- a/pkg/services/mto_service_item/mto_service_item_creator_test.go +++ b/pkg/services/mto_service_item/mto_service_item_creator_test.go @@ -27,6 +27,7 @@ import ( "github.com/transcom/mymove/pkg/services/ghcrateengine" moverouter "github.com/transcom/mymove/pkg/services/move" "github.com/transcom/mymove/pkg/services/query" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" "github.com/transcom/mymove/pkg/testdatagen" "github.com/transcom/mymove/pkg/unit" ) @@ -187,7 +188,7 @@ func (suite *MTOServiceItemServiceSuite) TestCreateMTOServiceItemWithInvalidMove // Error because we cannot create service items before move is approved. builder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &mocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -215,7 +216,7 @@ func (suite *MTOServiceItemServiceSuite) TestCreateMTOServiceItemWithInvalidMove func (suite *MTOServiceItemServiceSuite) TestCreateMTOServiceItem() { builder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &mocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -1025,7 +1026,7 @@ func (suite *MTOServiceItemServiceSuite) TestCreateOriginSITServiceItem() { } builder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &mocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -1074,7 +1075,7 @@ func (suite *MTOServiceItemServiceSuite) TestCreateOriginSITServiceItem() { } builder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &mocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -1148,7 +1149,7 @@ func (suite *MTOServiceItemServiceSuite) TestCreateOriginSITServiceItem() { } builder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &mocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -1274,7 +1275,7 @@ func (suite *MTOServiceItemServiceSuite) TestCreateOriginSITServiceItem() { } builder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &mocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -1308,7 +1309,7 @@ func (suite *MTOServiceItemServiceSuite) TestCreateOriginSITServiceItem() { } builder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &mocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -1341,7 +1342,7 @@ func (suite *MTOServiceItemServiceSuite) TestCreateOriginSITServiceItem() { } builder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &mocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -1416,7 +1417,7 @@ func (suite *MTOServiceItemServiceSuite) TestCreateOriginSITServiceItemFailToCre Reason: &reason, } builder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &mocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -1450,7 +1451,7 @@ func (suite *MTOServiceItemServiceSuite) TestCreateDestSITServiceItem() { }, }, nil) builder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &mocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -1749,7 +1750,7 @@ func (suite *MTOServiceItemServiceSuite) TestCreateDestSITServiceItem() { } builder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &mocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), diff --git a/pkg/services/mto_service_item/mto_service_item_updater_test.go b/pkg/services/mto_service_item/mto_service_item_updater_test.go index f2c6889ca98..094f7c32870 100644 --- a/pkg/services/mto_service_item/mto_service_item_updater_test.go +++ b/pkg/services/mto_service_item/mto_service_item_updater_test.go @@ -28,6 +28,7 @@ import ( mtoshipment "github.com/transcom/mymove/pkg/services/mto_shipment" "github.com/transcom/mymove/pkg/services/query" sitstatus "github.com/transcom/mymove/pkg/services/sit_status" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" storageTest "github.com/transcom/mymove/pkg/storage/test" "github.com/transcom/mymove/pkg/testdatagen" "github.com/transcom/mymove/pkg/unit" @@ -37,7 +38,7 @@ import ( func (suite *MTOServiceItemServiceSuite) TestMTOServiceItemUpdater() { builder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) shipmentFetcher := mtoshipment.NewMTOShipmentFetcher() addressCreator := address.NewAddressCreator() sitStatusService := sitstatus.NewShipmentSITStatus() @@ -1748,7 +1749,7 @@ func (suite *MTOServiceItemServiceSuite) createServiceItemForMoveWithUnacknowled func (suite *MTOServiceItemServiceSuite) TestUpdateMTOServiceItemStatus() { builder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) shipmentFetcher := mtoshipment.NewMTOShipmentFetcher() addressCreator := address.NewAddressCreator() planner := &mocks.Planner{} diff --git a/pkg/services/mto_shipment/mto_shipment_creator_test.go b/pkg/services/mto_shipment/mto_shipment_creator_test.go index 82e057c61f6..91a1074e37c 100644 --- a/pkg/services/mto_shipment/mto_shipment_creator_test.go +++ b/pkg/services/mto_shipment/mto_shipment_creator_test.go @@ -14,6 +14,7 @@ import ( "github.com/transcom/mymove/pkg/services/fetch" moverouter "github.com/transcom/mymove/pkg/services/move" "github.com/transcom/mymove/pkg/services/query" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" "github.com/transcom/mymove/pkg/testdatagen" "github.com/transcom/mymove/pkg/unit" ) @@ -29,7 +30,7 @@ func (suite *MTOShipmentServiceSuite) createSubtestData(customs []factory.Custom subtestData.move = factory.BuildMove(suite.DB(), customs, nil) builder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) fetcher := fetch.NewFetcher(builder) addressCreator := address.NewAddressCreator() @@ -45,7 +46,7 @@ func (suite *MTOShipmentServiceSuite) createSubtestDataV2(customs []factory.Cust subtestData.move = factory.BuildMove(suite.DB(), customs, nil) builder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) fetcher := fetch.NewFetcher(builder) addressCreator := address.NewAddressCreator() diff --git a/pkg/services/mto_shipment/mto_shipment_updater_test.go b/pkg/services/mto_shipment/mto_shipment_updater_test.go index dfabece3112..67aa1beab14 100644 --- a/pkg/services/mto_shipment/mto_shipment_updater_test.go +++ b/pkg/services/mto_shipment/mto_shipment_updater_test.go @@ -25,6 +25,7 @@ import ( moveservices "github.com/transcom/mymove/pkg/services/move" mtoserviceitem "github.com/transcom/mymove/pkg/services/mto_service_item" "github.com/transcom/mymove/pkg/services/query" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" "github.com/transcom/mymove/pkg/testdatagen" "github.com/transcom/mymove/pkg/unit" ) @@ -51,7 +52,7 @@ func (suite *MTOShipmentServiceSuite) TestMTOShipmentUpdater() { mock.Anything, mock.Anything, ).Return(1000, nil) - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) moveWeights := moveservices.NewMoveWeights(NewShipmentReweighRequester()) mockShipmentRecalculator := mockservices.PaymentRequestShipmentRecalculator{} mockShipmentRecalculator.On("ShipmentRecalculatePaymentRequest", @@ -1787,7 +1788,7 @@ func (suite *MTOShipmentServiceSuite) TestUpdateMTOShipmentStatus() { } builder := query.NewQueryBuilder() - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &mocks.Planner{} var TransitDistancePickupArg string var TransitDistanceDestinationArg string @@ -2401,7 +2402,7 @@ func (suite *MTOShipmentServiceSuite) TestMTOShipmentsMTOAvailableToPrime() { builder := query.NewQueryBuilder() fetcher := fetch.NewFetcher(builder) planner := &mocks.Planner{} - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) moveWeights := moveservices.NewMoveWeights(NewShipmentReweighRequester()) mockShipmentRecalculator := mockservices.PaymentRequestShipmentRecalculator{} mockShipmentRecalculator.On("ShipmentRecalculatePaymentRequest", @@ -2470,7 +2471,7 @@ func (suite *MTOShipmentServiceSuite) TestUpdateShipmentEstimatedWeightMoveExces builder := query.NewQueryBuilder() fetcher := fetch.NewFetcher(builder) planner := &mocks.Planner{} - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) moveWeights := moveservices.NewMoveWeights(NewShipmentReweighRequester()) mockShipmentRecalculator := mockservices.PaymentRequestShipmentRecalculator{} mockShipmentRecalculator.On("ShipmentRecalculatePaymentRequest", @@ -2653,7 +2654,7 @@ func (suite *MTOShipmentServiceSuite) TestUpdateShipmentActualWeightAutoReweigh( builder := query.NewQueryBuilder() fetcher := fetch.NewFetcher(builder) planner := &mocks.Planner{} - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) moveWeights := moveservices.NewMoveWeights(NewShipmentReweighRequester()) mockShipmentRecalculator := mockservices.PaymentRequestShipmentRecalculator{} mockShipmentRecalculator.On("ShipmentRecalculatePaymentRequest", @@ -2792,7 +2793,7 @@ func (suite *MTOShipmentServiceSuite) TestUpdateShipmentNullableFields() { builder := query.NewQueryBuilder() fetcher := fetch.NewFetcher(builder) planner := &mocks.Planner{} - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) mockShipmentRecalculator := mockservices.PaymentRequestShipmentRecalculator{} mockShipmentRecalculator.On("ShipmentRecalculatePaymentRequest", mock.AnythingOfType("*appcontext.appContext"), @@ -2943,7 +2944,7 @@ func (suite *MTOShipmentServiceSuite) TestUpdateStatusServiceItems() { } builder := query.NewQueryBuilder() - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &mocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), diff --git a/pkg/services/mto_shipment/shipment_approver_test.go b/pkg/services/mto_shipment/shipment_approver_test.go index 943cd4edb72..f8cca9b5477 100644 --- a/pkg/services/mto_shipment/shipment_approver_test.go +++ b/pkg/services/mto_shipment/shipment_approver_test.go @@ -22,6 +22,7 @@ import ( moverouter "github.com/transcom/mymove/pkg/services/move" mtoserviceitem "github.com/transcom/mymove/pkg/services/mto_service_item" "github.com/transcom/mymove/pkg/services/query" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" "github.com/transcom/mymove/pkg/testdatagen" "github.com/transcom/mymove/pkg/unit" ) @@ -85,7 +86,7 @@ func (suite *MTOShipmentServiceSuite) createApproveShipmentSubtestData() (subtes router := NewShipmentRouter() builder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &mocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), diff --git a/pkg/services/mto_shipment/shipment_cancellation_requester_test.go b/pkg/services/mto_shipment/shipment_cancellation_requester_test.go index 0d2b4c33310..8c9a9ea1994 100644 --- a/pkg/services/mto_shipment/shipment_cancellation_requester_test.go +++ b/pkg/services/mto_shipment/shipment_cancellation_requester_test.go @@ -11,11 +11,12 @@ import ( "github.com/transcom/mymove/pkg/factory" "github.com/transcom/mymove/pkg/models" moveservices "github.com/transcom/mymove/pkg/services/move" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" ) func (suite *MTOShipmentServiceSuite) TestRequestShipmentCancellation() { router := NewShipmentRouter() - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) requester := NewShipmentCancellationRequester(router, moveRouter) suite.Run("If the shipment diversion is requested successfully, it should update the shipment status in the DB", func() { @@ -108,7 +109,7 @@ func (suite *MTOShipmentServiceSuite) TestRequestShipmentCancellation() { suite.Run("It calls RequestCancellation on the ShipmentRouter", func() { shipmentRouter := NewShipmentRouter() - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) requester := NewShipmentCancellationRequester(shipmentRouter, moveRouter) // valid pickupdate is anytime after the request to cancel date actualPickupDate := time.Now().AddDate(0, 0, 1) @@ -143,7 +144,7 @@ func (suite *MTOShipmentServiceSuite) TestRequestShipmentCancellation() { suite.Run("It calls RequestCancellation on shipment with invalid actualPickupDate", func() { shipmentRouter := NewShipmentRouter() - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) requester := NewShipmentCancellationRequester(shipmentRouter, moveRouter) actualPickupDate := time.Now() shipment := factory.BuildMTOShipmentMinimal(suite.DB(), []factory.Customization{ diff --git a/pkg/services/mto_shipment/shipment_deleter_test.go b/pkg/services/mto_shipment/shipment_deleter_test.go index 1e0ca2796f6..204ff1d157c 100644 --- a/pkg/services/mto_shipment/shipment_deleter_test.go +++ b/pkg/services/mto_shipment/shipment_deleter_test.go @@ -19,11 +19,12 @@ import ( movetaskorder "github.com/transcom/mymove/pkg/services/move_task_order" mtoserviceitem "github.com/transcom/mymove/pkg/services/mto_service_item" "github.com/transcom/mymove/pkg/services/query" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" ) func (suite *MTOShipmentServiceSuite) TestShipmentDeleter() { builder := query.NewQueryBuilder() - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -77,7 +78,7 @@ func (suite *MTOShipmentServiceSuite) TestShipmentDeleter() { }) suite.Run("Returns an error when the Move is neither in Draft nor in NeedsServiceCounseling status", func() { - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) shipmentDeleter := NewShipmentDeleter(moveTaskOrderUpdater, moveRouter) shipment := factory.BuildMTOShipmentMinimal(suite.DB(), nil, nil) move := shipment.MoveTaskOrder @@ -96,7 +97,7 @@ func (suite *MTOShipmentServiceSuite) TestShipmentDeleter() { }) suite.Run("Soft deletes the shipment when it is found", func() { - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) shipmentDeleter := NewShipmentDeleter(moveTaskOrderUpdater, moveRouter) shipment := factory.BuildMTOShipmentMinimal(suite.DB(), nil, nil) @@ -138,7 +139,7 @@ func (suite *MTOShipmentServiceSuite) TestShipmentDeleter() { }) suite.Run("Soft deletes the shipment when it is found and check if shipment_seq_num changed", func() { - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) move := factory.BuildMove(suite.DB(), nil, nil) shipmentDeleter := NewShipmentDeleter(moveTaskOrderUpdater, moveRouter) shipment := factory.BuildMTOShipmentMinimal(suite.DB(), []factory.Customization{ @@ -201,7 +202,7 @@ func (suite *MTOShipmentServiceSuite) TestShipmentDeleter() { }) suite.Run("Returns not found error when the shipment is already deleted", func() { - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) shipmentDeleter := NewShipmentDeleter(moveTaskOrderUpdater, moveRouter) shipment := factory.BuildMTOShipmentMinimal(suite.DB(), nil, nil) session := suite.AppContextWithSessionForTest(&auth.Session{ @@ -218,7 +219,7 @@ func (suite *MTOShipmentServiceSuite) TestShipmentDeleter() { }) suite.Run("Soft deletes the associated PPM shipment", func() { - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) shipmentDeleter := NewShipmentDeleter(moveTaskOrderUpdater, moveRouter) ppmShipment := factory.BuildPPMShipment(suite.DB(), []factory.Customization{ { @@ -253,7 +254,7 @@ func (suite *MTOShipmentServiceSuite) TestShipmentDeleter() { func (suite *MTOShipmentServiceSuite) TestPrimeShipmentDeleter() { builder := query.NewQueryBuilder() - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &routemocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), diff --git a/pkg/services/mto_shipment/shipment_diversion_approver_test.go b/pkg/services/mto_shipment/shipment_diversion_approver_test.go index 73195c53c4e..e43319b2fba 100644 --- a/pkg/services/mto_shipment/shipment_diversion_approver_test.go +++ b/pkg/services/mto_shipment/shipment_diversion_approver_test.go @@ -11,11 +11,12 @@ import ( "github.com/transcom/mymove/pkg/factory" "github.com/transcom/mymove/pkg/models" moverouter "github.com/transcom/mymove/pkg/services/move" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" ) func (suite *MTOShipmentServiceSuite) TestApproveShipmentDiversion() { router := NewShipmentRouter() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) approver := NewShipmentDiversionApprover(router, moveRouter) suite.Run("If the shipment diversion is approved successfully, it should update the shipment status in the DB", func() { diff --git a/pkg/services/order/excess_weight_risk_manager_test.go b/pkg/services/order/excess_weight_risk_manager_test.go index ad67a0d80b5..282eefd6a8b 100644 --- a/pkg/services/order/excess_weight_risk_manager_test.go +++ b/pkg/services/order/excess_weight_risk_manager_test.go @@ -10,13 +10,14 @@ import ( "github.com/transcom/mymove/pkg/factory" "github.com/transcom/mymove/pkg/models" moverouter "github.com/transcom/mymove/pkg/services/move" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" storageTest "github.com/transcom/mymove/pkg/storage/test" "github.com/transcom/mymove/pkg/uploader" ) func (suite *OrderServiceSuite) TestUpdateBillableWeightAsTOO() { suite.Run("Returns an error when order is not found", func() { - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) excessWeightRiskManager := NewExcessWeightRiskManager(moveRouter) nonexistentUUID := uuid.Must(uuid.NewV4()) newAuthorizedWeight := int(10000) @@ -29,7 +30,7 @@ func (suite *OrderServiceSuite) TestUpdateBillableWeightAsTOO() { }) suite.Run("Returns an error when the etag does not match", func() { - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) excessWeightRiskManager := NewExcessWeightRiskManager(moveRouter) order := factory.BuildMove(suite.DB(), nil, nil).Orders newAuthorizedWeight := int(10000) @@ -43,7 +44,7 @@ func (suite *OrderServiceSuite) TestUpdateBillableWeightAsTOO() { }) suite.Run("Updates the BillableWeight and approves the move when all fields are valid", func() { - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) excessWeightRiskManager := NewExcessWeightRiskManager(moveRouter) now := time.Now() move := factory.BuildApprovalsRequestedMove(suite.DB(), []factory.Customization{ @@ -76,7 +77,7 @@ func (suite *OrderServiceSuite) TestUpdateBillableWeightAsTOO() { }) suite.Run("Updates the BillableWeight but does not approve the move if unacknowledged amended orders exist", func() { - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) excessWeightRiskManager := NewExcessWeightRiskManager(moveRouter) storer := storageTest.NewFakeS3Storage(true) userUploader, err := uploader.NewUserUploader(storer, 100*uploader.MB) @@ -137,7 +138,7 @@ func (suite *OrderServiceSuite) TestUpdateBillableWeightAsTOO() { }) suite.Run("Updates the BillableWeight but does not approve the move if unreviewed service items exist", func() { - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) excessWeightRiskManager := NewExcessWeightRiskManager(moveRouter) _, _, move := suite.createServiceItem() @@ -164,7 +165,7 @@ func (suite *OrderServiceSuite) TestUpdateBillableWeightAsTOO() { }) suite.Run("Updates the BillableWeight but does not acknowledge the risk if there is no excess weight risk", func() { - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) excessWeightRiskManager := NewExcessWeightRiskManager(moveRouter) move := factory.BuildApprovalsRequestedMove(suite.DB(), nil, nil) order := move.Orders @@ -189,7 +190,7 @@ func (suite *OrderServiceSuite) TestUpdateBillableWeightAsTOO() { }) suite.Run("Updates the BillableWeight but does not acknowledge the risk if the risk was already acknowledged", func() { - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) excessWeightRiskManager := NewExcessWeightRiskManager(moveRouter) now := time.Now() move := factory.BuildApprovalsRequestedMove(suite.DB(), []factory.Customization{ @@ -223,7 +224,7 @@ func (suite *OrderServiceSuite) TestUpdateBillableWeightAsTOO() { func (suite *OrderServiceSuite) TestUpdateBillableWeightAsTIO() { suite.Run("Returns an error when order is not found", func() { - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) excessWeightRiskManager := NewExcessWeightRiskManager(moveRouter) nonexistentUUID := uuid.Must(uuid.NewV4()) newAuthorizedWeight := int(10000) @@ -237,7 +238,7 @@ func (suite *OrderServiceSuite) TestUpdateBillableWeightAsTIO() { }) suite.Run("Returns an error when the etag does not match", func() { - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) excessWeightRiskManager := NewExcessWeightRiskManager(moveRouter) order := factory.BuildMove(suite.DB(), nil, nil).Orders newAuthorizedWeight := int(10000) @@ -252,7 +253,7 @@ func (suite *OrderServiceSuite) TestUpdateBillableWeightAsTIO() { }) suite.Run("Updates the MaxBillableWeight and TIO remarks and approves the move when all fields are valid", func() { - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) excessWeightRiskManager := NewExcessWeightRiskManager(moveRouter) now := time.Now() move := factory.BuildApprovalsRequestedMove(suite.DB(), []factory.Customization{ @@ -287,7 +288,7 @@ func (suite *OrderServiceSuite) TestUpdateBillableWeightAsTIO() { }) suite.Run("Updates the MaxBillableWeight and TIO remarks but does not approve the move if unacknowledged amended orders exist", func() { - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) excessWeightRiskManager := NewExcessWeightRiskManager(moveRouter) storer := storageTest.NewFakeS3Storage(true) userUploader, err := uploader.NewUserUploader(storer, 100*uploader.MB) @@ -350,7 +351,7 @@ func (suite *OrderServiceSuite) TestUpdateBillableWeightAsTIO() { }) suite.Run("Updates the MaxBillableWeight and TIO remarks but does not approve the move if unreviewed service items exist", func() { - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) excessWeightRiskManager := NewExcessWeightRiskManager(moveRouter) _, _, move := suite.createServiceItem() @@ -379,7 +380,7 @@ func (suite *OrderServiceSuite) TestUpdateBillableWeightAsTIO() { }) suite.Run("Updates the MaxBillableWeight and TIO remarks but does not acknowledge the risk if there is no excess weight risk", func() { - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) excessWeightRiskManager := NewExcessWeightRiskManager(moveRouter) move := factory.BuildApprovalsRequestedMove(suite.DB(), nil, nil) order := move.Orders @@ -406,7 +407,7 @@ func (suite *OrderServiceSuite) TestUpdateBillableWeightAsTIO() { }) suite.Run("Updates the MaxBillableWeight and TIO remarks but does not acknowledge the risk if the risk was already acknowledged", func() { - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) excessWeightRiskManager := NewExcessWeightRiskManager(moveRouter) now := time.Now() move := factory.BuildApprovalsRequestedMove(suite.DB(), []factory.Customization{ @@ -442,7 +443,7 @@ func (suite *OrderServiceSuite) TestUpdateBillableWeightAsTIO() { func (suite *OrderServiceSuite) TestAcknowledgeExcessWeightRisk() { suite.Run("Returns an error when move is not found", func() { - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) excessWeightRiskManager := NewExcessWeightRiskManager(moveRouter) nonexistentUUID := uuid.Must(uuid.NewV4()) eTag := "" @@ -454,7 +455,7 @@ func (suite *OrderServiceSuite) TestAcknowledgeExcessWeightRisk() { }) suite.Run("Returns an error when the etag does not match", func() { - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) excessWeightRiskManager := NewExcessWeightRiskManager(moveRouter) move := factory.BuildMove(suite.DB(), nil, nil) order := move.Orders @@ -468,7 +469,7 @@ func (suite *OrderServiceSuite) TestAcknowledgeExcessWeightRisk() { }) suite.Run("Updates the ExcessWeightAcknowledgedAt field and approves the move when all fields are valid", func() { - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) excessWeightRiskManager := NewExcessWeightRiskManager(moveRouter) now := time.Now() move := factory.BuildApprovalsRequestedMove(suite.DB(), []factory.Customization{ @@ -496,7 +497,7 @@ func (suite *OrderServiceSuite) TestAcknowledgeExcessWeightRisk() { }) suite.Run("Updates the ExcessWeightAcknowledgedAt field but does not approve the move if unacknowledged amended orders exist", func() { - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) excessWeightRiskManager := NewExcessWeightRiskManager(moveRouter) storer := storageTest.NewFakeS3Storage(true) userUploader, err := uploader.NewUserUploader(storer, 100*uploader.MB) @@ -550,7 +551,7 @@ func (suite *OrderServiceSuite) TestAcknowledgeExcessWeightRisk() { }) suite.Run("Updates the ExcessWeightAcknowledgedAt field but does not approve the move if unreviewed service items exist", func() { - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) excessWeightRiskManager := NewExcessWeightRiskManager(moveRouter) _, _, move := suite.createServiceItem() @@ -570,7 +571,7 @@ func (suite *OrderServiceSuite) TestAcknowledgeExcessWeightRisk() { }) suite.Run("Does not update the ExcessWeightAcknowledgedAt field if there is no risk of excess weight", func() { - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) excessWeightRiskManager := NewExcessWeightRiskManager(moveRouter) move := factory.BuildApprovalsRequestedMove(suite.DB(), nil, nil) @@ -591,7 +592,7 @@ func (suite *OrderServiceSuite) TestAcknowledgeExcessWeightRisk() { }) suite.Run("Does not update the ExcessWeightAcknowledgedAt field if the risk was already acknowledged", func() { - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) excessWeightRiskManager := NewExcessWeightRiskManager(moveRouter) date := time.Now().Add(30 * time.Minute) diff --git a/pkg/services/order/order_updater_test.go b/pkg/services/order/order_updater_test.go index 1bf72866552..8994233f250 100644 --- a/pkg/services/order/order_updater_test.go +++ b/pkg/services/order/order_updater_test.go @@ -17,6 +17,7 @@ import ( "github.com/transcom/mymove/pkg/handlers" "github.com/transcom/mymove/pkg/models" "github.com/transcom/mymove/pkg/services/move" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" storageTest "github.com/transcom/mymove/pkg/storage/test" "github.com/transcom/mymove/pkg/swagger/nullable" "github.com/transcom/mymove/pkg/testdatagen" @@ -24,7 +25,7 @@ import ( func (suite *OrderServiceSuite) TestUpdateOrderAsTOO() { suite.Run("Returns an error when order is not found", func() { - moveRouter := move.NewMoveRouter() + moveRouter := move.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) orderUpdater := NewOrderUpdater(moveRouter) nonexistentUUID := uuid.Must(uuid.NewV4()) @@ -38,7 +39,7 @@ func (suite *OrderServiceSuite) TestUpdateOrderAsTOO() { }) suite.Run("Returns an error when origin duty location is not found", func() { - moveRouter := move.NewMoveRouter() + moveRouter := move.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) orderUpdater := NewOrderUpdater(moveRouter) order := factory.BuildMove(suite.DB(), nil, nil).Orders newDutyLocation := factory.BuildDutyLocation(suite.DB(), nil, nil) @@ -57,7 +58,7 @@ func (suite *OrderServiceSuite) TestUpdateOrderAsTOO() { }) suite.Run("Returns an error when new duty location is not found", func() { - moveRouter := move.NewMoveRouter() + moveRouter := move.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) orderUpdater := NewOrderUpdater(moveRouter) order := factory.BuildMove(suite.DB(), nil, nil).Orders originDutyLocation := factory.BuildDutyLocation(suite.DB(), nil, nil) @@ -76,7 +77,7 @@ func (suite *OrderServiceSuite) TestUpdateOrderAsTOO() { }) suite.Run("Returns an error when the etag does not match", func() { - moveRouter := move.NewMoveRouter() + moveRouter := move.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) orderUpdater := NewOrderUpdater(moveRouter) order := factory.BuildMove(suite.DB(), nil, nil).Orders @@ -90,7 +91,7 @@ func (suite *OrderServiceSuite) TestUpdateOrderAsTOO() { }) suite.Run("Updates the order when all fields are valid", func() { - moveRouter := move.NewMoveRouter() + moveRouter := move.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) orderUpdater := NewOrderUpdater(moveRouter) move := factory.BuildServiceCounselingCompletedMove(suite.DB(), nil, nil) order := move.Orders @@ -154,7 +155,7 @@ func (suite *OrderServiceSuite) TestUpdateOrderAsTOO() { }) suite.Run("Rolls back transaction if Order is invalid", func() { - moveRouter := move.NewMoveRouter() + moveRouter := move.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) orderUpdater := NewOrderUpdater(moveRouter) order := factory.BuildServiceCounselingCompletedMove(suite.DB(), nil, nil).Orders @@ -188,7 +189,7 @@ func (suite *OrderServiceSuite) TestUpdateOrderAsTOO() { }) suite.Run("Allow Order update to have a missing HHG SAC", func() { - moveRouter := move.NewMoveRouter() + moveRouter := move.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) orderUpdater := NewOrderUpdater(moveRouter) order := factory.BuildServiceCounselingCompletedMove(suite.DB(), nil, nil).Orders @@ -232,7 +233,7 @@ func (suite *OrderServiceSuite) TestUpdateOrderAsTOO() { }) suite.Run("Allow Order update to have a missing NTS SAC", func() { - moveRouter := move.NewMoveRouter() + moveRouter := move.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) orderUpdater := NewOrderUpdater(moveRouter) order := factory.BuildServiceCounselingCompletedMove(suite.DB(), nil, nil).Orders @@ -276,7 +277,7 @@ func (suite *OrderServiceSuite) TestUpdateOrderAsTOO() { }) suite.Run("Allow Order update to have a missing NTS TAC", func() { - moveRouter := move.NewMoveRouter() + moveRouter := move.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) orderUpdater := NewOrderUpdater(moveRouter) order := factory.BuildServiceCounselingCompletedMove(suite.DB(), nil, nil).Orders @@ -320,7 +321,7 @@ func (suite *OrderServiceSuite) TestUpdateOrderAsTOO() { }) suite.Run("Rolls back transaction if Order is invalid", func() { - moveRouter := move.NewMoveRouter() + moveRouter := move.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) orderUpdater := NewOrderUpdater(moveRouter) order := factory.BuildServiceCounselingCompletedMove(suite.DB(), nil, nil).Orders @@ -355,7 +356,7 @@ func (suite *OrderServiceSuite) TestUpdateOrderAsTOO() { }) suite.Run("Rolls back transaction if Order is missing required fields", func() { - moveRouter := move.NewMoveRouter() + moveRouter := move.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) orderUpdater := NewOrderUpdater(moveRouter) orderWithoutDefaults := factory.BuildOrderWithoutDefaults(suite.DB(), nil, nil) @@ -398,7 +399,7 @@ func (suite *OrderServiceSuite) TestUpdateOrderAsTOO() { func (suite *OrderServiceSuite) TestUpdateOrderAsCounselor() { suite.Run("Returns an error when order is not found", func() { - moveRouter := move.NewMoveRouter() + moveRouter := move.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) orderUpdater := NewOrderUpdater(moveRouter) nonexistentUUID := uuid.Must(uuid.NewV4()) @@ -412,7 +413,7 @@ func (suite *OrderServiceSuite) TestUpdateOrderAsCounselor() { }) suite.Run("Returns an error when the etag does not match", func() { - moveRouter := move.NewMoveRouter() + moveRouter := move.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) orderUpdater := NewOrderUpdater(moveRouter) order := factory.BuildMove(suite.DB(), nil, nil).Orders @@ -426,7 +427,7 @@ func (suite *OrderServiceSuite) TestUpdateOrderAsCounselor() { }) suite.Run("Updates the order when it is found", func() { - moveRouter := move.NewMoveRouter() + moveRouter := move.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) orderUpdater := NewOrderUpdater(moveRouter) order := factory.BuildNeedsServiceCounselingMove(suite.DB(), nil, nil).Orders @@ -477,7 +478,7 @@ func (suite *OrderServiceSuite) TestUpdateOrderAsCounselor() { }) suite.Run("Updates the PPM actual expense reimbursement when pay grade is civilian", func() { - moveRouter := move.NewMoveRouter() + moveRouter := move.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) orderUpdater := NewOrderUpdater(moveRouter) ppmShipment := factory.BuildPPMShipmentThatNeedsCloseout(suite.DB(), nil, nil) @@ -505,7 +506,7 @@ func (suite *OrderServiceSuite) TestUpdateOrderAsCounselor() { }) suite.Run("Rolls back transaction if Order is invalid", func() { - moveRouter := move.NewMoveRouter() + moveRouter := move.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) orderUpdater := NewOrderUpdater(moveRouter) order := factory.BuildOrderWithoutDefaults(suite.DB(), nil, nil) @@ -540,7 +541,7 @@ func (suite *OrderServiceSuite) TestUpdateOrderAsCounselor() { func (suite *OrderServiceSuite) TestUpdateAllowanceAsTOO() { suite.Run("Returns an error when order is not found", func() { - moveRouter := move.NewMoveRouter() + moveRouter := move.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) orderUpdater := NewOrderUpdater(moveRouter) nonexistentUUID := uuid.Must(uuid.NewV4()) @@ -554,7 +555,7 @@ func (suite *OrderServiceSuite) TestUpdateAllowanceAsTOO() { }) suite.Run("Returns an error when the etag does not match", func() { - moveRouter := move.NewMoveRouter() + moveRouter := move.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) orderUpdater := NewOrderUpdater(moveRouter) order := factory.BuildMove(suite.DB(), nil, nil).Orders @@ -568,7 +569,7 @@ func (suite *OrderServiceSuite) TestUpdateAllowanceAsTOO() { }) suite.Run("Updates the allowance when all fields are valid and no dependents", func() { - moveRouter := move.NewMoveRouter() + moveRouter := move.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) orderUpdater := NewOrderUpdater(moveRouter) order := factory.BuildServiceCounselingCompletedMove(suite.DB(), nil, nil).Orders @@ -607,7 +608,7 @@ func (suite *OrderServiceSuite) TestUpdateAllowanceAsTOO() { }) suite.Run("Updates the allowance when all OCONUS fields are valid with dependents", func() { - moveRouter := move.NewMoveRouter() + moveRouter := move.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) orderUpdater := NewOrderUpdater(moveRouter) order := factory.BuildServiceCounselingCompletedMove(suite.DB(), nil, nil).Orders @@ -652,7 +653,7 @@ func (suite *OrderServiceSuite) TestUpdateAllowanceAsTOO() { }) suite.Run("Updates the allowance when all fields are valid with dependents", func() { - moveRouter := move.NewMoveRouter() + moveRouter := move.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) orderUpdater := NewOrderUpdater(moveRouter) // Build with dependents trait order := factory.BuildServiceCounselingCompletedMove(suite.DB(), nil, []factory.Trait{ @@ -696,7 +697,7 @@ func (suite *OrderServiceSuite) TestUpdateAllowanceAsTOO() { func (suite *OrderServiceSuite) TestUpdateAllowanceAsCounselor() { suite.Run("Returns an error when order is not found", func() { - moveRouter := move.NewMoveRouter() + moveRouter := move.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) orderUpdater := NewOrderUpdater(moveRouter) nonexistentUUID := uuid.Must(uuid.NewV4()) @@ -710,7 +711,7 @@ func (suite *OrderServiceSuite) TestUpdateAllowanceAsCounselor() { }) suite.Run("Returns an error when the etag does not match", func() { - moveRouter := move.NewMoveRouter() + moveRouter := move.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) orderUpdater := NewOrderUpdater(moveRouter) order := factory.BuildMove(suite.DB(), nil, nil).Orders @@ -724,7 +725,7 @@ func (suite *OrderServiceSuite) TestUpdateAllowanceAsCounselor() { }) suite.Run("Updates the entitlement of OCONUS fields", func() { - moveRouter := move.NewMoveRouter() + moveRouter := move.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) orderUpdater := NewOrderUpdater(moveRouter) order := factory.BuildNeedsServiceCounselingMove(suite.DB(), nil, nil).Orders @@ -764,7 +765,7 @@ func (suite *OrderServiceSuite) TestUpdateAllowanceAsCounselor() { }) suite.Run("Updates the allowance when all fields are valid with dependents authorized but not present", func() { - moveRouter := move.NewMoveRouter() + moveRouter := move.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) orderUpdater := NewOrderUpdater(moveRouter) order := factory.BuildNeedsServiceCounselingMove(suite.DB(), nil, nil).Orders @@ -807,7 +808,7 @@ func (suite *OrderServiceSuite) TestUpdateAllowanceAsCounselor() { }) suite.Run("Updates the allowance when all fields are valid with dependents present and authorized", func() { - moveRouter := move.NewMoveRouter() + moveRouter := move.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) orderUpdater := NewOrderUpdater(moveRouter) order := factory.BuildNeedsServiceCounselingMove(suite.DB(), nil, []factory.Trait{ factory.GetTraitHasDependents, @@ -852,7 +853,7 @@ func (suite *OrderServiceSuite) TestUpdateAllowanceAsCounselor() { }) suite.Run("Updates the allowance when move needs service counseling and order fields are missing", func() { - moveRouter := move.NewMoveRouter() + moveRouter := move.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) orderUpdater := NewOrderUpdater(moveRouter) orderWithoutDefaults := factory.BuildOrderWithoutDefaults(suite.DB(), nil, nil) move := factory.BuildNeedsServiceCounselingMove(suite.DB(), []factory.Customization{ @@ -909,7 +910,7 @@ func (suite *OrderServiceSuite) TestUpdateAllowanceAsCounselor() { }) suite.Run("Entire update is aborted when ProGearWeight is over max amount", func() { - moveRouter := move.NewMoveRouter() + moveRouter := move.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) orderUpdater := NewOrderUpdater(moveRouter) order := factory.BuildNeedsServiceCounselingMove(suite.DB(), nil, nil).Orders @@ -945,7 +946,7 @@ func (suite *OrderServiceSuite) TestUpdateAllowanceAsCounselor() { }) suite.Run("Entire update is aborted when ProGearWeightSpouse is over max amount", func() { - moveRouter := move.NewMoveRouter() + moveRouter := move.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) orderUpdater := NewOrderUpdater(moveRouter) order := factory.BuildNeedsServiceCounselingMove(suite.DB(), nil, nil).Orders @@ -982,7 +983,7 @@ func (suite *OrderServiceSuite) TestUpdateAllowanceAsCounselor() { } func (suite *OrderServiceSuite) TestUploadAmendedOrdersForCustomer() { - moveRouter := move.NewMoveRouter() + moveRouter := move.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) orderUpdater := NewOrderUpdater(moveRouter) setUpOrders := func(setUpPreExistingAmendedOrders bool) *models.Order { diff --git a/pkg/services/shipment_address_update/shipment_address_update_requester_test.go b/pkg/services/shipment_address_update/shipment_address_update_requester_test.go index 863e1851d21..d9a3dad5a54 100644 --- a/pkg/services/shipment_address_update/shipment_address_update_requester_test.go +++ b/pkg/services/shipment_address_update/shipment_address_update_requester_test.go @@ -13,6 +13,7 @@ import ( routemocks "github.com/transcom/mymove/pkg/route/mocks" "github.com/transcom/mymove/pkg/services/address" moveservices "github.com/transcom/mymove/pkg/services/move" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" "github.com/transcom/mymove/pkg/testdatagen" ) @@ -62,7 +63,7 @@ func (suite *ShipmentAddressUpdateServiceSuite) TestCreateApprovedShipmentAddres } addressCreator := address.NewAddressCreator() mockPlanner := &routemocks.Planner{} - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) addressUpdateRequester := NewShipmentAddressUpdateRequester(mockPlanner, addressCreator, moveRouter) suite.Run("Successfully create ShipmentAddressUpdate", func() { @@ -577,7 +578,7 @@ func (suite *ShipmentAddressUpdateServiceSuite) TestCreateApprovedShipmentAddres func (suite *ShipmentAddressUpdateServiceSuite) TestTOOApprovedShipmentAddressUpdateRequest() { addressCreator := address.NewAddressCreator() mockPlanner := &routemocks.Planner{} - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) mockPlanner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), mock.Anything, @@ -834,7 +835,7 @@ func (suite *ShipmentAddressUpdateServiceSuite) TestTOOApprovedShipmentAddressUp } addressCreator := address.NewAddressCreator() mockPlanner := &routemocks.Planner{} - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) addressUpdateRequester := NewShipmentAddressUpdateRequester(mockPlanner, addressCreator, moveRouter) suite.Run("Service items are rejected and regenerated when pricing type changes post TOO approval", func() { diff --git a/pkg/services/sit_extension/sit_extension_approver_test.go b/pkg/services/sit_extension/sit_extension_approver_test.go index 286d31cfcc8..56e787d7de2 100644 --- a/pkg/services/sit_extension/sit_extension_approver_test.go +++ b/pkg/services/sit_extension/sit_extension_approver_test.go @@ -9,10 +9,11 @@ import ( "github.com/transcom/mymove/pkg/factory" "github.com/transcom/mymove/pkg/models" moverouter "github.com/transcom/mymove/pkg/services/move" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" ) func (suite *SitExtensionServiceSuite) TestApproveSITExtension() { - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) sitExtensionApprover := NewSITExtensionApprover(moveRouter) suite.Run("Returns an error when shipment is not found", func() { diff --git a/pkg/services/sit_extension/sit_extension_creator_test.go b/pkg/services/sit_extension/sit_extension_creator_test.go index 9a3a15afc98..a0531ee0c0c 100644 --- a/pkg/services/sit_extension/sit_extension_creator_test.go +++ b/pkg/services/sit_extension/sit_extension_creator_test.go @@ -9,12 +9,13 @@ import ( "github.com/transcom/mymove/pkg/services" moverouter "github.com/transcom/mymove/pkg/services/move" movefetcher "github.com/transcom/mymove/pkg/services/move_task_order" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" ) func (suite *SitExtensionServiceSuite) TestSITExtensionCreator() { // Create move router for SitExtension Createor - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) sitExtensionCreator := NewSitExtensionCreator(moveRouter) movefetcher := movefetcher.NewMoveTaskOrderFetcher() diff --git a/pkg/services/sit_extension/sit_extension_denier_test.go b/pkg/services/sit_extension/sit_extension_denier_test.go index 3ea81e61d42..1649346eb76 100644 --- a/pkg/services/sit_extension/sit_extension_denier_test.go +++ b/pkg/services/sit_extension/sit_extension_denier_test.go @@ -11,11 +11,12 @@ import ( "github.com/transcom/mymove/pkg/factory" "github.com/transcom/mymove/pkg/models" moverouter "github.com/transcom/mymove/pkg/services/move" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" "github.com/transcom/mymove/pkg/testdatagen" ) func (suite *SitExtensionServiceSuite) TestDenySITExtension() { - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) sitExtensionDenier := NewSITExtensionDenier(moveRouter) suite.Run("Returns an error when shipment is not found", func() { diff --git a/pkg/services/transportation_office.go b/pkg/services/transportation_office.go index 307f0d0fef5..a0d5cd95b8c 100644 --- a/pkg/services/transportation_office.go +++ b/pkg/services/transportation_office.go @@ -13,4 +13,5 @@ type TransportationOfficesFetcher interface { GetTransportationOffice(appCtx appcontext.AppContext, transportationOfficeID uuid.UUID, includeOnlyPPMCloseoutOffices bool) (*models.TransportationOffice, error) GetAllGBLOCs(appCtx appcontext.AppContext) (*models.GBLOCs, error) GetCounselingOffices(appCtx appcontext.AppContext, dutyLocationID uuid.UUID) (*models.TransportationOffices, error) + FindClosestCounselingOffice(appCtx appcontext.AppContext, dutyLocationID uuid.UUID) (models.TransportationOffice, error) } diff --git a/pkg/services/transportation_office/transportation_office_fetcher.go b/pkg/services/transportation_office/transportation_office_fetcher.go index be942890c75..0f8b77ff181 100644 --- a/pkg/services/transportation_office/transportation_office_fetcher.go +++ b/pkg/services/transportation_office/transportation_office_fetcher.go @@ -142,6 +142,18 @@ func (o transportationOfficesFetcher) GetCounselingOffices(appCtx appcontext.App return &officeList, nil } +func (o transportationOfficesFetcher) FindClosestCounselingOffice(appCtx appcontext.AppContext, dutyLocationID uuid.UUID) (models.TransportationOffice, error) { + officeList, err := findCounselingOffice(appCtx, dutyLocationID) + var closestOffice models.TransportationOffice + + if err != nil { + return closestOffice, err + } + + closestOffice = officeList[0] + return closestOffice, nil +} + // return all the transportation offices in the GBLOC of the given duty location where provides_services_counseling = true func findCounselingOffice(appCtx appcontext.AppContext, dutyLocationID uuid.UUID) (models.TransportationOffices, error) { var officeList []models.TransportationOffice diff --git a/pkg/testdatagen/scenario/devseed.go b/pkg/testdatagen/scenario/devseed.go index fe698271e8d..93555dd2ce3 100644 --- a/pkg/testdatagen/scenario/devseed.go +++ b/pkg/testdatagen/scenario/devseed.go @@ -14,6 +14,7 @@ import ( "github.com/transcom/mymove/pkg/models" moverouter "github.com/transcom/mymove/pkg/services/move" mtoshipment "github.com/transcom/mymove/pkg/services/mto_shipment" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" "github.com/transcom/mymove/pkg/uploader" ) @@ -28,7 +29,7 @@ var DevSeedScenario = devSeedScenario{ // Setup initializes the run setup for the devseed scenario func (e *devSeedScenario) Setup(appCtx appcontext.AppContext, userUploader *uploader.UserUploader, primeUploader *uploader.PrimeUploader) { db := appCtx.DB() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) shipmentFetcher := mtoshipment.NewMTOShipmentFetcher() // Testdatagen factories will create new random duty locations so let's get the standard ones in the migrations diff --git a/pkg/testdatagen/scenario/e2ebasic.go b/pkg/testdatagen/scenario/e2ebasic.go index 3f778ea4894..2ddf692fe32 100644 --- a/pkg/testdatagen/scenario/e2ebasic.go +++ b/pkg/testdatagen/scenario/e2ebasic.go @@ -15,6 +15,7 @@ import ( "github.com/transcom/mymove/pkg/models" "github.com/transcom/mymove/pkg/models/roles" moverouter "github.com/transcom/mymove/pkg/services/move" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" "github.com/transcom/mymove/pkg/testdatagen" "github.com/transcom/mymove/pkg/unit" "github.com/transcom/mymove/pkg/uploader" @@ -4299,7 +4300,7 @@ func createNTSMoveWithServiceItemsandPaymentRequests(appCtx appcontext.AppContex // Run does that data load thing func (e e2eBasicScenario) Run(appCtx appcontext.AppContext, userUploader *uploader.UserUploader, primeUploader *uploader.PrimeUploader) { - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) // Testdatagen factories will create new random duty locations so let's get the standard ones in the migrations var allDutyLocations []models.DutyLocation err := appCtx.DB().All(&allDutyLocations) diff --git a/pkg/testdatagen/testharness/make_move.go b/pkg/testdatagen/testharness/make_move.go index fd337bb029f..937b9fae06e 100644 --- a/pkg/testdatagen/testharness/make_move.go +++ b/pkg/testdatagen/testharness/make_move.go @@ -24,6 +24,7 @@ import ( mtoserviceitem "github.com/transcom/mymove/pkg/services/mto_service_item" mtoshipment "github.com/transcom/mymove/pkg/services/mto_shipment" "github.com/transcom/mymove/pkg/services/query" + transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" "github.com/transcom/mymove/pkg/storage" "github.com/transcom/mymove/pkg/testdatagen" "github.com/transcom/mymove/pkg/testdatagen/scenario" @@ -3792,7 +3793,7 @@ func MakeHHGMoveWithApprovedNTSShipmentsForTOO(appCtx appcontext.AppContext) mod locator := models.GenerateLocator() move := scenario.CreateMoveWithHHGAndNTSShipments(appCtx, locator, false) - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) err := moveRouter.Approve(appCtx, &move) if err != nil { log.Panic("Failed to approve move: %w", err) @@ -3896,7 +3897,7 @@ func MakeHHGMoveWithApprovedNTSRShipmentsForTOO(appCtx appcontext.AppContext) mo locator := models.GenerateLocator() move := scenario.CreateMoveWithHHGAndNTSRShipments(appCtx, locator, false) - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) err := moveRouter.Approve(appCtx, &move) if err != nil { log.Panic("Failed to approve move: %w", err) @@ -4028,7 +4029,7 @@ func MakeBoatHaulAwayMoveNeedsSC(appCtx appcontext.AppContext) models.Move { MoveLocator: models.GenerateLocator(), } - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) move := scenario.CreateBoatHaulAwayMoveForSC(appCtx, userUploader, moveRouter, moveInfo) @@ -4057,7 +4058,7 @@ func MakeBoatHaulAwayMoveNeedsTOOApproval(appCtx appcontext.AppContext) models.M MoveLocator: models.GenerateLocator(), } - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) move := scenario.CreateBoatHaulAwayMoveForTOO(appCtx, userUploader, moveRouter, moveInfo) @@ -4567,7 +4568,7 @@ func MakeSubmittedMoveWithPPMShipmentForSC(appCtx appcontext.AppContext) models. MoveLocator: models.GenerateLocator(), } - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) move := scenario.CreateSubmittedMoveWithPPMShipmentForSC(appCtx, userUploader, moveRouter, moveInfo) From e5a6ef0ac5e2c1043fe2c59c3a42198f2232573c Mon Sep 17 00:00:00 2001 From: Samay Sofo Date: Mon, 6 Jan 2025 14:10:12 +0000 Subject: [PATCH 03/28] fixed origindutylocation providesServicesCounseling nil issue --- pkg/services/move/move_router.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/services/move/move_router.go b/pkg/services/move/move_router.go index 9e3f35a7483..9df5ccbe531 100644 --- a/pkg/services/move/move_router.go +++ b/pkg/services/move/move_router.go @@ -176,6 +176,7 @@ func (router moveRouter) needsServiceCounseling(appCtx appcontext.AppContext, mo // sendToServiceCounselor makes the move available for a Service Counselor to review func (router moveRouter) sendToServiceCounselor(appCtx appcontext.AppContext, move *models.Move) error { var orders models.Order + var originDutyLocation models.DutyLocation err := appCtx.DB().Q(). Where("orders.id = ?", move.OrdersID). First(&orders) @@ -213,7 +214,20 @@ func (router moveRouter) sendToServiceCounselor(appCtx appcontext.AppContext, mo move.Status = models.MoveStatusNeedsServiceCounseling now := time.Now() move.SubmittedAt = &now + if orders.OriginDutyLocationID == nil || *orders.OriginDutyLocationID == uuid.Nil { + return apperror.NewInvalidInputError(orders.ID, err, nil, "orders missing OriginDutyLocation") + } + originDutyLocation, err = models.FetchDutyLocation(appCtx.DB(), *orders.OriginDutyLocationID) + if err != nil { + appCtx.Logger().Error("failure finding the origin duty location", zap.Error(err)) + return apperror.NewInvalidInputError(*orders.OriginDutyLocationID, err, nil, "unable to find origin duty location") + } + orders.OriginDutyLocation = &originDutyLocation + if err != nil { + appCtx.Logger().Error("failure finding the origin duty location", zap.Error(err)) + return apperror.NewInvalidInputError(*orders.OriginDutyLocationID, err, nil, "unable to find origin duty location") + } for i := range move.MTOShipments { // if it's a PPMShipment update both the mto and ppm shipment level statuses if move.MTOShipments[i].ShipmentType == models.MTOShipmentTypePPM { From fe1793e36e37e1561caff80a84a27232240e38c8 Mon Sep 17 00:00:00 2001 From: Samay Sofo Date: Mon, 6 Jan 2025 14:26:45 +0000 Subject: [PATCH 04/28] code clean up --- pkg/services/move/move_router.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pkg/services/move/move_router.go b/pkg/services/move/move_router.go index 9df5ccbe531..9b47f5b5d48 100644 --- a/pkg/services/move/move_router.go +++ b/pkg/services/move/move_router.go @@ -224,10 +224,6 @@ func (router moveRouter) sendToServiceCounselor(appCtx appcontext.AppContext, mo return apperror.NewInvalidInputError(*orders.OriginDutyLocationID, err, nil, "unable to find origin duty location") } orders.OriginDutyLocation = &originDutyLocation - if err != nil { - appCtx.Logger().Error("failure finding the origin duty location", zap.Error(err)) - return apperror.NewInvalidInputError(*orders.OriginDutyLocationID, err, nil, "unable to find origin duty location") - } for i := range move.MTOShipments { // if it's a PPMShipment update both the mto and ppm shipment level statuses if move.MTOShipments[i].ShipmentType == models.MTOShipmentTypePPM { From 78581e2b452afcbe3553358ae72d243c5a5db78a Mon Sep 17 00:00:00 2001 From: Samay Sofo Date: Thu, 9 Jan 2025 15:18:39 +0000 Subject: [PATCH 05/28] Added function for finding the closeset counseling office with its assciated tests --- .../transportation_office_fetcher.go | 105 ++++++++++++++++-- .../transportation_office_fetcher_test.go | 78 +++++++++++++ 2 files changed, 171 insertions(+), 12 deletions(-) diff --git a/pkg/services/transportation_office/transportation_office_fetcher.go b/pkg/services/transportation_office/transportation_office_fetcher.go index 0f8b77ff181..f1b565f4a3a 100644 --- a/pkg/services/transportation_office/transportation_office_fetcher.go +++ b/pkg/services/transportation_office/transportation_office_fetcher.go @@ -6,6 +6,7 @@ import ( "github.com/gofrs/uuid" "github.com/pkg/errors" + "go.uber.org/zap" "github.com/transcom/mymove/pkg/appcontext" "github.com/transcom/mymove/pkg/apperror" @@ -142,18 +143,6 @@ func (o transportationOfficesFetcher) GetCounselingOffices(appCtx appcontext.App return &officeList, nil } -func (o transportationOfficesFetcher) FindClosestCounselingOffice(appCtx appcontext.AppContext, dutyLocationID uuid.UUID) (models.TransportationOffice, error) { - officeList, err := findCounselingOffice(appCtx, dutyLocationID) - var closestOffice models.TransportationOffice - - if err != nil { - return closestOffice, err - } - - closestOffice = officeList[0] - return closestOffice, nil -} - // return all the transportation offices in the GBLOC of the given duty location where provides_services_counseling = true func findCounselingOffice(appCtx appcontext.AppContext, dutyLocationID uuid.UUID) (models.TransportationOffices, error) { var officeList []models.TransportationOffice @@ -317,3 +306,95 @@ func findOconusGblocDepartmentIndicator(appCtx appcontext.AppContext, dutyLocati return nil, apperror.NewImplementationError(fmt.Sprintf("Error: Cannot determine GBLOC -- serviceMember.Affiliation: %s, DutyLocaton: %s, departmentIndicator: %s, dutyLocation.Address.ID: %s", serviceMember.Affiliation, dutyLocation.Name, *departmentIndicator, dutyLocation.Address.ID)) } + +// Return the closeset transportation office in the GBLOC of the given duty location for oconus/cunus duty locations +func (o transportationOfficesFetcher) FindClosestCounselingOffice(appCtx appcontext.AppContext, dutyLocationID uuid.UUID) (models.TransportationOffice, error) { + var closestOffice models.TransportationOffice + duty_location, err := models.FetchDutyLocation(appCtx.DB(), dutyLocationID) + if err != nil { + appCtx.Logger().Error("Failed to fetch duty location", zap.Error(err)) + return closestOffice, err + } + var sqlQuery string + + // Find for oconus duty location + if *duty_location.Address.IsOconus { + gblocDepartmentIndicator, err := findOconusGblocDepartmentIndicator(appCtx, duty_location) + if err != nil { + appCtx.Logger().Error("Failed to find OCONUS GBLOC department indicator", zap.Error(err)) + return closestOffice, err + } + + sqlQuery = ` + WITH counseling_offices AS ( + SELECT transportation_offices.id, transportation_offices.name, transportation_offices.address_id AS counseling_address, + SUBSTRING(a.postal_code, 1, 3) AS origin_zip, SUBSTRING(a2.postal_code, 1, 3) AS dest_zip + FROM duty_locations + JOIN addresses a ON duty_locations.address_id = a.id + JOIN v_locations v ON (a.us_post_region_cities_id = v.uprc_id OR v.uprc_id IS NULL) + JOIN re_oconus_rate_areas r ON r.us_post_region_cities_id = v.uprc_id + JOIN gbloc_aors ON gbloc_aors.oconus_rate_area_id = r.id + JOIN jppso_regions j ON gbloc_aors.jppso_regions_id = j.id + JOIN transportation_offices ON j.code = transportation_offices.gbloc + JOIN addresses a2 ON a2.id = transportation_offices.address_id + WHERE duty_locations.id = $1 AND j.code = $2 + AND transportation_offices.provides_ppm_closeout = true + ) + SELECT counseling_offices.id, counseling_offices.name + FROM counseling_offices + JOIN addresses cnsl_address ON counseling_offices.counseling_address = cnsl_address.id + LEFT JOIN zip3_distances ON ( + (SUBSTRING(cnsl_address.postal_code, 1, 3) = zip3_distances.to_zip3 + AND counseling_offices.origin_zip = zip3_distances.from_zip3) + OR + (SUBSTRING(cnsl_address.postal_code, 1, 3) = zip3_distances.from_zip3 + AND counseling_offices.origin_zip = zip3_distances.to_zip3) + ) + GROUP BY counseling_offices.id, counseling_offices.name, zip3_distances.distance_miles + ORDER BY COALESCE(zip3_distances.distance_miles, 0) ASC + FETCH FIRST 1 ROW ONLY` + + if err := appCtx.DB().Q().RawQuery(sqlQuery, dutyLocationID, gblocDepartmentIndicator.Gbloc).First(&closestOffice); err != nil { + appCtx.Logger().Error("Failed to execute OCONUS SQL query", zap.Error(err)) + if errors.Cause(err).Error() != models.RecordNotFoundErrorString { + return closestOffice, err + } + } + return closestOffice, nil + } else { + + // Find for conus duty location + sqlQuery = ` + WITH counseling_offices AS ( + SELECT transportation_offices.id, transportation_offices.name, transportation_offices.address_id AS counseling_address, SUBSTRING(addresses.postal_code, 1, 3) AS pickup_zip + FROM postal_code_to_gblocs + JOIN addresses ON postal_code_to_gblocs.postal_code = addresses.postal_code + JOIN duty_locations ON addresses.id = duty_locations.address_id + JOIN transportation_offices ON postal_code_to_gblocs.gbloc = transportation_offices.gbloc + WHERE duty_locations.id = $1 + ) + SELECT counseling_offices.id, counseling_offices.name + FROM counseling_offices + JOIN duty_locations duty_locations2 ON counseling_offices.id = duty_locations2.transportation_office_id + JOIN addresses ON counseling_offices.counseling_address = addresses.id + JOIN re_us_post_regions ON addresses.postal_code = re_us_post_regions.uspr_zip_id + LEFT JOIN zip3_distances ON ( + (re_us_post_regions.zip3 = zip3_distances.to_zip3 AND counseling_offices.pickup_zip = zip3_distances.from_zip3) + OR + (re_us_post_regions.zip3 = zip3_distances.from_zip3 AND counseling_offices.pickup_zip = zip3_distances.to_zip3) + ) + WHERE duty_locations2.provides_services_counseling = true + GROUP BY counseling_offices.id, counseling_offices.name, zip3_distances.distance_miles + ORDER BY COALESCE(zip3_distances.distance_miles, 0), counseling_offices.name ASC + FETCH FIRST 1 ROW ONLY` + + if err := appCtx.DB().Q().RawQuery(sqlQuery, dutyLocationID).First(&closestOffice); err != nil { + appCtx.Logger().Error("Failed to execute CONUS SQL query", zap.Error(err)) + if errors.Cause(err).Error() != models.RecordNotFoundErrorString { + return closestOffice, err + } + } + } + + return closestOffice, nil +} diff --git a/pkg/services/transportation_office/transportation_office_fetcher_test.go b/pkg/services/transportation_office/transportation_office_fetcher_test.go index ab07d8c5e39..415fa3422ba 100644 --- a/pkg/services/transportation_office/transportation_office_fetcher_test.go +++ b/pkg/services/transportation_office/transportation_office_fetcher_test.go @@ -677,3 +677,81 @@ func (suite *TransportationOfficeServiceSuite) Test_GetTransportationOffice() { suite.Equal("OFFICE ONE", office1f.Name) suite.Equal("OFFICE TWO", office2f.Name) } + +func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOffices() { + // Test for CONUS + suite.Run("success - find closest counseling office for CONUS", func() { + customAddressCONUS := models.Address{ + ID: uuid.Must(uuid.NewV4()), + StreetAddress1: "123 Mayport St", + City: "NS Mayport", + State: "FL", + PostalCode: "32228", + County: "Duval", + IsOconus: models.BoolPointer(false), + } + suite.MustSave(&customAddressCONUS) + airForce := models.AffiliationAIRFORCE + + origDutyLocationCONUS := factory.BuildDutyLocation(suite.DB(), []factory.Customization{ + {Model: customAddressCONUS, Type: &factory.Addresses.DutyLocationAddress}, + { + Model: models.DutyLocation{ + ProvidesServicesCounseling: false, + }, + }, + {Model: models.TransportationOffice{ + Name: "NS Mayport", + Gbloc: "CNNQ", + ProvidesCloseout: false, + }}, + {Model: models.ServiceMember{Affiliation: &airForce}}, + }, nil) + + suite.NotNil(origDutyLocationCONUS) + suite.NotNil(suite.toFetcher) + + officeCONUS, err := suite.toFetcher.FindClosestCounselingOffice(suite.AppContextForTest(), origDutyLocationCONUS.ID) + + suite.NoError(err) + suite.NotNil(officeCONUS) + suite.Equal("PPPO Jacksonville - USN", officeCONUS.Name) // Check for CONUS condition + }) + + // Test for OCONUS + suite.Run("success - find closest counseling office for OCONUS", func() { + customAddressOCONUS := models.Address{ + ID: uuid.Must(uuid.NewV4()), + StreetAddress1: "456 Yokota St", + City: "Yokota AB", + State: "Tokyo", + PostalCode: "197-0001", + County: "Japan", + IsOconus: models.BoolPointer(true), + } + suite.MustSave(&customAddressOCONUS) + army := models.AffiliationARMY + + origDutyLocationOCONUS := factory.BuildDutyLocation(suite.DB(), []factory.Customization{ + {Model: customAddressOCONUS, Type: &factory.Addresses.DutyLocationAddress}, + { + Model: models.DutyLocation{ + ProvidesServicesCounseling: false, + }, + }, + {Model: models.TransportationOffice{ + Name: "Yokota AB", + Gbloc: "JPN1", + ProvidesCloseout: true, + }}, + {Model: models.ServiceMember{Affiliation: &army}}, + }, nil) + + suite.NotNil(origDutyLocationOCONUS) + suite.NotNil(suite.toFetcher) + officeOCONUS, err := suite.toFetcher.FindClosestCounselingOffice(suite.AppContextForTest(), origDutyLocationOCONUS.ID) + suite.NoError(err) + suite.NotNil(officeOCONUS) + suite.Equal("Yokota AB - USN", officeOCONUS.Name) // Check for OCONUS condition + }) +} From faa41a8fd7133e118f89ef86c36ab6c37162ff92 Mon Sep 17 00:00:00 2001 From: Samay Sofo Date: Fri, 10 Jan 2025 12:43:10 +0000 Subject: [PATCH 06/28] Added test for CONUS/OCONUS for finding the closest counseling offices. --- .../mocks/TransportationOfficesFetcher.go | 34 +- .../transportation_office_fetcher.go | 2 +- .../transportation_office_fetcher_test.go | 532 ++++++++++++++++-- 3 files changed, 501 insertions(+), 67 deletions(-) diff --git a/pkg/services/mocks/TransportationOfficesFetcher.go b/pkg/services/mocks/TransportationOfficesFetcher.go index 754823af361..ca9277f5f9f 100644 --- a/pkg/services/mocks/TransportationOfficesFetcher.go +++ b/pkg/services/mocks/TransportationOfficesFetcher.go @@ -16,6 +16,34 @@ type TransportationOfficesFetcher struct { mock.Mock } +// FindClosestCounselingOffice provides a mock function with given fields: appCtx, dutyLocationID +func (_m *TransportationOfficesFetcher) FindClosestCounselingOffice(appCtx appcontext.AppContext, dutyLocationID uuid.UUID) (models.TransportationOffice, error) { + ret := _m.Called(appCtx, dutyLocationID) + + if len(ret) == 0 { + panic("no return value specified for FindClosestCounselingOffice") + } + + var r0 models.TransportationOffice + var r1 error + if rf, ok := ret.Get(0).(func(appcontext.AppContext, uuid.UUID) (models.TransportationOffice, error)); ok { + return rf(appCtx, dutyLocationID) + } + if rf, ok := ret.Get(0).(func(appcontext.AppContext, uuid.UUID) models.TransportationOffice); ok { + r0 = rf(appCtx, dutyLocationID) + } else { + r0 = ret.Get(0).(models.TransportationOffice) + } + + if rf, ok := ret.Get(1).(func(appcontext.AppContext, uuid.UUID) error); ok { + r1 = rf(appCtx, dutyLocationID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // GetAllGBLOCs provides a mock function with given fields: appCtx func (_m *TransportationOfficesFetcher) GetAllGBLOCs(appCtx appcontext.AppContext) (*models.GBLOCs, error) { ret := _m.Called(appCtx) @@ -136,12 +164,6 @@ func (_m *TransportationOfficesFetcher) GetTransportationOffices(appCtx appconte return r0, r1 } -func (_m *TransportationOfficesFetcher) FindClosestCounselingOffice(appCtx appcontext.AppContext, dutyLocationID uuid.UUID) (models.TransportationOffice, error) { - _m.GetCounselingOffices(appCtx, dutyLocationID) - //TODO: Fix - return models.TransportationOffice{}, nil -} - // NewTransportationOfficesFetcher creates a new instance of TransportationOfficesFetcher. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. // The first argument is typically a *testing.T value. func NewTransportationOfficesFetcher(t interface { diff --git a/pkg/services/transportation_office/transportation_office_fetcher.go b/pkg/services/transportation_office/transportation_office_fetcher.go index f1b565f4a3a..6ebb89837e4 100644 --- a/pkg/services/transportation_office/transportation_office_fetcher.go +++ b/pkg/services/transportation_office/transportation_office_fetcher.go @@ -307,7 +307,7 @@ func findOconusGblocDepartmentIndicator(appCtx appcontext.AppContext, dutyLocati serviceMember.Affiliation, dutyLocation.Name, *departmentIndicator, dutyLocation.Address.ID)) } -// Return the closeset transportation office in the GBLOC of the given duty location for oconus/cunus duty locations +// Return the closeset transportation office in the GBLOC of the given duty location for oconus/conus duty locations func (o transportationOfficesFetcher) FindClosestCounselingOffice(appCtx appcontext.AppContext, dutyLocationID uuid.UUID) (models.TransportationOffice, error) { var closestOffice models.TransportationOffice duty_location, err := models.FetchDutyLocation(appCtx.DB(), dutyLocationID) diff --git a/pkg/services/transportation_office/transportation_office_fetcher_test.go b/pkg/services/transportation_office/transportation_office_fetcher_test.go index 415fa3422ba..a18b64eb335 100644 --- a/pkg/services/transportation_office/transportation_office_fetcher_test.go +++ b/pkg/services/transportation_office/transportation_office_fetcher_test.go @@ -678,80 +678,492 @@ func (suite *TransportationOfficeServiceSuite) Test_GetTransportationOffice() { suite.Equal("OFFICE TWO", office2f.Name) } -func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOffices() { - // Test for CONUS - suite.Run("success - find closest counseling office for CONUS", func() { - customAddressCONUS := models.Address{ - ID: uuid.Must(uuid.NewV4()), - StreetAddress1: "123 Mayport St", - City: "NS Mayport", - State: "FL", - PostalCode: "32228", - County: "Duval", - IsOconus: models.BoolPointer(false), - } - suite.MustSave(&customAddressCONUS) - airForce := models.AffiliationAIRFORCE - - origDutyLocationCONUS := factory.BuildDutyLocation(suite.DB(), []factory.Customization{ - {Model: customAddressCONUS, Type: &factory.Addresses.DutyLocationAddress}, +func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeCONUS() { + suite.toFetcher = NewTransportationOfficesFetcher() + customAddress1 := models.Address{ + ID: uuid.Must(uuid.NewV4()), + StreetAddress1: "123 Mayport St", + City: "Mayport", + State: "FL", + PostalCode: "32228", + County: "Duval", + IsOconus: models.BoolPointer(false), + } + factory.BuildDutyLocation(suite.DB(), []factory.Customization{ + {Model: customAddress1, Type: &factory.Addresses.DutyLocationAddress}, + { + Model: models.DutyLocation{ + ProvidesServicesCounseling: false, + }, + }, + { + Model: models.TransportationOffice{ + Name: "PPPO Holloman AFB - USAF", + }, + }, + }, nil) + + customAddress2 := models.Address{ + ID: uuid.Must(uuid.NewV4()), + StreetAddress1: "123 Mayport St", + City: "Jacksonville", + State: "FL", + PostalCode: "32228", + County: "Duval", + IsOconus: models.BoolPointer(false), + } + factory.BuildDutyLocation(suite.DB(), []factory.Customization{ + {Model: customAddress2, Type: &factory.Addresses.DutyLocationAddress}, + { + Model: models.DutyLocation{ + ProvidesServicesCounseling: true, + }, + }, + { + Model: models.TransportationOffice{ + Name: "PPPO Jacksonville - USN", + }, + }, + }, nil) + + customAddress3 := models.Address{ + ID: uuid.Must(uuid.NewV4()), + StreetAddress1: "123 Mayport St", + City: "Palm Valley", + State: "FL", + PostalCode: "32228", + County: "Duval", + IsOconus: models.BoolPointer(false), + } + origDutyLocation := factory.BuildDutyLocation(suite.DB(), []factory.Customization{ + {Model: customAddress3, Type: &factory.Addresses.DutyLocationAddress}, + { + Model: models.DutyLocation{ + ProvidesServicesCounseling: true, + }, + }, + { + Model: models.TransportationOffice{ + Name: "PPPO Fort Moore - USA", + Gbloc: "CNNQ", + ProvidesCloseout: true, + }, + }, + }, nil) + + customAddress4 := models.Address{ + ID: uuid.Must(uuid.NewV4()), + StreetAddress1: "123 Mayport St", + City: "Fernandina", + State: "FL", + PostalCode: "32228", + County: "Duval", + IsOconus: models.BoolPointer(false), + } + factory.BuildDutyLocation(suite.DB(), []factory.Customization{ + {Model: customAddress4, Type: &factory.Addresses.DutyLocationAddress}, + { + Model: models.DutyLocation{ + ProvidesServicesCounseling: true, + }, + }, + { + Model: models.TransportationOffice{ + Name: "PPPO Fort Meade - USA", + Gbloc: "CNNQ", + ProvidesCloseout: true, + }, + }, + }, nil) + + offices, err := suite.toFetcher.FindClosestCounselingOffice(suite.AppContextForTest(), origDutyLocation.ID) + suite.NoError(err) + suite.Equal(offices.Name, "PPPO Jacksonville - USN") +} + +func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeOCONUS() { + testContractName := "Test_findOconusGblocDepartmentIndicator" + testContractCode := "Test_findOconusGblocDepartmentIndicator_Code" + testPostalCode := "32228" + testPostalCode2 := "99701" + testGbloc := "CNNQ" + testGbloc2 := "KKFA" + testTransportationName := "JPPSO - North West (JEAT) - USA" + testTransportationName2 := "PPPO Fort Belvoir - USA" + + serviceAffiliations := []models.ServiceMemberAffiliation{models.AffiliationARMY, + models.AffiliationNAVY, models.AffiliationMARINES, models.AffiliationAIRFORCE, models.AffiliationCOASTGUARD, + models.AffiliationSPACEFORCE} + + setupServiceMember := func(serviceMemberAffiliation models.ServiceMemberAffiliation) models.ServiceMember { + customServiceMember := models.ServiceMember{ + FirstName: models.StringPointer("John"), + LastName: models.StringPointer("Doe"), + Telephone: models.StringPointer("999-999-9999"), + SecondaryTelephone: models.StringPointer("123-555-9999"), + PersonalEmail: models.StringPointer("peyton@example.com"), + Edipi: models.StringPointer("1000011111"), + Affiliation: &serviceMemberAffiliation, + Suffix: models.StringPointer("Random suffix string"), + PhoneIsPreferred: models.BoolPointer(false), + EmailIsPreferred: models.BoolPointer(false), + } + + customAddress := models.Address{ + StreetAddress1: "987 Another Street", + } + + customUser := models.User{ + OktaEmail: "test_email@email.com", + } + + serviceMember := factory.BuildServiceMember(suite.DB(), []factory.Customization{ + {Model: customServiceMember}, + {Model: customAddress}, + {Model: customUser}, + }, nil) + + return serviceMember + } + + createContract := func(appCtx appcontext.AppContext, contractCode string, contractName string) (*models.ReContract, error) { + // See if contract code already exists. + exists, err := appCtx.DB().Where("code = ?", contractCode).Exists(&models.ReContract{}) + if err != nil { + return nil, fmt.Errorf("could not determine if contract code [%s] existed: %w", contractCode, err) + } + if exists { + return nil, fmt.Errorf("the provided contract code [%s] already exists", contractCode) + } + + // Contract code is new; insert it. + contract := models.ReContract{ + Code: contractCode, + Name: contractName, + } + verrs, err := appCtx.DB().ValidateAndSave(&contract) + if verrs.HasAny() { + return nil, fmt.Errorf("validation errors when saving contract [%+v]: %w", contract, verrs) + } + if err != nil { + return nil, fmt.Errorf("could not save contract [%+v]: %w", contract, err) + } + return &contract, nil + } + + setupDataForOconusSearchCounselingOffice := func(contract models.ReContract, postalCode string, gbloc string, transportationName string) (models.ReRateArea, models.OconusRateArea, models.UsPostRegionCity, models.DutyLocation) { + rateAreaCode := uuid.Must(uuid.NewV4()).String()[0:5] + rateArea := models.ReRateArea{ + ID: uuid.Must(uuid.NewV4()), + ContractID: contract.ID, + IsOconus: true, + Code: rateAreaCode, + Name: fmt.Sprintf("Alaska-%s", rateAreaCode), + Contract: contract, + } + verrs, err := suite.DB().ValidateAndCreate(&rateArea) + if verrs.HasAny() { + suite.Fail(verrs.Error()) + } + if err != nil { + suite.Fail(err.Error()) + } + + us_country, err := models.FetchCountryByCode(suite.DB(), "US") + suite.NotNil(us_country) + suite.Nil(err) + + usprc, err := models.FindByZipCode(suite.AppContextForTest().DB(), postalCode) + suite.NotNil(usprc) + suite.FatalNoError(err) + + oconusRateArea := models.OconusRateArea{ + ID: uuid.Must(uuid.NewV4()), + RateAreaId: rateArea.ID, + CountryId: us_country.ID, + UsPostRegionCityId: usprc.ID, + Active: true, + } + verrs, err = suite.DB().ValidateAndCreate(&oconusRateArea) + if verrs.HasAny() { + suite.Fail(verrs.Error()) + } + if err != nil { + suite.Fail(err.Error()) + } + + address := models.Address{ + StreetAddress1: "123 Ocunus St.", + City: "Fairbanks", + State: "AK", + PostalCode: postalCode, + County: "Fairbanks North Star Borough", + IsOconus: models.BoolPointer(true), + UsPostRegionCityId: &usprc.ID, + CountryId: models.UUIDPointer(us_country.ID), + } + suite.MustSave(&address) + + origDutyLocation := factory.BuildDutyLocation(suite.DB(), []factory.Customization{ { Model: models.DutyLocation{ - ProvidesServicesCounseling: false, + AddressID: address.ID, + ProvidesServicesCounseling: true, + }, + }, + { + Model: models.TransportationOffice{ + Name: transportationName, + Gbloc: gbloc, + ProvidesCloseout: true, }, }, - {Model: models.TransportationOffice{ - Name: "NS Mayport", - Gbloc: "CNNQ", - ProvidesCloseout: false, - }}, - {Model: models.ServiceMember{Affiliation: &airForce}}, }, nil) + suite.MustSave(&origDutyLocation) + found_duty_location, _ := models.FetchDutyLocation(suite.DB(), origDutyLocation.ID) + return rateArea, oconusRateArea, *usprc, found_duty_location + } + + suite.Run("success - findOconusGblocDepartmentIndicator - returns default GLOC for departmentAffiliation if no specific departmentAffilation mapping is defined", func() { + contract, err := createContract(suite.AppContextForTest(), testContractCode, testContractName) + suite.NotNil(contract) + suite.FatalNoError(err) + + const fairbanksAlaskaPostalCode = "99790" + _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(*contract, fairbanksAlaskaPostalCode, testGbloc, testTransportationName) + + // setup department affiliation to GBLOC mappings + expected_gbloc := "TEST-GBLOC" + jppsoRegion := models.JppsoRegions{ + Code: expected_gbloc, + Name: "TEST PPM", + } + suite.MustSave(&jppsoRegion) - suite.NotNil(origDutyLocationCONUS) - suite.NotNil(suite.toFetcher) + gblocAors := models.GblocAors{ + JppsoRegionID: jppsoRegion.ID, + OconusRateAreaID: oconusRateArea.ID, + // DepartmentIndicator is nil, + } + suite.MustSave(&gblocAors) - officeCONUS, err := suite.toFetcher.FindClosestCounselingOffice(suite.AppContextForTest(), origDutyLocationCONUS.ID) + serviceAffiliations := []models.ServiceMemberAffiliation{models.AffiliationARMY, + models.AffiliationNAVY, models.AffiliationMARINES, models.AffiliationAIRFORCE, models.AffiliationCOASTGUARD, + models.AffiliationSPACEFORCE} - suite.NoError(err) - suite.NotNil(officeCONUS) - suite.Equal("PPPO Jacksonville - USN", officeCONUS.Name) // Check for CONUS condition + // loop through and make sure all branches are using expected default GBLOC + for _, affiliation := range serviceAffiliations { + serviceMember := setupServiceMember(affiliation) + appCtx := suite.AppContextWithSessionForTest(&auth.Session{ + ServiceMemberID: serviceMember.ID, + }) + suite.Nil(err) + departmentIndictor, err := findOconusGblocDepartmentIndicator(appCtx, dutylocation) + suite.NotNil(departmentIndictor) + suite.Nil(err) + suite.Nil(departmentIndictor.DepartmentIndicator) + suite.Equal(expected_gbloc, departmentIndictor.Gbloc) + } }) - // Test for OCONUS - suite.Run("success - find closest counseling office for OCONUS", func() { - customAddressOCONUS := models.Address{ - ID: uuid.Must(uuid.NewV4()), - StreetAddress1: "456 Yokota St", - City: "Yokota AB", - State: "Tokyo", - PostalCode: "197-0001", - County: "Japan", - IsOconus: models.BoolPointer(true), - } - suite.MustSave(&customAddressOCONUS) - army := models.AffiliationARMY - - origDutyLocationOCONUS := factory.BuildDutyLocation(suite.DB(), []factory.Customization{ - {Model: customAddressOCONUS, Type: &factory.Addresses.DutyLocationAddress}, + suite.Run("Success - findOconusGblocDepartmentIndicator - Should return specific GLOC for departmentAffiliation when a specific departmentAffilation mapping is defined", func() { + contract, err := createContract(suite.AppContextForTest(), testContractCode, testContractName) + suite.NotNil(contract) + suite.FatalNoError(err) + + _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(*contract, testPostalCode, testGbloc, testTransportationName) + + departmentIndicators := []models.DepartmentIndicator{models.DepartmentIndicatorARMY, + models.DepartmentIndicatorARMYCORPSOFENGINEERS, models.DepartmentIndicatorCOASTGUARD, + models.DepartmentIndicatorNAVYANDMARINES, models.DepartmentIndicatorAIRANDSPACEFORCE} + + expectedAffiliationToDepartmentIndicatorMap := make(map[string]string, 0) + expectedAffiliationToDepartmentIndicatorMap[models.AffiliationARMY.String()] = models.DepartmentIndicatorARMY.String() + expectedAffiliationToDepartmentIndicatorMap[models.AffiliationNAVY.String()] = models.DepartmentIndicatorNAVYANDMARINES.String() + expectedAffiliationToDepartmentIndicatorMap[models.AffiliationMARINES.String()] = models.DepartmentIndicatorNAVYANDMARINES.String() + expectedAffiliationToDepartmentIndicatorMap[models.AffiliationAIRFORCE.String()] = models.DepartmentIndicatorAIRANDSPACEFORCE.String() + expectedAffiliationToDepartmentIndicatorMap[models.AffiliationCOASTGUARD.String()] = models.DepartmentIndicatorCOASTGUARD.String() + expectedAffiliationToDepartmentIndicatorMap[models.AffiliationSPACEFORCE.String()] = models.DepartmentIndicatorAIRANDSPACEFORCE.String() + + // setup department affiliation to GBLOC mappings + expected_gbloc := "TEST-GBLOC" + jppsoRegion := models.JppsoRegions{ + Code: expected_gbloc, + Name: "TEST PPM", + } + suite.MustSave(&jppsoRegion) + + defaultGblocAors := models.GblocAors{ + JppsoRegionID: jppsoRegion.ID, + OconusRateAreaID: oconusRateArea.ID, + //DepartmentIndicator is nil, + } + suite.MustSave(&defaultGblocAors) + + // setup specific departmentAffiliation mapping for each branch + for _, departmentIndicator := range departmentIndicators { + gblocAors := models.GblocAors{ + JppsoRegionID: jppsoRegion.ID, + OconusRateAreaID: oconusRateArea.ID, + DepartmentIndicator: models.StringPointer(departmentIndicator.String()), + } + suite.MustSave(&gblocAors) + } + + // loop through and make sure all branches are using it's own dedicated GBLOC and not default + for _, affiliation := range serviceAffiliations { + serviceMember := setupServiceMember(affiliation) + appCtx := suite.AppContextWithSessionForTest(&auth.Session{ + ServiceMemberID: serviceMember.ID, + }) + suite.Nil(err) + departmentIndictor, err := findOconusGblocDepartmentIndicator(appCtx, dutylocation) + suite.NotNil(departmentIndictor) + suite.Nil(err) + suite.NotNil(departmentIndictor.DepartmentIndicator) + if match, ok := expectedAffiliationToDepartmentIndicatorMap[affiliation.String()]; ok { + // verify service member's affiliation matches on specific departmentIndicator mapping record + suite.Equal(match, *departmentIndictor.DepartmentIndicator) + } else { + suite.Fail(fmt.Sprintf("key does not exist for %s", affiliation.String())) + } + suite.Equal(expected_gbloc, departmentIndictor.Gbloc) + } + }) + + suite.Run("success - offices using default departmentIndicator mapping", func() { + contract, err := createContract(suite.AppContextForTest(), testContractCode, testContractName) + suite.NotNil(contract) + suite.FatalNoError(err) + + _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(*contract, testPostalCode, testGbloc, testTransportationName) + + // setup department affiliation to GBLOC mappings + jppsoRegion := models.JppsoRegions{ + Code: testGbloc, + Name: "TEST PPM", + } + suite.MustSave(&jppsoRegion) + + gblocAors := models.GblocAors{ + JppsoRegionID: jppsoRegion.ID, + OconusRateAreaID: oconusRateArea.ID, + } + suite.MustSave(&gblocAors) + + postalCodeToGBLOC := models.PostalCodeToGBLOC{ + PostalCode: testPostalCode, + GBLOC: testGbloc, + CreatedAt: time.Now(), + UpdatedAt: time.Now(), + } + suite.MustSave(&postalCodeToGBLOC) + + serviceMember := setupServiceMember(models.AffiliationAIRFORCE) + appCtx := suite.AppContextWithSessionForTest(&auth.Session{ + ServiceMemberID: serviceMember.ID, + }) + + suite.Nil(err) + offices, err := findCounselingOffice(appCtx, dutylocation.ID) + suite.NotNil(offices) + suite.Nil(err) + suite.Equal(1, len(offices)) + suite.Equal(testTransportationName, offices[0].Name) + + factory.BuildTransportationOffice(suite.DB(), []factory.Customization{ { - Model: models.DutyLocation{ - ProvidesServicesCounseling: false, + Model: models.TransportationOffice{ + Name: testTransportationName2, + ProvidesCloseout: true, + Gbloc: testGbloc, + }, + }, + }, nil) + offices, err = findCounselingOffice(appCtx, dutylocation.ID) + suite.NotNil(offices) + suite.Nil(err) + suite.Equal(2, len(offices)) + }) + + suite.Run("Should return correct office based on service affiliation", func() { + contract, err := createContract(suite.AppContextForTest(), testContractCode, testContractName) + suite.NotNil(contract) + suite.FatalNoError(err) + + _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(*contract, testPostalCode, testGbloc, testTransportationName) + + jppsoRegion_AFSF := models.JppsoRegions{ + Code: testGbloc, + Name: "TEST PPO", + } + suite.MustSave(&jppsoRegion_AFSF) + + gblocAors_AFSF := models.GblocAors{ + JppsoRegionID: jppsoRegion_AFSF.ID, + OconusRateAreaID: oconusRateArea.ID, + DepartmentIndicator: models.StringPointer(models.DepartmentIndicatorAIRANDSPACEFORCE.String()), + } + suite.MustSave(&gblocAors_AFSF) + + postalCodeToGBLOC_AFSF := models.PostalCodeToGBLOC{ + PostalCode: testPostalCode, + GBLOC: testGbloc, + CreatedAt: time.Now(), + UpdatedAt: time.Now(), + } + suite.MustSave(&postalCodeToGBLOC_AFSF) + + jppsoRegion_not_AFSF := models.JppsoRegions{ + Code: testGbloc2, + Name: "TEST PPO 2", + } + suite.MustSave(&jppsoRegion_not_AFSF) + + gblocAors_not_AFSF := models.GblocAors{ + JppsoRegionID: jppsoRegion_not_AFSF.ID, + OconusRateAreaID: oconusRateArea.ID, + } + suite.MustSave(&gblocAors_not_AFSF) + + postalCodeToGBLOC_not_AFSF := models.PostalCodeToGBLOC{ + PostalCode: testPostalCode2, + GBLOC: testGbloc2, + CreatedAt: time.Now(), + UpdatedAt: time.Now(), + } + suite.MustSave(&postalCodeToGBLOC_not_AFSF) + + // add transportation office for other branches not AF/SF + factory.BuildTransportationOffice(suite.DB(), []factory.Customization{ + { + Model: models.TransportationOffice{ + Name: testTransportationName2, + ProvidesCloseout: true, + Gbloc: testGbloc2, }, }, - {Model: models.TransportationOffice{ - Name: "Yokota AB", - Gbloc: "JPN1", - ProvidesCloseout: true, - }}, - {Model: models.ServiceMember{Affiliation: &army}}, }, nil) - suite.NotNil(origDutyLocationOCONUS) - suite.NotNil(suite.toFetcher) - officeOCONUS, err := suite.toFetcher.FindClosestCounselingOffice(suite.AppContextForTest(), origDutyLocationOCONUS.ID) - suite.NoError(err) - suite.NotNil(officeOCONUS) - suite.Equal("Yokota AB - USN", officeOCONUS.Name) // Check for OCONUS condition + for _, affiliation := range serviceAffiliations { + serviceMember := setupServiceMember(affiliation) + if affiliation == models.AffiliationAIRFORCE || affiliation == models.AffiliationSPACEFORCE { + appCtx := suite.AppContextWithSessionForTest(&auth.Session{ + ServiceMemberID: serviceMember.ID, + }) + offices, err := suite.toFetcher.FindClosestCounselingOffice(appCtx, dutylocation.ID) + suite.NotNil(offices) + suite.Nil(err) + suite.Equal(testTransportationName, offices.Name) + } else { + appCtx := suite.AppContextWithSessionForTest(&auth.Session{ + ServiceMemberID: serviceMember.ID, + }) + offices, err := suite.toFetcher.FindClosestCounselingOffice(appCtx, dutylocation.ID) + suite.NotNil(offices) + suite.Nil(err) + suite.Equal(testTransportationName2, offices.Name) + } + } }) } From c70c798d8b05e810becfed343c076b9299d59748 Mon Sep 17 00:00:00 2001 From: Samay Sofo Date: Fri, 10 Jan 2025 14:41:35 +0000 Subject: [PATCH 07/28] merged main and refactored refactored failing tests --- .../mto_service_item/mto_service_item_creator_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/services/mto_service_item/mto_service_item_creator_test.go b/pkg/services/mto_service_item/mto_service_item_creator_test.go index bb797d0451a..cd18573a069 100644 --- a/pkg/services/mto_service_item/mto_service_item_creator_test.go +++ b/pkg/services/mto_service_item/mto_service_item_creator_test.go @@ -2109,7 +2109,7 @@ func (suite *MTOServiceItemServiceSuite) TestPriceEstimator() { } builder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &mocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), @@ -2409,7 +2409,7 @@ func (suite *MTOServiceItemServiceSuite) TestPriceEstimator() { } builder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() + moveRouter := moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &mocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), From ec9946b34e5988de48c0dec917589abbac5ad9d3 Mon Sep 17 00:00:00 2001 From: Samay Sofo Date: Mon, 13 Jan 2025 17:10:21 +0000 Subject: [PATCH 08/28] fixed failing tests for disabling the counseling checkbox --- .../Office/RequestedShipments/RequestedShipments.test.jsx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/components/Office/RequestedShipments/RequestedShipments.test.jsx b/src/components/Office/RequestedShipments/RequestedShipments.test.jsx index 8fdd77d5f51..3ba0372039f 100644 --- a/src/components/Office/RequestedShipments/RequestedShipments.test.jsx +++ b/src/components/Office/RequestedShipments/RequestedShipments.test.jsx @@ -667,7 +667,7 @@ describe('RequestedShipments', () => { expect(screen.getByTestId('counselingFee')).toBeInTheDocument(); }); - it('does not render the "Add service items to move" section or Counseling option when all shipments are PPM', () => { + it('should disable the counseling checkbox when full ppm shipment', () => { const testPropsServiceItemsEmpty = { mtoServiceItems: serviceItemsEmpty, mtoShipments: ppmOnlyShipments, @@ -675,10 +675,9 @@ describe('RequestedShipments', () => { }; renderComponent(testPropsServiceItemsEmpty); - expect(screen.queryByText('Add service items to this move')).not.toBeInTheDocument(); + expect(screen.queryByText('Add service items to this move')).toBeInTheDocument(); expect(screen.getByText('Approve selected')).toBeInTheDocument(); - expect(screen.queryByTestId('shipmentManagementFee')).not.toBeInTheDocument(); - expect(screen.queryByTestId('counselingFee')).not.toBeInTheDocument(); + expect(screen.queryByTestId('counselingFee')).toBeDisabled(); }); }); }); From 63555bb8861e707485a2bd2bd53e832a98b177a0 Mon Sep 17 00:00:00 2001 From: Samay Sofo Date: Mon, 13 Jan 2025 18:22:44 +0000 Subject: [PATCH 09/28] updated failing tests --- .../SubmittedRequestedShipments.test.jsx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/components/Office/RequestedShipments/SubmittedRequestedShipments.test.jsx b/src/components/Office/RequestedShipments/SubmittedRequestedShipments.test.jsx index 1388bdf84e4..30ec9358f6f 100644 --- a/src/components/Office/RequestedShipments/SubmittedRequestedShipments.test.jsx +++ b/src/components/Office/RequestedShipments/SubmittedRequestedShipments.test.jsx @@ -177,7 +177,7 @@ describe('RequestedShipments', () => { moveCode: 'TE5TC0DE', }; - it('does not render the "Add service items to move" section or Counseling option when all shipments are PPM', () => { + it('should disable the counseling checkbox when full ppm shipment', () => { const testPropsServiceItemsEmpty = { mtoServiceItems: serviceItemsEmpty, mtoShipments: ppmOnlyShipments, @@ -185,10 +185,9 @@ describe('RequestedShipments', () => { }; renderComponent(testPropsServiceItemsEmpty); - expect(screen.queryByText('Add service items to this move')).not.toBeInTheDocument(); + expect(screen.queryByText('Add service items to this move')).toBeInTheDocument(); expect(screen.getByText('Approve selected')).toBeInTheDocument(); - expect(screen.queryByTestId('shipmentManagementFee')).not.toBeInTheDocument(); - expect(screen.queryByTestId('counselingFee')).not.toBeInTheDocument(); + expect(screen.queryByTestId('counselingFee')).toBeDisabled(); }); }); }); From f946703b210248e8429b13d3fd3a1b33ae9c305b Mon Sep 17 00:00:00 2001 From: Samay Sofo Date: Wed, 22 Jan 2025 10:42:30 +0000 Subject: [PATCH 10/28] fixed suggested comments from pr. --- .../mocks/TransportationOfficesFetcher.go | 12 +-- pkg/services/move/move_router.go | 2 +- pkg/services/transportation_office.go | 2 +- .../transportation_office_fetcher.go | 16 ++-- .../transportation_office_fetcher_test.go | 89 +++++-------------- .../RequestedShipments.test.jsx | 2 +- .../SubmittedRequestedShipments.test.jsx | 2 +- 7 files changed, 40 insertions(+), 85 deletions(-) diff --git a/pkg/services/mocks/TransportationOfficesFetcher.go b/pkg/services/mocks/TransportationOfficesFetcher.go index ca9277f5f9f..47f5a5f9477 100644 --- a/pkg/services/mocks/TransportationOfficesFetcher.go +++ b/pkg/services/mocks/TransportationOfficesFetcher.go @@ -17,22 +17,24 @@ type TransportationOfficesFetcher struct { } // FindClosestCounselingOffice provides a mock function with given fields: appCtx, dutyLocationID -func (_m *TransportationOfficesFetcher) FindClosestCounselingOffice(appCtx appcontext.AppContext, dutyLocationID uuid.UUID) (models.TransportationOffice, error) { +func (_m *TransportationOfficesFetcher) FindClosestCounselingOffice(appCtx appcontext.AppContext, dutyLocationID uuid.UUID) (*models.TransportationOffice, error) { ret := _m.Called(appCtx, dutyLocationID) if len(ret) == 0 { panic("no return value specified for FindClosestCounselingOffice") } - var r0 models.TransportationOffice + var r0 *models.TransportationOffice var r1 error - if rf, ok := ret.Get(0).(func(appcontext.AppContext, uuid.UUID) (models.TransportationOffice, error)); ok { + if rf, ok := ret.Get(0).(func(appcontext.AppContext, uuid.UUID) (*models.TransportationOffice, error)); ok { return rf(appCtx, dutyLocationID) } - if rf, ok := ret.Get(0).(func(appcontext.AppContext, uuid.UUID) models.TransportationOffice); ok { + if rf, ok := ret.Get(0).(func(appcontext.AppContext, uuid.UUID) *models.TransportationOffice); ok { r0 = rf(appCtx, dutyLocationID) } else { - r0 = ret.Get(0).(models.TransportationOffice) + if ret.Get(0) != nil { + r0 = ret.Get(0).(*models.TransportationOffice) + } } if rf, ok := ret.Get(1).(func(appcontext.AppContext, uuid.UUID) error); ok { diff --git a/pkg/services/move/move_router.go b/pkg/services/move/move_router.go index 9b47f5b5d48..ce706240b69 100644 --- a/pkg/services/move/move_router.go +++ b/pkg/services/move/move_router.go @@ -238,7 +238,7 @@ func (router moveRouter) sendToServiceCounselor(appCtx appcontext.AppContext, mo appCtx.Logger().Error(msg, zap.Error(err)) return apperror.NewQueryError("Closest Counseling Office", err, "Failed to find counseling office that provides counseling") } - move.CounselingOffice = &closestCounselingOffice + move.CounselingOffice = closestCounselingOffice } if verrs, err := appCtx.DB().ValidateAndUpdate(&move.MTOShipments[i]); verrs.HasAny() || err != nil { diff --git a/pkg/services/transportation_office.go b/pkg/services/transportation_office.go index a0d5cd95b8c..f8cc2cf3afa 100644 --- a/pkg/services/transportation_office.go +++ b/pkg/services/transportation_office.go @@ -13,5 +13,5 @@ type TransportationOfficesFetcher interface { GetTransportationOffice(appCtx appcontext.AppContext, transportationOfficeID uuid.UUID, includeOnlyPPMCloseoutOffices bool) (*models.TransportationOffice, error) GetAllGBLOCs(appCtx appcontext.AppContext) (*models.GBLOCs, error) GetCounselingOffices(appCtx appcontext.AppContext, dutyLocationID uuid.UUID) (*models.TransportationOffices, error) - FindClosestCounselingOffice(appCtx appcontext.AppContext, dutyLocationID uuid.UUID) (models.TransportationOffice, error) + FindClosestCounselingOffice(appCtx appcontext.AppContext, dutyLocationID uuid.UUID) (*models.TransportationOffice, error) } diff --git a/pkg/services/transportation_office/transportation_office_fetcher.go b/pkg/services/transportation_office/transportation_office_fetcher.go index 6ebb89837e4..0e9948752c7 100644 --- a/pkg/services/transportation_office/transportation_office_fetcher.go +++ b/pkg/services/transportation_office/transportation_office_fetcher.go @@ -307,13 +307,13 @@ func findOconusGblocDepartmentIndicator(appCtx appcontext.AppContext, dutyLocati serviceMember.Affiliation, dutyLocation.Name, *departmentIndicator, dutyLocation.Address.ID)) } -// Return the closeset transportation office in the GBLOC of the given duty location for oconus/conus duty locations -func (o transportationOfficesFetcher) FindClosestCounselingOffice(appCtx appcontext.AppContext, dutyLocationID uuid.UUID) (models.TransportationOffice, error) { +// Return the closest transportation office in the GBLOC of the given duty location for oconus/conus duty locations +func (o transportationOfficesFetcher) FindClosestCounselingOffice(appCtx appcontext.AppContext, dutyLocationID uuid.UUID) (*models.TransportationOffice, error) { var closestOffice models.TransportationOffice duty_location, err := models.FetchDutyLocation(appCtx.DB(), dutyLocationID) if err != nil { appCtx.Logger().Error("Failed to fetch duty location", zap.Error(err)) - return closestOffice, err + return &closestOffice, err } var sqlQuery string @@ -322,7 +322,7 @@ func (o transportationOfficesFetcher) FindClosestCounselingOffice(appCtx appcont gblocDepartmentIndicator, err := findOconusGblocDepartmentIndicator(appCtx, duty_location) if err != nil { appCtx.Logger().Error("Failed to find OCONUS GBLOC department indicator", zap.Error(err)) - return closestOffice, err + return &closestOffice, err } sqlQuery = ` @@ -357,10 +357,10 @@ func (o transportationOfficesFetcher) FindClosestCounselingOffice(appCtx appcont if err := appCtx.DB().Q().RawQuery(sqlQuery, dutyLocationID, gblocDepartmentIndicator.Gbloc).First(&closestOffice); err != nil { appCtx.Logger().Error("Failed to execute OCONUS SQL query", zap.Error(err)) if errors.Cause(err).Error() != models.RecordNotFoundErrorString { - return closestOffice, err + return &closestOffice, err } } - return closestOffice, nil + return &closestOffice, nil } else { // Find for conus duty location @@ -391,10 +391,10 @@ func (o transportationOfficesFetcher) FindClosestCounselingOffice(appCtx appcont if err := appCtx.DB().Q().RawQuery(sqlQuery, dutyLocationID).First(&closestOffice); err != nil { appCtx.Logger().Error("Failed to execute CONUS SQL query", zap.Error(err)) if errors.Cause(err).Error() != models.RecordNotFoundErrorString { - return closestOffice, err + return &closestOffice, err } } } - return closestOffice, nil + return &closestOffice, nil } diff --git a/pkg/services/transportation_office/transportation_office_fetcher_test.go b/pkg/services/transportation_office/transportation_office_fetcher_test.go index cca4d4c6fd5..a1f47237cd9 100644 --- a/pkg/services/transportation_office/transportation_office_fetcher_test.go +++ b/pkg/services/transportation_office/transportation_office_fetcher_test.go @@ -680,17 +680,12 @@ func (suite *TransportationOfficeServiceSuite) Test_GetTransportationOffice() { func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeCONUS() { suite.toFetcher = NewTransportationOfficesFetcher() - customAddress1 := models.Address{ - ID: uuid.Must(uuid.NewV4()), - StreetAddress1: "123 Mayport St", - City: "Mayport", - State: "FL", - PostalCode: "32228", - County: models.StringPointer("Duval"), - IsOconus: models.BoolPointer(false), - } factory.BuildDutyLocation(suite.DB(), []factory.Customization{ - {Model: customAddress1, Type: &factory.Addresses.DutyLocationAddress}, + {Model: models.Address{ + ID: uuid.Must(uuid.NewV4()), + PostalCode: "32228", + IsOconus: models.BoolPointer(false), + }, Type: &factory.Addresses.DutyLocationAddress}, { Model: models.DutyLocation{ ProvidesServicesCounseling: false, @@ -702,18 +697,11 @@ func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeC }, }, }, nil) - - customAddress2 := models.Address{ - ID: uuid.Must(uuid.NewV4()), - StreetAddress1: "123 Mayport St", - City: "Jacksonville", - State: "FL", - PostalCode: "32228", - County: models.StringPointer("Duval"), - IsOconus: models.BoolPointer(false), - } factory.BuildDutyLocation(suite.DB(), []factory.Customization{ - {Model: customAddress2, Type: &factory.Addresses.DutyLocationAddress}, + {Model: models.Address{ + PostalCode: "32228", + IsOconus: models.BoolPointer(false), + }, Type: &factory.Addresses.DutyLocationAddress}, { Model: models.DutyLocation{ ProvidesServicesCounseling: true, @@ -725,18 +713,12 @@ func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeC }, }, }, nil) - - customAddress3 := models.Address{ - ID: uuid.Must(uuid.NewV4()), - StreetAddress1: "123 Mayport St", - City: "Palm Valley", - State: "FL", - PostalCode: "32228", - County: models.StringPointer("Duval"), - IsOconus: models.BoolPointer(false), - } origDutyLocation := factory.BuildDutyLocation(suite.DB(), []factory.Customization{ - {Model: customAddress3, Type: &factory.Addresses.DutyLocationAddress}, + {Model: models.Address{ + ID: uuid.Must(uuid.NewV4()), + PostalCode: "32228", + IsOconus: models.BoolPointer(false), + }, Type: &factory.Addresses.DutyLocationAddress}, { Model: models.DutyLocation{ ProvidesServicesCounseling: true, @@ -750,18 +732,11 @@ func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeC }, }, }, nil) - - customAddress4 := models.Address{ - ID: uuid.Must(uuid.NewV4()), - StreetAddress1: "123 Mayport St", - City: "Fernandina", - State: "FL", - PostalCode: "32228", - County: models.StringPointer("Duval"), - IsOconus: models.BoolPointer(false), - } factory.BuildDutyLocation(suite.DB(), []factory.Customization{ - {Model: customAddress4, Type: &factory.Addresses.DutyLocationAddress}, + {Model: models.Address{ + PostalCode: "32228", + IsOconus: models.BoolPointer(false), + }, Type: &factory.Addresses.DutyLocationAddress}, { Model: models.DutyLocation{ ProvidesServicesCounseling: true, @@ -796,31 +771,10 @@ func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeO models.AffiliationSPACEFORCE} setupServiceMember := func(serviceMemberAffiliation models.ServiceMemberAffiliation) models.ServiceMember { - customServiceMember := models.ServiceMember{ - FirstName: models.StringPointer("John"), - LastName: models.StringPointer("Doe"), - Telephone: models.StringPointer("999-999-9999"), - SecondaryTelephone: models.StringPointer("123-555-9999"), - PersonalEmail: models.StringPointer("peyton@example.com"), - Edipi: models.StringPointer("1000011111"), - Affiliation: &serviceMemberAffiliation, - Suffix: models.StringPointer("Random suffix string"), - PhoneIsPreferred: models.BoolPointer(false), - EmailIsPreferred: models.BoolPointer(false), - } - - customAddress := models.Address{ - StreetAddress1: "987 Another Street", - } - - customUser := models.User{ - OktaEmail: "test_email@email.com", - } - serviceMember := factory.BuildServiceMember(suite.DB(), []factory.Customization{ - {Model: customServiceMember}, - {Model: customAddress}, - {Model: customUser}, + {Model: models.ServiceMember{ + Affiliation: &serviceMemberAffiliation, + }}, }, nil) return serviceMember @@ -919,7 +873,6 @@ func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeO }, }, }, nil) - suite.MustSave(&origDutyLocation) found_duty_location, _ := models.FetchDutyLocation(suite.DB(), origDutyLocation.ID) return rateArea, oconusRateArea, *usprc, found_duty_location } diff --git a/src/components/Office/RequestedShipments/RequestedShipments.test.jsx b/src/components/Office/RequestedShipments/RequestedShipments.test.jsx index 3ba0372039f..99b9c4be671 100644 --- a/src/components/Office/RequestedShipments/RequestedShipments.test.jsx +++ b/src/components/Office/RequestedShipments/RequestedShipments.test.jsx @@ -667,7 +667,7 @@ describe('RequestedShipments', () => { expect(screen.getByTestId('counselingFee')).toBeInTheDocument(); }); - it('should disable the counseling checkbox when full ppm shipment', () => { + it('should disable the counseling checkbox when all shipments are PPM', () => { const testPropsServiceItemsEmpty = { mtoServiceItems: serviceItemsEmpty, mtoShipments: ppmOnlyShipments, diff --git a/src/components/Office/RequestedShipments/SubmittedRequestedShipments.test.jsx b/src/components/Office/RequestedShipments/SubmittedRequestedShipments.test.jsx index 30ec9358f6f..68e7e6e6964 100644 --- a/src/components/Office/RequestedShipments/SubmittedRequestedShipments.test.jsx +++ b/src/components/Office/RequestedShipments/SubmittedRequestedShipments.test.jsx @@ -177,7 +177,7 @@ describe('RequestedShipments', () => { moveCode: 'TE5TC0DE', }; - it('should disable the counseling checkbox when full ppm shipment', () => { + it('should disable the counseling checkbox when all shipments are PPM', () => { const testPropsServiceItemsEmpty = { mtoServiceItems: serviceItemsEmpty, mtoShipments: ppmOnlyShipments, From 48d0e9be92324368dfdf01101676d360eec8a5c5 Mon Sep 17 00:00:00 2001 From: Samay Sofo Date: Wed, 22 Jan 2025 12:08:25 +0000 Subject: [PATCH 11/28] Added test to to move router for ppm --- pkg/services/move/move_router_test.go | 72 +++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/pkg/services/move/move_router_test.go b/pkg/services/move/move_router_test.go index 89d6d6f351d..f62d3865f00 100644 --- a/pkg/services/move/move_router_test.go +++ b/pkg/services/move/move_router_test.go @@ -990,6 +990,78 @@ func (suite *MoveServiceSuite) TestMoveSubmission() { suite.Contains(err.Error(), expError) suite.Equal(models.MoveStatusNeedsServiceCounseling, move.Status, "expected move to still be in NEEDS_SERVICE_COUNSELING status when routing has failed") }) + + suite.Run("SignedCirtification created, Route PPM moves to the closest service counseling office and set status to NEEDS SERVICE COUNSELING", func() { + // Under test: MoveRouter.Submit Full PPM should route to service counselor + // Set up: Create moves and SignedCertification + // Expected outcome: signed cert is created + // Expected outcome: Move status is set to needs service counseling + tests := []struct { + desc string + ProvidesServicesCounseling bool + moveStatus models.MoveStatus + }{ + {"Routes to Service Counseling", true, models.MoveStatusNeedsServiceCounseling}, + {"Routes to Service Counseling", false, models.MoveStatusNeedsServiceCounseling}, + } + for _, tt := range tests { + suite.Run(tt.desc, func() { + move := factory.BuildMove(suite.DB(), []factory.Customization{ + { + Model: models.DutyLocation{ + ProvidesServicesCounseling: tt.ProvidesServicesCounseling, + }, + Type: &factory.DutyLocations.OriginDutyLocation, + }, + { + Model: models.Move{ + Status: models.MoveStatusDRAFT, + }, + }, + }, nil) + + shipment := factory.BuildMTOShipmentMinimal(suite.DB(), []factory.Customization{ + { + Model: models.MTOShipment{ + Status: models.MTOShipmentStatusDraft, + ShipmentType: models.MTOShipmentTypePPM, + }, + }, + { + Model: move, + LinkOnly: true, + }, + }, nil) + + ppmShipment := factory.BuildPPMShipment(suite.DB(), []factory.Customization{ + { + Model: models.PPMShipment{ + Status: models.PPMShipmentStatusDraft, + }, + }, + }, nil) + + move.MTOShipments = models.MTOShipments{shipment} + move.MTOShipments[0].PPMShipment = &ppmShipment + + newSignedCertification := factory.BuildSignedCertification(nil, []factory.Customization{ + { + Model: move, + LinkOnly: true, + }, + }, nil) + err := moveRouter.Submit(suite.AppContextForTest(), &move, &newSignedCertification) + suite.NoError(err) + err = suite.DB().Where("move_id = $1", move.ID).First(&newSignedCertification) + suite.NoError(err) + suite.NotNil(newSignedCertification) + + err = suite.DB().Find(&move, move.ID) + suite.NoError(err) + suite.Equal(tt.moveStatus, move.Status) + }) + } + }) } func (suite *MoveServiceSuite) TestMoveCancellation() { From c7c50989b48229b5fc19b45c6dea2a63f3c1577a Mon Sep 17 00:00:00 2001 From: Samay Sofo Date: Mon, 27 Jan 2025 21:19:47 +0000 Subject: [PATCH 12/28] added provides counseling services to oconus sql --- .../transportation_office/transportation_office_fetcher.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/services/transportation_office/transportation_office_fetcher.go b/pkg/services/transportation_office/transportation_office_fetcher.go index 0e9948752c7..4e46b1a7162 100644 --- a/pkg/services/transportation_office/transportation_office_fetcher.go +++ b/pkg/services/transportation_office/transportation_office_fetcher.go @@ -337,7 +337,7 @@ func (o transportationOfficesFetcher) FindClosestCounselingOffice(appCtx appcont JOIN jppso_regions j ON gbloc_aors.jppso_regions_id = j.id JOIN transportation_offices ON j.code = transportation_offices.gbloc JOIN addresses a2 ON a2.id = transportation_offices.address_id - WHERE duty_locations.id = $1 AND j.code = $2 + WHERE duty_locations.provides_services_counseling = true and duty_locations.id = $1 AND j.code = $2 AND transportation_offices.provides_ppm_closeout = true ) SELECT counseling_offices.id, counseling_offices.name @@ -371,7 +371,7 @@ func (o transportationOfficesFetcher) FindClosestCounselingOffice(appCtx appcont JOIN addresses ON postal_code_to_gblocs.postal_code = addresses.postal_code JOIN duty_locations ON addresses.id = duty_locations.address_id JOIN transportation_offices ON postal_code_to_gblocs.gbloc = transportation_offices.gbloc - WHERE duty_locations.id = $1 + WHERE duty_locations.provides_services_counseling = true and duty_locations.id = $1 ) SELECT counseling_offices.id, counseling_offices.name FROM counseling_offices From 7e26bd152b4a68879bc43fd3ff2a43ff4577b416 Mon Sep 17 00:00:00 2001 From: Samay Sofo Date: Wed, 29 Jan 2025 21:33:37 +0000 Subject: [PATCH 13/28] Updated test to include condition for routing counseling office. --- pkg/services/move/move_router_test.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/services/move/move_router_test.go b/pkg/services/move/move_router_test.go index f62d3865f00..9a8a7b20c44 100644 --- a/pkg/services/move/move_router_test.go +++ b/pkg/services/move/move_router_test.go @@ -13,6 +13,8 @@ import ( storageTest "github.com/transcom/mymove/pkg/storage/test" "github.com/transcom/mymove/pkg/testdatagen" "github.com/transcom/mymove/pkg/uploader" + "github.com/stretchr/testify/mock" + "github.com/transcom/mymove/pkg/services/mocks" ) func (suite *MoveServiceSuite) TestMoveApproval() { @@ -1001,7 +1003,6 @@ func (suite *MoveServiceSuite) TestMoveSubmission() { ProvidesServicesCounseling bool moveStatus models.MoveStatus }{ - {"Routes to Service Counseling", true, models.MoveStatusNeedsServiceCounseling}, {"Routes to Service Counseling", false, models.MoveStatusNeedsServiceCounseling}, } for _, tt := range tests { @@ -1050,6 +1051,11 @@ func (suite *MoveServiceSuite) TestMoveSubmission() { LinkOnly: true, }, }, nil) + mockFetcher := &mocks.TransportationOfficesFetcher{} + closestCounselingOffice := &models.TransportationOffice{} + if !tt.ProvidesServicesCounseling { + mockFetcher.On("FindClosestCounselingOffice", mock.Anything, mock.Anything).Return(closestCounselingOffice, nil) + } err := moveRouter.Submit(suite.AppContextForTest(), &move, &newSignedCertification) suite.NoError(err) err = suite.DB().Where("move_id = $1", move.ID).First(&newSignedCertification) @@ -1059,6 +1065,9 @@ func (suite *MoveServiceSuite) TestMoveSubmission() { err = suite.DB().Find(&move, move.ID) suite.NoError(err) suite.Equal(tt.moveStatus, move.Status) + if !tt.ProvidesServicesCounseling { + suite.Equal(closestCounselingOffice, move.CounselingOffice) + } }) } }) From 88d33bfd32ed8940a7d14072ca0bb251e76be45a Mon Sep 17 00:00:00 2001 From: Samay Sofo Date: Wed, 29 Jan 2025 21:55:06 +0000 Subject: [PATCH 14/28] code refactoring --- pkg/services/move/move_router_test.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/services/move/move_router_test.go b/pkg/services/move/move_router_test.go index 9a8a7b20c44..f4d279b8309 100644 --- a/pkg/services/move/move_router_test.go +++ b/pkg/services/move/move_router_test.go @@ -6,15 +6,15 @@ import ( "github.com/gofrs/uuid" + "github.com/stretchr/testify/mock" "github.com/transcom/mymove/pkg/apperror" "github.com/transcom/mymove/pkg/factory" "github.com/transcom/mymove/pkg/models" + "github.com/transcom/mymove/pkg/services/mocks" transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" storageTest "github.com/transcom/mymove/pkg/storage/test" "github.com/transcom/mymove/pkg/testdatagen" "github.com/transcom/mymove/pkg/uploader" - "github.com/stretchr/testify/mock" - "github.com/transcom/mymove/pkg/services/mocks" ) func (suite *MoveServiceSuite) TestMoveApproval() { @@ -1052,10 +1052,10 @@ func (suite *MoveServiceSuite) TestMoveSubmission() { }, }, nil) mockFetcher := &mocks.TransportationOfficesFetcher{} - closestCounselingOffice := &models.TransportationOffice{} - if !tt.ProvidesServicesCounseling { - mockFetcher.On("FindClosestCounselingOffice", mock.Anything, mock.Anything).Return(closestCounselingOffice, nil) - } + closestCounselingOffice := &models.TransportationOffice{} + if !tt.ProvidesServicesCounseling { + mockFetcher.On("FindClosestCounselingOffice", mock.Anything, mock.Anything).Return(closestCounselingOffice, nil) + } err := moveRouter.Submit(suite.AppContextForTest(), &move, &newSignedCertification) suite.NoError(err) err = suite.DB().Where("move_id = $1", move.ID).First(&newSignedCertification) @@ -1066,8 +1066,8 @@ func (suite *MoveServiceSuite) TestMoveSubmission() { suite.NoError(err) suite.Equal(tt.moveStatus, move.Status) if !tt.ProvidesServicesCounseling { - suite.Equal(closestCounselingOffice, move.CounselingOffice) - } + suite.Equal(closestCounselingOffice, move.CounselingOffice) + } }) } }) From dd32a0b0ccede82e268b06ec99eed9a5e6ec4b07 Mon Sep 17 00:00:00 2001 From: Samay Sofo Date: Wed, 29 Jan 2025 23:12:54 +0000 Subject: [PATCH 15/28] updated test due to failing tests from INT pr --- pkg/services/move/move_router_test.go | 2 +- .../transportation_office_fetcher_test.go | 59 +++---------------- 2 files changed, 9 insertions(+), 52 deletions(-) diff --git a/pkg/services/move/move_router_test.go b/pkg/services/move/move_router_test.go index f4d279b8309..11e36d18c6c 100644 --- a/pkg/services/move/move_router_test.go +++ b/pkg/services/move/move_router_test.go @@ -5,8 +5,8 @@ import ( "time" "github.com/gofrs/uuid" - "github.com/stretchr/testify/mock" + "github.com/transcom/mymove/pkg/apperror" "github.com/transcom/mymove/pkg/factory" "github.com/transcom/mymove/pkg/models" diff --git a/pkg/services/transportation_office/transportation_office_fetcher_test.go b/pkg/services/transportation_office/transportation_office_fetcher_test.go index a1f47237cd9..6756ad6a882 100644 --- a/pkg/services/transportation_office/transportation_office_fetcher_test.go +++ b/pkg/services/transportation_office/transportation_office_fetcher_test.go @@ -13,6 +13,7 @@ import ( "github.com/transcom/mymove/pkg/factory" "github.com/transcom/mymove/pkg/models" "github.com/transcom/mymove/pkg/services" + "github.com/transcom/mymove/pkg/testdatagen" "github.com/transcom/mymove/pkg/testingsuite" ) @@ -190,8 +191,6 @@ func (suite *TransportationOfficeServiceSuite) Test_FindCounselingOffices() { } func (suite *TransportationOfficeServiceSuite) Test_Oconus_AK_FindCounselingOffices() { - testContractName := "Test_findOconusGblocDepartmentIndicator" - testContractCode := "Test_findOconusGblocDepartmentIndicator_Code" testPostalCode := "99790" testPostalCode2 := "99701" testGbloc := "ABCD" @@ -233,31 +232,7 @@ func (suite *TransportationOfficeServiceSuite) Test_Oconus_AK_FindCounselingOffi return serviceMember } - - createContract := func(appCtx appcontext.AppContext, contractCode string, contractName string) (*models.ReContract, error) { - // See if contract code already exists. - exists, err := appCtx.DB().Where("code = ?", contractCode).Exists(&models.ReContract{}) - if err != nil { - return nil, fmt.Errorf("could not determine if contract code [%s] existed: %w", contractCode, err) - } - if exists { - return nil, fmt.Errorf("the provided contract code [%s] already exists", contractCode) - } - - // Contract code is new; insert it. - contract := models.ReContract{ - Code: contractCode, - Name: contractName, - } - verrs, err := appCtx.DB().ValidateAndSave(&contract) - if verrs.HasAny() { - return nil, fmt.Errorf("validation errors when saving contract [%+v]: %w", contract, verrs) - } - if err != nil { - return nil, fmt.Errorf("could not save contract [%+v]: %w", contract, err) - } - return &contract, nil - } + contract := testdatagen.FetchOrMakeReContract(suite.DB(), testdatagen.Assertions{}) setupDataForOconusSearchCounselingOffice := func(contract models.ReContract, postalCode string, gbloc string, transportationName string) (models.ReRateArea, models.OconusRateArea, models.UsPostRegionCity, models.DutyLocation) { rateAreaCode := uuid.Must(uuid.NewV4()).String()[0:5] @@ -335,12 +310,9 @@ func (suite *TransportationOfficeServiceSuite) Test_Oconus_AK_FindCounselingOffi } suite.Run("success - findOconusGblocDepartmentIndicator - returns default GLOC for departmentAffiliation if no specific departmentAffilation mapping is defined", func() { - contract, err := createContract(suite.AppContextForTest(), testContractCode, testContractName) suite.NotNil(contract) - suite.FatalNoError(err) - const fairbanksAlaskaPostalCode = "99790" - _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(*contract, fairbanksAlaskaPostalCode, testGbloc, testTransportationName) + _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(contract, fairbanksAlaskaPostalCode, testGbloc, testTransportationName) // setup department affiliation to GBLOC mappings expected_gbloc := "TEST-GBLOC" @@ -367,7 +339,6 @@ func (suite *TransportationOfficeServiceSuite) Test_Oconus_AK_FindCounselingOffi appCtx := suite.AppContextWithSessionForTest(&auth.Session{ ServiceMemberID: serviceMember.ID, }) - suite.Nil(err) departmentIndictor, err := findOconusGblocDepartmentIndicator(appCtx, dutylocation) suite.NotNil(departmentIndictor) suite.Nil(err) @@ -377,11 +348,9 @@ func (suite *TransportationOfficeServiceSuite) Test_Oconus_AK_FindCounselingOffi }) suite.Run("success - findOconusGblocDepartmentIndicator - returns specific GLOC for departmentAffiliation when a specific departmentAffilation mapping is defined", func() { - contract, err := createContract(suite.AppContextForTest(), testContractCode, testContractName) suite.NotNil(contract) - suite.FatalNoError(err) - _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(*contract, testPostalCode, testGbloc, testTransportationName) + _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(contract, testPostalCode, testGbloc, testTransportationName) departmentIndicators := []models.DepartmentIndicator{models.DepartmentIndicatorARMY, models.DepartmentIndicatorARMYCORPSOFENGINEERS, models.DepartmentIndicatorCOASTGUARD, @@ -426,7 +395,6 @@ func (suite *TransportationOfficeServiceSuite) Test_Oconus_AK_FindCounselingOffi appCtx := suite.AppContextWithSessionForTest(&auth.Session{ ServiceMemberID: serviceMember.ID, }) - suite.Nil(err) departmentIndictor, err := findOconusGblocDepartmentIndicator(appCtx, dutylocation) suite.NotNil(departmentIndictor) suite.Nil(err) @@ -442,11 +410,9 @@ func (suite *TransportationOfficeServiceSuite) Test_Oconus_AK_FindCounselingOffi }) suite.Run("failure -- returns error when there are default and no department specific GBLOC", func() { - contract, err := createContract(suite.AppContextForTest(), testContractCode, testContractName) suite.NotNil(contract) - suite.FatalNoError(err) - _, _, _, dutylocation := setupDataForOconusSearchCounselingOffice(*contract, testPostalCode, testGbloc, testTransportationName) + _, _, _, dutylocation := setupDataForOconusSearchCounselingOffice(contract, testPostalCode, testGbloc, testTransportationName) // No specific departmentAffiliation mapping or default were created. // Expect an error response when nothing is found. @@ -454,25 +420,21 @@ func (suite *TransportationOfficeServiceSuite) Test_Oconus_AK_FindCounselingOffi appCtx := suite.AppContextWithSessionForTest(&auth.Session{ ServiceMemberID: serviceMember.ID, }) - suite.Nil(err) departmentIndictor, err := findOconusGblocDepartmentIndicator(appCtx, dutylocation) suite.Nil(departmentIndictor) suite.NotNil(err) }) suite.Run("failure - findOconusGblocDepartmentIndicator - returns error when find service member ID fails", func() { - contract, err := createContract(suite.AppContextForTest(), testContractCode, testContractName) suite.NotNil(contract) - suite.FatalNoError(err) - _, _, _, dutylocation := setupDataForOconusSearchCounselingOffice(*contract, testPostalCode, testGbloc, testTransportationName) + _, _, _, dutylocation := setupDataForOconusSearchCounselingOffice(contract, testPostalCode, testGbloc, testTransportationName) appCtx := suite.AppContextWithSessionForTest(&auth.Session{ // create fake service member ID to raise NOT found error ServiceMemberID: uuid.Must(uuid.NewV4()), }) - suite.Nil(err) departmentIndictor, err := findOconusGblocDepartmentIndicator(appCtx, dutylocation) suite.Nil(departmentIndictor) suite.NotNil(err) @@ -489,11 +451,9 @@ func (suite *TransportationOfficeServiceSuite) Test_Oconus_AK_FindCounselingOffi }) suite.Run("success - offices using default departmentIndicator mapping", func() { - contract, err := createContract(suite.AppContextForTest(), testContractCode, testContractName) suite.NotNil(contract) - suite.FatalNoError(err) - _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(*contract, testPostalCode, testGbloc, testTransportationName) + _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(contract, testPostalCode, testGbloc, testTransportationName) // setup department affiliation to GBLOC mappings jppsoRegion := models.JppsoRegions{ @@ -522,7 +482,6 @@ func (suite *TransportationOfficeServiceSuite) Test_Oconus_AK_FindCounselingOffi ServiceMemberID: serviceMember.ID, }) - suite.Nil(err) offices, err := findCounselingOffice(appCtx, dutylocation.ID) suite.NotNil(offices) suite.Nil(err) @@ -546,11 +505,9 @@ func (suite *TransportationOfficeServiceSuite) Test_Oconus_AK_FindCounselingOffi }) suite.Run("success - returns correct office based on service affiliation -- simulate Zone 2 scenerio", func() { - contract, err := createContract(suite.AppContextForTest(), testContractCode, testContractName) suite.NotNil(contract) - suite.FatalNoError(err) - _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(*contract, testPostalCode, testGbloc, testTransportationName) + _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(contract, testPostalCode, testGbloc, testTransportationName) // ****************************************************************************** // setup department affiliation to GBLOC mappings for AF/SF From b821b7b6910b0fc5ebdba88a3e4eceed6b5290f0 Mon Sep 17 00:00:00 2001 From: Samay Sofo Date: Wed, 29 Jan 2025 23:38:51 +0000 Subject: [PATCH 16/28] code refactoring --- .../transportation_office_fetcher_test.go | 108 ++++++++++-------- 1 file changed, 59 insertions(+), 49 deletions(-) diff --git a/pkg/services/transportation_office/transportation_office_fetcher_test.go b/pkg/services/transportation_office/transportation_office_fetcher_test.go index 6756ad6a882..6c6736bf735 100644 --- a/pkg/services/transportation_office/transportation_office_fetcher_test.go +++ b/pkg/services/transportation_office/transportation_office_fetcher_test.go @@ -191,6 +191,8 @@ func (suite *TransportationOfficeServiceSuite) Test_FindCounselingOffices() { } func (suite *TransportationOfficeServiceSuite) Test_Oconus_AK_FindCounselingOffices() { + testContractName := "Test_findOconusGblocDepartmentIndicator" + testContractCode := "Test_findOconusGblocDepartmentIndicator_Code" testPostalCode := "99790" testPostalCode2 := "99701" testGbloc := "ABCD" @@ -232,7 +234,31 @@ func (suite *TransportationOfficeServiceSuite) Test_Oconus_AK_FindCounselingOffi return serviceMember } - contract := testdatagen.FetchOrMakeReContract(suite.DB(), testdatagen.Assertions{}) + + createContract := func(appCtx appcontext.AppContext, contractCode string, contractName string) (*models.ReContract, error) { + // See if contract code already exists. + exists, err := appCtx.DB().Where("code = ?", contractCode).Exists(&models.ReContract{}) + if err != nil { + return nil, fmt.Errorf("could not determine if contract code [%s] existed: %w", contractCode, err) + } + if exists { + return nil, fmt.Errorf("the provided contract code [%s] already exists", contractCode) + } + + // Contract code is new; insert it. + contract := models.ReContract{ + Code: contractCode, + Name: contractName, + } + verrs, err := appCtx.DB().ValidateAndSave(&contract) + if verrs.HasAny() { + return nil, fmt.Errorf("validation errors when saving contract [%+v]: %w", contract, verrs) + } + if err != nil { + return nil, fmt.Errorf("could not save contract [%+v]: %w", contract, err) + } + return &contract, nil + } setupDataForOconusSearchCounselingOffice := func(contract models.ReContract, postalCode string, gbloc string, transportationName string) (models.ReRateArea, models.OconusRateArea, models.UsPostRegionCity, models.DutyLocation) { rateAreaCode := uuid.Must(uuid.NewV4()).String()[0:5] @@ -310,9 +336,12 @@ func (suite *TransportationOfficeServiceSuite) Test_Oconus_AK_FindCounselingOffi } suite.Run("success - findOconusGblocDepartmentIndicator - returns default GLOC for departmentAffiliation if no specific departmentAffilation mapping is defined", func() { + contract, err := createContract(suite.AppContextForTest(), testContractCode, testContractName) suite.NotNil(contract) + suite.FatalNoError(err) + const fairbanksAlaskaPostalCode = "99790" - _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(contract, fairbanksAlaskaPostalCode, testGbloc, testTransportationName) + _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(*contract, fairbanksAlaskaPostalCode, testGbloc, testTransportationName) // setup department affiliation to GBLOC mappings expected_gbloc := "TEST-GBLOC" @@ -339,6 +368,7 @@ func (suite *TransportationOfficeServiceSuite) Test_Oconus_AK_FindCounselingOffi appCtx := suite.AppContextWithSessionForTest(&auth.Session{ ServiceMemberID: serviceMember.ID, }) + suite.Nil(err) departmentIndictor, err := findOconusGblocDepartmentIndicator(appCtx, dutylocation) suite.NotNil(departmentIndictor) suite.Nil(err) @@ -348,9 +378,11 @@ func (suite *TransportationOfficeServiceSuite) Test_Oconus_AK_FindCounselingOffi }) suite.Run("success - findOconusGblocDepartmentIndicator - returns specific GLOC for departmentAffiliation when a specific departmentAffilation mapping is defined", func() { + contract, err := createContract(suite.AppContextForTest(), testContractCode, testContractName) suite.NotNil(contract) + suite.FatalNoError(err) - _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(contract, testPostalCode, testGbloc, testTransportationName) + _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(*contract, testPostalCode, testGbloc, testTransportationName) departmentIndicators := []models.DepartmentIndicator{models.DepartmentIndicatorARMY, models.DepartmentIndicatorARMYCORPSOFENGINEERS, models.DepartmentIndicatorCOASTGUARD, @@ -395,6 +427,7 @@ func (suite *TransportationOfficeServiceSuite) Test_Oconus_AK_FindCounselingOffi appCtx := suite.AppContextWithSessionForTest(&auth.Session{ ServiceMemberID: serviceMember.ID, }) + suite.Nil(err) departmentIndictor, err := findOconusGblocDepartmentIndicator(appCtx, dutylocation) suite.NotNil(departmentIndictor) suite.Nil(err) @@ -410,9 +443,11 @@ func (suite *TransportationOfficeServiceSuite) Test_Oconus_AK_FindCounselingOffi }) suite.Run("failure -- returns error when there are default and no department specific GBLOC", func() { + contract, err := createContract(suite.AppContextForTest(), testContractCode, testContractName) suite.NotNil(contract) + suite.FatalNoError(err) - _, _, _, dutylocation := setupDataForOconusSearchCounselingOffice(contract, testPostalCode, testGbloc, testTransportationName) + _, _, _, dutylocation := setupDataForOconusSearchCounselingOffice(*contract, testPostalCode, testGbloc, testTransportationName) // No specific departmentAffiliation mapping or default were created. // Expect an error response when nothing is found. @@ -420,21 +455,25 @@ func (suite *TransportationOfficeServiceSuite) Test_Oconus_AK_FindCounselingOffi appCtx := suite.AppContextWithSessionForTest(&auth.Session{ ServiceMemberID: serviceMember.ID, }) + suite.Nil(err) departmentIndictor, err := findOconusGblocDepartmentIndicator(appCtx, dutylocation) suite.Nil(departmentIndictor) suite.NotNil(err) }) suite.Run("failure - findOconusGblocDepartmentIndicator - returns error when find service member ID fails", func() { + contract, err := createContract(suite.AppContextForTest(), testContractCode, testContractName) suite.NotNil(contract) + suite.FatalNoError(err) - _, _, _, dutylocation := setupDataForOconusSearchCounselingOffice(contract, testPostalCode, testGbloc, testTransportationName) + _, _, _, dutylocation := setupDataForOconusSearchCounselingOffice(*contract, testPostalCode, testGbloc, testTransportationName) appCtx := suite.AppContextWithSessionForTest(&auth.Session{ // create fake service member ID to raise NOT found error ServiceMemberID: uuid.Must(uuid.NewV4()), }) + suite.Nil(err) departmentIndictor, err := findOconusGblocDepartmentIndicator(appCtx, dutylocation) suite.Nil(departmentIndictor) suite.NotNil(err) @@ -451,9 +490,11 @@ func (suite *TransportationOfficeServiceSuite) Test_Oconus_AK_FindCounselingOffi }) suite.Run("success - offices using default departmentIndicator mapping", func() { + contract, err := createContract(suite.AppContextForTest(), testContractCode, testContractName) suite.NotNil(contract) + suite.FatalNoError(err) - _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(contract, testPostalCode, testGbloc, testTransportationName) + _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(*contract, testPostalCode, testGbloc, testTransportationName) // setup department affiliation to GBLOC mappings jppsoRegion := models.JppsoRegions{ @@ -482,6 +523,7 @@ func (suite *TransportationOfficeServiceSuite) Test_Oconus_AK_FindCounselingOffi ServiceMemberID: serviceMember.ID, }) + suite.Nil(err) offices, err := findCounselingOffice(appCtx, dutylocation.ID) suite.NotNil(offices) suite.Nil(err) @@ -505,9 +547,11 @@ func (suite *TransportationOfficeServiceSuite) Test_Oconus_AK_FindCounselingOffi }) suite.Run("success - returns correct office based on service affiliation -- simulate Zone 2 scenerio", func() { + contract, err := createContract(suite.AppContextForTest(), testContractCode, testContractName) suite.NotNil(contract) + suite.FatalNoError(err) - _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(contract, testPostalCode, testGbloc, testTransportationName) + _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(*contract, testPostalCode, testGbloc, testTransportationName) // ****************************************************************************** // setup department affiliation to GBLOC mappings for AF/SF @@ -714,8 +758,6 @@ func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeC } func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeOCONUS() { - testContractName := "Test_findOconusGblocDepartmentIndicator" - testContractCode := "Test_findOconusGblocDepartmentIndicator_Code" testPostalCode := "32228" testPostalCode2 := "99701" testGbloc := "CNNQ" @@ -737,31 +779,7 @@ func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeO return serviceMember } - createContract := func(appCtx appcontext.AppContext, contractCode string, contractName string) (*models.ReContract, error) { - // See if contract code already exists. - exists, err := appCtx.DB().Where("code = ?", contractCode).Exists(&models.ReContract{}) - if err != nil { - return nil, fmt.Errorf("could not determine if contract code [%s] existed: %w", contractCode, err) - } - if exists { - return nil, fmt.Errorf("the provided contract code [%s] already exists", contractCode) - } - - // Contract code is new; insert it. - contract := models.ReContract{ - Code: contractCode, - Name: contractName, - } - verrs, err := appCtx.DB().ValidateAndSave(&contract) - if verrs.HasAny() { - return nil, fmt.Errorf("validation errors when saving contract [%+v]: %w", contract, verrs) - } - if err != nil { - return nil, fmt.Errorf("could not save contract [%+v]: %w", contract, err) - } - return &contract, nil - } - + contract := testdatagen.FetchOrMakeReContract(suite.DB(), testdatagen.Assertions{}) setupDataForOconusSearchCounselingOffice := func(contract models.ReContract, postalCode string, gbloc string, transportationName string) (models.ReRateArea, models.OconusRateArea, models.UsPostRegionCity, models.DutyLocation) { rateAreaCode := uuid.Must(uuid.NewV4()).String()[0:5] rateArea := models.ReRateArea{ @@ -835,12 +853,10 @@ func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeO } suite.Run("success - findOconusGblocDepartmentIndicator - returns default GLOC for departmentAffiliation if no specific departmentAffilation mapping is defined", func() { - contract, err := createContract(suite.AppContextForTest(), testContractCode, testContractName) suite.NotNil(contract) - suite.FatalNoError(err) const fairbanksAlaskaPostalCode = "99790" - _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(*contract, fairbanksAlaskaPostalCode, testGbloc, testTransportationName) + _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(contract, fairbanksAlaskaPostalCode, testGbloc, testTransportationName) // setup department affiliation to GBLOC mappings expected_gbloc := "TEST-GBLOC" @@ -867,7 +883,6 @@ func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeO appCtx := suite.AppContextWithSessionForTest(&auth.Session{ ServiceMemberID: serviceMember.ID, }) - suite.Nil(err) departmentIndictor, err := findOconusGblocDepartmentIndicator(appCtx, dutylocation) suite.NotNil(departmentIndictor) suite.Nil(err) @@ -877,11 +892,10 @@ func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeO }) suite.Run("Success - findOconusGblocDepartmentIndicator - Should return specific GLOC for departmentAffiliation when a specific departmentAffilation mapping is defined", func() { - contract, err := createContract(suite.AppContextForTest(), testContractCode, testContractName) + contract := testdatagen.FetchOrMakeReContract(suite.DB(), testdatagen.Assertions{}) suite.NotNil(contract) - suite.FatalNoError(err) - _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(*contract, testPostalCode, testGbloc, testTransportationName) + _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(contract, testPostalCode, testGbloc, testTransportationName) departmentIndicators := []models.DepartmentIndicator{models.DepartmentIndicatorARMY, models.DepartmentIndicatorARMYCORPSOFENGINEERS, models.DepartmentIndicatorCOASTGUARD, @@ -926,7 +940,6 @@ func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeO appCtx := suite.AppContextWithSessionForTest(&auth.Session{ ServiceMemberID: serviceMember.ID, }) - suite.Nil(err) departmentIndictor, err := findOconusGblocDepartmentIndicator(appCtx, dutylocation) suite.NotNil(departmentIndictor) suite.Nil(err) @@ -942,11 +955,10 @@ func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeO }) suite.Run("success - offices using default departmentIndicator mapping", func() { - contract, err := createContract(suite.AppContextForTest(), testContractCode, testContractName) + contract := testdatagen.FetchOrMakeReContract(suite.DB(), testdatagen.Assertions{}) suite.NotNil(contract) - suite.FatalNoError(err) - _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(*contract, testPostalCode, testGbloc, testTransportationName) + _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(contract, testPostalCode, testGbloc, testTransportationName) // setup department affiliation to GBLOC mappings jppsoRegion := models.JppsoRegions{ @@ -974,7 +986,6 @@ func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeO ServiceMemberID: serviceMember.ID, }) - suite.Nil(err) offices, err := findCounselingOffice(appCtx, dutylocation.ID) suite.NotNil(offices) suite.Nil(err) @@ -997,11 +1008,10 @@ func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeO }) suite.Run("Should return correct office based on service affiliation", func() { - contract, err := createContract(suite.AppContextForTest(), testContractCode, testContractName) + contract := testdatagen.FetchOrMakeReContract(suite.DB(), testdatagen.Assertions{}) suite.NotNil(contract) - suite.FatalNoError(err) - _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(*contract, testPostalCode, testGbloc, testTransportationName) + _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(contract, testPostalCode, testGbloc, testTransportationName) jppsoRegion_AFSF := models.JppsoRegions{ Code: testGbloc, From 0386d2e91189be659c8e7d880e4f7b85db6d35e4 Mon Sep 17 00:00:00 2001 From: Samay Sofo Date: Wed, 29 Jan 2025 23:40:45 +0000 Subject: [PATCH 17/28] code clean up --- .../transportation_office_fetcher_test.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/pkg/services/transportation_office/transportation_office_fetcher_test.go b/pkg/services/transportation_office/transportation_office_fetcher_test.go index 6c6736bf735..a02083263ee 100644 --- a/pkg/services/transportation_office/transportation_office_fetcher_test.go +++ b/pkg/services/transportation_office/transportation_office_fetcher_test.go @@ -892,7 +892,6 @@ func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeO }) suite.Run("Success - findOconusGblocDepartmentIndicator - Should return specific GLOC for departmentAffiliation when a specific departmentAffilation mapping is defined", func() { - contract := testdatagen.FetchOrMakeReContract(suite.DB(), testdatagen.Assertions{}) suite.NotNil(contract) _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(contract, testPostalCode, testGbloc, testTransportationName) @@ -955,7 +954,6 @@ func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeO }) suite.Run("success - offices using default departmentIndicator mapping", func() { - contract := testdatagen.FetchOrMakeReContract(suite.DB(), testdatagen.Assertions{}) suite.NotNil(contract) _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(contract, testPostalCode, testGbloc, testTransportationName) @@ -1008,7 +1006,6 @@ func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeO }) suite.Run("Should return correct office based on service affiliation", func() { - contract := testdatagen.FetchOrMakeReContract(suite.DB(), testdatagen.Assertions{}) suite.NotNil(contract) _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(contract, testPostalCode, testGbloc, testTransportationName) From d86f375bd4cee4b759c6c509b78dd0b3a674044c Mon Sep 17 00:00:00 2001 From: Samay Sofo Date: Thu, 30 Jan 2025 23:33:23 +0000 Subject: [PATCH 18/28] Updated code to include new param --- .../transportation_office_fetcher.go | 2 +- .../transportation_office_fetcher_test.go | 64 ++++++++++++++----- 2 files changed, 49 insertions(+), 17 deletions(-) diff --git a/pkg/services/transportation_office/transportation_office_fetcher.go b/pkg/services/transportation_office/transportation_office_fetcher.go index 4e46b1a7162..08eda5eaa04 100644 --- a/pkg/services/transportation_office/transportation_office_fetcher.go +++ b/pkg/services/transportation_office/transportation_office_fetcher.go @@ -319,7 +319,7 @@ func (o transportationOfficesFetcher) FindClosestCounselingOffice(appCtx appcont // Find for oconus duty location if *duty_location.Address.IsOconus { - gblocDepartmentIndicator, err := findOconusGblocDepartmentIndicator(appCtx, duty_location) + gblocDepartmentIndicator, err := findOconusGblocDepartmentIndicator(appCtx, duty_location, appCtx.Session().ServiceMemberID) if err != nil { appCtx.Logger().Error("Failed to find OCONUS GBLOC department indicator", zap.Error(err)) return &closestOffice, err diff --git a/pkg/services/transportation_office/transportation_office_fetcher_test.go b/pkg/services/transportation_office/transportation_office_fetcher_test.go index a02083263ee..b5d7aa7fd56 100644 --- a/pkg/services/transportation_office/transportation_office_fetcher_test.go +++ b/pkg/services/transportation_office/transportation_office_fetcher_test.go @@ -13,7 +13,6 @@ import ( "github.com/transcom/mymove/pkg/factory" "github.com/transcom/mymove/pkg/models" "github.com/transcom/mymove/pkg/services" - "github.com/transcom/mymove/pkg/testdatagen" "github.com/transcom/mymove/pkg/testingsuite" ) @@ -758,6 +757,8 @@ func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeC } func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeOCONUS() { + testContractName := "Test_findOconusGblocDepartmentIndicator" + testContractCode := "Test_findOconusGblocDepartmentIndicator_Code" testPostalCode := "32228" testPostalCode2 := "99701" testGbloc := "CNNQ" @@ -779,7 +780,30 @@ func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeO return serviceMember } - contract := testdatagen.FetchOrMakeReContract(suite.DB(), testdatagen.Assertions{}) + createContract := func(appCtx appcontext.AppContext, contractCode string, contractName string) (*models.ReContract, error) { + // See if contract code already exists. + exists, err := appCtx.DB().Where("code = ?", contractCode).Exists(&models.ReContract{}) + if err != nil { + return nil, fmt.Errorf("could not determine if contract code [%s] existed: %w", contractCode, err) + } + if exists { + return nil, fmt.Errorf("the provided contract code [%s] already exists", contractCode) + } + // Contract code is new; insert it. + contract := models.ReContract{ + Code: contractCode, + Name: contractName, + } + verrs, err := appCtx.DB().ValidateAndSave(&contract) + if verrs.HasAny() { + return nil, fmt.Errorf("validation errors when saving contract [%+v]: %w", contract, verrs) + } + if err != nil { + return nil, fmt.Errorf("could not save contract [%+v]: %w", contract, err) + } + return &contract, nil + } + setupDataForOconusSearchCounselingOffice := func(contract models.ReContract, postalCode string, gbloc string, transportationName string) (models.ReRateArea, models.OconusRateArea, models.UsPostRegionCity, models.DutyLocation) { rateAreaCode := uuid.Must(uuid.NewV4()).String()[0:5] rateArea := models.ReRateArea{ @@ -822,11 +846,7 @@ func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeO } address := models.Address{ - StreetAddress1: "123 Ocunus St.", - City: "Fairbanks", - State: "AK", PostalCode: postalCode, - County: models.StringPointer("Fairbanks North Star Borough"), IsOconus: models.BoolPointer(true), UsPostRegionCityID: &usprc.ID, CountryId: models.UUIDPointer(us_country.ID), @@ -852,11 +872,14 @@ func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeO return rateArea, oconusRateArea, *usprc, found_duty_location } - suite.Run("success - findOconusGblocDepartmentIndicator - returns default GLOC for departmentAffiliation if no specific departmentAffilation mapping is defined", func() { + suite.Run("success - findOconusGblocDepartmentIndicator - returns default GBLOC for departmentAffiliation if no specific departmentAffilation mapping is defined", func() { + contract, err := createContract(suite.AppContextForTest(), testContractCode, testContractName) + suite.NotNil(contract) + suite.FatalNoError(err) suite.NotNil(contract) const fairbanksAlaskaPostalCode = "99790" - _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(contract, fairbanksAlaskaPostalCode, testGbloc, testTransportationName) + _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(*contract, fairbanksAlaskaPostalCode, testGbloc, testTransportationName) // setup department affiliation to GBLOC mappings expected_gbloc := "TEST-GBLOC" @@ -883,7 +906,7 @@ func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeO appCtx := suite.AppContextWithSessionForTest(&auth.Session{ ServiceMemberID: serviceMember.ID, }) - departmentIndictor, err := findOconusGblocDepartmentIndicator(appCtx, dutylocation) + departmentIndictor, err := findOconusGblocDepartmentIndicator(appCtx, dutylocation, appCtx.Session().ServiceMemberID) suite.NotNil(departmentIndictor) suite.Nil(err) suite.Nil(departmentIndictor.DepartmentIndicator) @@ -891,10 +914,13 @@ func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeO } }) - suite.Run("Success - findOconusGblocDepartmentIndicator - Should return specific GLOC for departmentAffiliation when a specific departmentAffilation mapping is defined", func() { + suite.Run("Success - findOconusGblocDepartmentIndicator - Should return specific GBLOC for departmentAffiliation when a specific departmentAffilation mapping is defined", func() { + contract, err := createContract(suite.AppContextForTest(), testContractCode, testContractName) + suite.NotNil(contract) + suite.FatalNoError(err) suite.NotNil(contract) - _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(contract, testPostalCode, testGbloc, testTransportationName) + _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(*contract, testPostalCode, testGbloc, testTransportationName) departmentIndicators := []models.DepartmentIndicator{models.DepartmentIndicatorARMY, models.DepartmentIndicatorARMYCORPSOFENGINEERS, models.DepartmentIndicatorCOASTGUARD, @@ -939,7 +965,7 @@ func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeO appCtx := suite.AppContextWithSessionForTest(&auth.Session{ ServiceMemberID: serviceMember.ID, }) - departmentIndictor, err := findOconusGblocDepartmentIndicator(appCtx, dutylocation) + departmentIndictor, err := findOconusGblocDepartmentIndicator(appCtx, dutylocation, appCtx.Session().ServiceMemberID) suite.NotNil(departmentIndictor) suite.Nil(err) suite.NotNil(departmentIndictor.DepartmentIndicator) @@ -954,9 +980,12 @@ func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeO }) suite.Run("success - offices using default departmentIndicator mapping", func() { + contract, err := createContract(suite.AppContextForTest(), testContractCode, testContractName) + suite.NotNil(contract) + suite.FatalNoError(err) suite.NotNil(contract) - _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(contract, testPostalCode, testGbloc, testTransportationName) + _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(*contract, testPostalCode, testGbloc, testTransportationName) // setup department affiliation to GBLOC mappings jppsoRegion := models.JppsoRegions{ @@ -984,7 +1013,7 @@ func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeO ServiceMemberID: serviceMember.ID, }) - offices, err := findCounselingOffice(appCtx, dutylocation.ID) + offices, err := findCounselingOffice(appCtx, dutylocation.ID, serviceMember.ID) suite.NotNil(offices) suite.Nil(err) suite.Equal(1, len(offices)) @@ -999,16 +1028,19 @@ func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeO }, }, }, nil) - offices, err = findCounselingOffice(appCtx, dutylocation.ID) + offices, err = findCounselingOffice(appCtx, dutylocation.ID, serviceMember.ID) suite.NotNil(offices) suite.Nil(err) suite.Equal(2, len(offices)) }) suite.Run("Should return correct office based on service affiliation", func() { + contract, err := createContract(suite.AppContextForTest(), testContractCode, testContractName) + suite.NotNil(contract) + suite.FatalNoError(err) suite.NotNil(contract) - _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(contract, testPostalCode, testGbloc, testTransportationName) + _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(*contract, testPostalCode, testGbloc, testTransportationName) jppsoRegion_AFSF := models.JppsoRegions{ Code: testGbloc, From 051302566cad27c92c78c2e1414e343bde687324 Mon Sep 17 00:00:00 2001 From: Samay Sofo Date: Fri, 31 Jan 2025 15:09:48 +0000 Subject: [PATCH 19/28] added serviceMemberID param --- .../mocks/TransportationOfficesFetcher.go | 18 +++++++++--------- pkg/services/move/move_router.go | 2 +- pkg/services/transportation_office.go | 2 +- .../transportation_office_fetcher.go | 4 ++-- .../transportation_office_fetcher_test.go | 17 ++++++++++++----- 5 files changed, 25 insertions(+), 18 deletions(-) diff --git a/pkg/services/mocks/TransportationOfficesFetcher.go b/pkg/services/mocks/TransportationOfficesFetcher.go index 47f5a5f9477..14310348bec 100644 --- a/pkg/services/mocks/TransportationOfficesFetcher.go +++ b/pkg/services/mocks/TransportationOfficesFetcher.go @@ -16,9 +16,9 @@ type TransportationOfficesFetcher struct { mock.Mock } -// FindClosestCounselingOffice provides a mock function with given fields: appCtx, dutyLocationID -func (_m *TransportationOfficesFetcher) FindClosestCounselingOffice(appCtx appcontext.AppContext, dutyLocationID uuid.UUID) (*models.TransportationOffice, error) { - ret := _m.Called(appCtx, dutyLocationID) +// FindClosestCounselingOffice provides a mock function with given fields: appCtx, dutyLocationID, serviceMemberID +func (_m *TransportationOfficesFetcher) FindClosestCounselingOffice(appCtx appcontext.AppContext, dutyLocationID uuid.UUID, serviceMemberID uuid.UUID) (*models.TransportationOffice, error) { + ret := _m.Called(appCtx, dutyLocationID, serviceMemberID) if len(ret) == 0 { panic("no return value specified for FindClosestCounselingOffice") @@ -26,19 +26,19 @@ func (_m *TransportationOfficesFetcher) FindClosestCounselingOffice(appCtx appco var r0 *models.TransportationOffice var r1 error - if rf, ok := ret.Get(0).(func(appcontext.AppContext, uuid.UUID) (*models.TransportationOffice, error)); ok { - return rf(appCtx, dutyLocationID) + if rf, ok := ret.Get(0).(func(appcontext.AppContext, uuid.UUID, uuid.UUID) (*models.TransportationOffice, error)); ok { + return rf(appCtx, dutyLocationID, serviceMemberID) } - if rf, ok := ret.Get(0).(func(appcontext.AppContext, uuid.UUID) *models.TransportationOffice); ok { - r0 = rf(appCtx, dutyLocationID) + if rf, ok := ret.Get(0).(func(appcontext.AppContext, uuid.UUID, uuid.UUID) *models.TransportationOffice); ok { + r0 = rf(appCtx, dutyLocationID, serviceMemberID) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*models.TransportationOffice) } } - if rf, ok := ret.Get(1).(func(appcontext.AppContext, uuid.UUID) error); ok { - r1 = rf(appCtx, dutyLocationID) + if rf, ok := ret.Get(1).(func(appcontext.AppContext, uuid.UUID, uuid.UUID) error); ok { + r1 = rf(appCtx, dutyLocationID, serviceMemberID) } else { r1 = ret.Error(1) } diff --git a/pkg/services/move/move_router.go b/pkg/services/move/move_router.go index ce706240b69..4f2c87b73b5 100644 --- a/pkg/services/move/move_router.go +++ b/pkg/services/move/move_router.go @@ -232,7 +232,7 @@ func (router moveRouter) sendToServiceCounselor(appCtx appcontext.AppContext, mo // actual expense reimbursement is always true for civilian moves move.MTOShipments[i].PPMShipment.IsActualExpenseReimbursement = models.BoolPointer(isCivilian) if move.IsPPMOnly() && !orders.OriginDutyLocation.ProvidesServicesCounseling { - closestCounselingOffice, err := router.transportationOfficesFetcher.FindClosestCounselingOffice(appCtx, *move.Orders.OriginDutyLocationID) + closestCounselingOffice, err := router.transportationOfficesFetcher.FindClosestCounselingOffice(appCtx, *move.Orders.OriginDutyLocationID, move.Orders.ServiceMemberID) if err != nil { msg := "Failure setting PPM counseling office to closest service counseling office" appCtx.Logger().Error(msg, zap.Error(err)) diff --git a/pkg/services/transportation_office.go b/pkg/services/transportation_office.go index f8cc2cf3afa..2b282070f5a 100644 --- a/pkg/services/transportation_office.go +++ b/pkg/services/transportation_office.go @@ -13,5 +13,5 @@ type TransportationOfficesFetcher interface { GetTransportationOffice(appCtx appcontext.AppContext, transportationOfficeID uuid.UUID, includeOnlyPPMCloseoutOffices bool) (*models.TransportationOffice, error) GetAllGBLOCs(appCtx appcontext.AppContext) (*models.GBLOCs, error) GetCounselingOffices(appCtx appcontext.AppContext, dutyLocationID uuid.UUID) (*models.TransportationOffices, error) - FindClosestCounselingOffice(appCtx appcontext.AppContext, dutyLocationID uuid.UUID) (*models.TransportationOffice, error) + FindClosestCounselingOffice(appCtx appcontext.AppContext, dutyLocationID uuid.UUID, serviceMemberID uuid.UUID) (*models.TransportationOffice, error) } diff --git a/pkg/services/transportation_office/transportation_office_fetcher.go b/pkg/services/transportation_office/transportation_office_fetcher.go index 08eda5eaa04..b050994f4b1 100644 --- a/pkg/services/transportation_office/transportation_office_fetcher.go +++ b/pkg/services/transportation_office/transportation_office_fetcher.go @@ -308,7 +308,7 @@ func findOconusGblocDepartmentIndicator(appCtx appcontext.AppContext, dutyLocati } // Return the closest transportation office in the GBLOC of the given duty location for oconus/conus duty locations -func (o transportationOfficesFetcher) FindClosestCounselingOffice(appCtx appcontext.AppContext, dutyLocationID uuid.UUID) (*models.TransportationOffice, error) { +func (o transportationOfficesFetcher) FindClosestCounselingOffice(appCtx appcontext.AppContext, dutyLocationID uuid.UUID, serviceMemberID uuid.UUID) (*models.TransportationOffice, error) { var closestOffice models.TransportationOffice duty_location, err := models.FetchDutyLocation(appCtx.DB(), dutyLocationID) if err != nil { @@ -319,7 +319,7 @@ func (o transportationOfficesFetcher) FindClosestCounselingOffice(appCtx appcont // Find for oconus duty location if *duty_location.Address.IsOconus { - gblocDepartmentIndicator, err := findOconusGblocDepartmentIndicator(appCtx, duty_location, appCtx.Session().ServiceMemberID) + gblocDepartmentIndicator, err := findOconusGblocDepartmentIndicator(appCtx, duty_location, serviceMemberID) if err != nil { appCtx.Logger().Error("Failed to find OCONUS GBLOC department indicator", zap.Error(err)) return &closestOffice, err diff --git a/pkg/services/transportation_office/transportation_office_fetcher_test.go b/pkg/services/transportation_office/transportation_office_fetcher_test.go index b5d7aa7fd56..7bd0837e69c 100644 --- a/pkg/services/transportation_office/transportation_office_fetcher_test.go +++ b/pkg/services/transportation_office/transportation_office_fetcher_test.go @@ -750,8 +750,15 @@ func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeC }, }, }, nil) - - offices, err := suite.toFetcher.FindClosestCounselingOffice(suite.AppContextForTest(), origDutyLocation.ID) + armyAffliation := models.AffiliationARMY + serviceMember := factory.BuildServiceMember(suite.DB(), []factory.Customization{ + { + Model: models.ServiceMember{ + Affiliation: &armyAffliation, + }, + }, + }, nil) + offices, err := suite.toFetcher.FindClosestCounselingOffice(suite.AppContextForTest(), origDutyLocation.ID, serviceMember.ID) suite.NoError(err) suite.Equal(offices.Name, "PPPO Jacksonville - USN") } @@ -906,7 +913,7 @@ func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeO appCtx := suite.AppContextWithSessionForTest(&auth.Session{ ServiceMemberID: serviceMember.ID, }) - departmentIndictor, err := findOconusGblocDepartmentIndicator(appCtx, dutylocation, appCtx.Session().ServiceMemberID) + departmentIndictor, err := findOconusGblocDepartmentIndicator(appCtx, dutylocation, serviceMember.ID) suite.NotNil(departmentIndictor) suite.Nil(err) suite.Nil(departmentIndictor.DepartmentIndicator) @@ -1100,7 +1107,7 @@ func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeO appCtx := suite.AppContextWithSessionForTest(&auth.Session{ ServiceMemberID: serviceMember.ID, }) - offices, err := suite.toFetcher.FindClosestCounselingOffice(appCtx, dutylocation.ID) + offices, err := suite.toFetcher.FindClosestCounselingOffice(appCtx, dutylocation.ID, serviceMember.ID) suite.NotNil(offices) suite.Nil(err) suite.Equal(testTransportationName, offices.Name) @@ -1108,7 +1115,7 @@ func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeO appCtx := suite.AppContextWithSessionForTest(&auth.Session{ ServiceMemberID: serviceMember.ID, }) - offices, err := suite.toFetcher.FindClosestCounselingOffice(appCtx, dutylocation.ID) + offices, err := suite.toFetcher.FindClosestCounselingOffice(appCtx, dutylocation.ID, serviceMember.ID) suite.NotNil(offices) suite.Nil(err) suite.Equal(testTransportationName2, offices.Name) From 5c4c8057179bce69bf16dbedc83525a4f25f21bd Mon Sep 17 00:00:00 2001 From: Samay Sofo Date: Wed, 5 Feb 2025 13:41:26 +0000 Subject: [PATCH 20/28] code refactoring --- .../transportation_office/transportation_office_fetcher.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/services/transportation_office/transportation_office_fetcher.go b/pkg/services/transportation_office/transportation_office_fetcher.go index b050994f4b1..aa131337767 100644 --- a/pkg/services/transportation_office/transportation_office_fetcher.go +++ b/pkg/services/transportation_office/transportation_office_fetcher.go @@ -371,7 +371,7 @@ func (o transportationOfficesFetcher) FindClosestCounselingOffice(appCtx appcont JOIN addresses ON postal_code_to_gblocs.postal_code = addresses.postal_code JOIN duty_locations ON addresses.id = duty_locations.address_id JOIN transportation_offices ON postal_code_to_gblocs.gbloc = transportation_offices.gbloc - WHERE duty_locations.provides_services_counseling = true and duty_locations.id = $1 + WHERE duty_locations.id = $1 ) SELECT counseling_offices.id, counseling_offices.name FROM counseling_offices From acd226cb1a1276d77410bda9cf587a9682ee055d Mon Sep 17 00:00:00 2001 From: Samay Sofo Date: Thu, 6 Feb 2025 14:48:36 +0000 Subject: [PATCH 21/28] updated test to used buildAdrress factory and code clean up --- .../transportation_office_fetcher_test.go | 34 +++++++------------ 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/pkg/services/transportation_office/transportation_office_fetcher_test.go b/pkg/services/transportation_office/transportation_office_fetcher_test.go index 7bd0837e69c..aa831a818d8 100644 --- a/pkg/services/transportation_office/transportation_office_fetcher_test.go +++ b/pkg/services/transportation_office/transportation_office_fetcher_test.go @@ -680,12 +680,16 @@ func (suite *TransportationOfficeServiceSuite) Test_GetTransportationOffice() { func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeCONUS() { suite.toFetcher = NewTransportationOfficesFetcher() + address := factory.BuildAddress(suite.DB(), []factory.Customization{ + { + Model: models.Address{ + PostalCode: "32228", + IsOconus: models.BoolPointer(false), + }, + }, + }, nil) factory.BuildDutyLocation(suite.DB(), []factory.Customization{ - {Model: models.Address{ - ID: uuid.Must(uuid.NewV4()), - PostalCode: "32228", - IsOconus: models.BoolPointer(false), - }, Type: &factory.Addresses.DutyLocationAddress}, + {Model: address, LinkOnly: true, Type: &factory.Addresses.DutyLocationAddress}, { Model: models.DutyLocation{ ProvidesServicesCounseling: false, @@ -698,10 +702,7 @@ func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeC }, }, nil) factory.BuildDutyLocation(suite.DB(), []factory.Customization{ - {Model: models.Address{ - PostalCode: "32228", - IsOconus: models.BoolPointer(false), - }, Type: &factory.Addresses.DutyLocationAddress}, + {Model: address, LinkOnly: true, Type: &factory.Addresses.DutyLocationAddress}, { Model: models.DutyLocation{ ProvidesServicesCounseling: true, @@ -714,11 +715,7 @@ func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeC }, }, nil) origDutyLocation := factory.BuildDutyLocation(suite.DB(), []factory.Customization{ - {Model: models.Address{ - ID: uuid.Must(uuid.NewV4()), - PostalCode: "32228", - IsOconus: models.BoolPointer(false), - }, Type: &factory.Addresses.DutyLocationAddress}, + {Model: address, LinkOnly: true, Type: &factory.Addresses.DutyLocationAddress}, { Model: models.DutyLocation{ ProvidesServicesCounseling: true, @@ -733,10 +730,7 @@ func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeC }, }, nil) factory.BuildDutyLocation(suite.DB(), []factory.Customization{ - {Model: models.Address{ - PostalCode: "32228", - IsOconus: models.BoolPointer(false), - }, Type: &factory.Addresses.DutyLocationAddress}, + {Model: address, LinkOnly: true, Type: &factory.Addresses.DutyLocationAddress}, { Model: models.DutyLocation{ ProvidesServicesCounseling: true, @@ -883,7 +877,6 @@ func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeO contract, err := createContract(suite.AppContextForTest(), testContractCode, testContractName) suite.NotNil(contract) suite.FatalNoError(err) - suite.NotNil(contract) const fairbanksAlaskaPostalCode = "99790" _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(*contract, fairbanksAlaskaPostalCode, testGbloc, testTransportationName) @@ -925,7 +918,6 @@ func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeO contract, err := createContract(suite.AppContextForTest(), testContractCode, testContractName) suite.NotNil(contract) suite.FatalNoError(err) - suite.NotNil(contract) _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(*contract, testPostalCode, testGbloc, testTransportationName) @@ -990,7 +982,6 @@ func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeO contract, err := createContract(suite.AppContextForTest(), testContractCode, testContractName) suite.NotNil(contract) suite.FatalNoError(err) - suite.NotNil(contract) _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(*contract, testPostalCode, testGbloc, testTransportationName) @@ -1045,7 +1036,6 @@ func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeO contract, err := createContract(suite.AppContextForTest(), testContractCode, testContractName) suite.NotNil(contract) suite.FatalNoError(err) - suite.NotNil(contract) _, oconusRateArea, _, dutylocation := setupDataForOconusSearchCounselingOffice(*contract, testPostalCode, testGbloc, testTransportationName) From bb1e04251f8fe9261bf787d50a6b7aebb0d73139 Mon Sep 17 00:00:00 2001 From: Samay Sofo Date: Thu, 6 Feb 2025 22:30:29 +0000 Subject: [PATCH 22/28] refactored code --- pkg/services/mocks/TransportationOfficesFetcher.go | 6 +++--- pkg/services/move/move_router.go | 4 ++-- pkg/services/transportation_office.go | 2 +- .../transportation_office_fetcher.go | 6 +++--- .../transportation_office_fetcher_test.go | 10 +++++----- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/pkg/services/mocks/TransportationOfficesFetcher.go b/pkg/services/mocks/TransportationOfficesFetcher.go index 14310348bec..7224e438426 100644 --- a/pkg/services/mocks/TransportationOfficesFetcher.go +++ b/pkg/services/mocks/TransportationOfficesFetcher.go @@ -16,12 +16,12 @@ type TransportationOfficesFetcher struct { mock.Mock } -// FindClosestCounselingOffice provides a mock function with given fields: appCtx, dutyLocationID, serviceMemberID -func (_m *TransportationOfficesFetcher) FindClosestCounselingOffice(appCtx appcontext.AppContext, dutyLocationID uuid.UUID, serviceMemberID uuid.UUID) (*models.TransportationOffice, error) { +// FindCounselingOfficeForPrimeCounseled provides a mock function with given fields: appCtx, dutyLocationID, serviceMemberID +func (_m *TransportationOfficesFetcher) FindCounselingOfficeForPrimeCounseled(appCtx appcontext.AppContext, dutyLocationID uuid.UUID, serviceMemberID uuid.UUID) (*models.TransportationOffice, error) { ret := _m.Called(appCtx, dutyLocationID, serviceMemberID) if len(ret) == 0 { - panic("no return value specified for FindClosestCounselingOffice") + panic("no return value specified for FindCounselingOfficeForPrimeCounseled") } var r0 *models.TransportationOffice diff --git a/pkg/services/move/move_router.go b/pkg/services/move/move_router.go index 4f2c87b73b5..0ff16c84789 100644 --- a/pkg/services/move/move_router.go +++ b/pkg/services/move/move_router.go @@ -232,13 +232,13 @@ func (router moveRouter) sendToServiceCounselor(appCtx appcontext.AppContext, mo // actual expense reimbursement is always true for civilian moves move.MTOShipments[i].PPMShipment.IsActualExpenseReimbursement = models.BoolPointer(isCivilian) if move.IsPPMOnly() && !orders.OriginDutyLocation.ProvidesServicesCounseling { - closestCounselingOffice, err := router.transportationOfficesFetcher.FindClosestCounselingOffice(appCtx, *move.Orders.OriginDutyLocationID, move.Orders.ServiceMemberID) + closestCounselingOffice, err := router.transportationOfficesFetcher.FindCounselingOfficeForPrimeCounseled(appCtx, *move.Orders.OriginDutyLocationID, move.Orders.ServiceMemberID) if err != nil { msg := "Failure setting PPM counseling office to closest service counseling office" appCtx.Logger().Error(msg, zap.Error(err)) return apperror.NewQueryError("Closest Counseling Office", err, "Failed to find counseling office that provides counseling") } - move.CounselingOffice = closestCounselingOffice + move.CounselingOfficeID = &closestCounselingOffice.ID } if verrs, err := appCtx.DB().ValidateAndUpdate(&move.MTOShipments[i]); verrs.HasAny() || err != nil { diff --git a/pkg/services/transportation_office.go b/pkg/services/transportation_office.go index 2b282070f5a..6041b502424 100644 --- a/pkg/services/transportation_office.go +++ b/pkg/services/transportation_office.go @@ -13,5 +13,5 @@ type TransportationOfficesFetcher interface { GetTransportationOffice(appCtx appcontext.AppContext, transportationOfficeID uuid.UUID, includeOnlyPPMCloseoutOffices bool) (*models.TransportationOffice, error) GetAllGBLOCs(appCtx appcontext.AppContext) (*models.GBLOCs, error) GetCounselingOffices(appCtx appcontext.AppContext, dutyLocationID uuid.UUID) (*models.TransportationOffices, error) - FindClosestCounselingOffice(appCtx appcontext.AppContext, dutyLocationID uuid.UUID, serviceMemberID uuid.UUID) (*models.TransportationOffice, error) + FindCounselingOfficeForPrimeCounseled(appCtx appcontext.AppContext, dutyLocationID uuid.UUID, serviceMemberID uuid.UUID) (*models.TransportationOffice, error) } diff --git a/pkg/services/transportation_office/transportation_office_fetcher.go b/pkg/services/transportation_office/transportation_office_fetcher.go index aa131337767..225695a7485 100644 --- a/pkg/services/transportation_office/transportation_office_fetcher.go +++ b/pkg/services/transportation_office/transportation_office_fetcher.go @@ -307,8 +307,8 @@ func findOconusGblocDepartmentIndicator(appCtx appcontext.AppContext, dutyLocati serviceMember.Affiliation, dutyLocation.Name, *departmentIndicator, dutyLocation.Address.ID)) } -// Return the closest transportation office in the GBLOC of the given duty location for oconus/conus duty locations -func (o transportationOfficesFetcher) FindClosestCounselingOffice(appCtx appcontext.AppContext, dutyLocationID uuid.UUID, serviceMemberID uuid.UUID) (*models.TransportationOffice, error) { +// Return the closest transportation office in the GBLOC of the given duty location for oconus/conus duty locations for a prime counseled +func (o transportationOfficesFetcher) FindCounselingOfficeForPrimeCounseled(appCtx appcontext.AppContext, dutyLocationID uuid.UUID, serviceMemberID uuid.UUID) (*models.TransportationOffice, error) { var closestOffice models.TransportationOffice duty_location, err := models.FetchDutyLocation(appCtx.DB(), dutyLocationID) if err != nil { @@ -337,7 +337,7 @@ func (o transportationOfficesFetcher) FindClosestCounselingOffice(appCtx appcont JOIN jppso_regions j ON gbloc_aors.jppso_regions_id = j.id JOIN transportation_offices ON j.code = transportation_offices.gbloc JOIN addresses a2 ON a2.id = transportation_offices.address_id - WHERE duty_locations.provides_services_counseling = true and duty_locations.id = $1 AND j.code = $2 + WHERE duty_locations.id = $1 AND j.code = $2 AND transportation_offices.provides_ppm_closeout = true ) SELECT counseling_offices.id, counseling_offices.name diff --git a/pkg/services/transportation_office/transportation_office_fetcher_test.go b/pkg/services/transportation_office/transportation_office_fetcher_test.go index aa831a818d8..2590422d4fd 100644 --- a/pkg/services/transportation_office/transportation_office_fetcher_test.go +++ b/pkg/services/transportation_office/transportation_office_fetcher_test.go @@ -678,7 +678,7 @@ func (suite *TransportationOfficeServiceSuite) Test_GetTransportationOffice() { suite.Equal("OFFICE TWO", office2f.Name) } -func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeCONUS() { +func (suite *TransportationOfficeServiceSuite) Test_FindCounselingOfficeForPrimeCounseledCONUS() { suite.toFetcher = NewTransportationOfficesFetcher() address := factory.BuildAddress(suite.DB(), []factory.Customization{ { @@ -752,12 +752,12 @@ func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeC }, }, }, nil) - offices, err := suite.toFetcher.FindClosestCounselingOffice(suite.AppContextForTest(), origDutyLocation.ID, serviceMember.ID) + offices, err := suite.toFetcher.FindCounselingOfficeForPrimeCounseled(suite.AppContextForTest(), origDutyLocation.ID, serviceMember.ID) suite.NoError(err) suite.Equal(offices.Name, "PPPO Jacksonville - USN") } -func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeOCONUS() { +func (suite *TransportationOfficeServiceSuite) Test_FindCounselingOfficeForPrimeCounseledOCONUS() { testContractName := "Test_findOconusGblocDepartmentIndicator" testContractCode := "Test_findOconusGblocDepartmentIndicator_Code" testPostalCode := "32228" @@ -1097,7 +1097,7 @@ func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeO appCtx := suite.AppContextWithSessionForTest(&auth.Session{ ServiceMemberID: serviceMember.ID, }) - offices, err := suite.toFetcher.FindClosestCounselingOffice(appCtx, dutylocation.ID, serviceMember.ID) + offices, err := suite.toFetcher.FindCounselingOfficeForPrimeCounseled(appCtx, dutylocation.ID, serviceMember.ID) suite.NotNil(offices) suite.Nil(err) suite.Equal(testTransportationName, offices.Name) @@ -1105,7 +1105,7 @@ func (suite *TransportationOfficeServiceSuite) Test_FindClosestCounselingOfficeO appCtx := suite.AppContextWithSessionForTest(&auth.Session{ ServiceMemberID: serviceMember.ID, }) - offices, err := suite.toFetcher.FindClosestCounselingOffice(appCtx, dutylocation.ID, serviceMember.ID) + offices, err := suite.toFetcher.FindCounselingOfficeForPrimeCounseled(appCtx, dutylocation.ID, serviceMember.ID) suite.NotNil(offices) suite.Nil(err) suite.Equal(testTransportationName2, offices.Name) From 8e8f6c09ca8d7376234ea2042c3860510a3634db Mon Sep 17 00:00:00 2001 From: Samay Sofo Date: Tue, 11 Feb 2025 13:13:36 +0000 Subject: [PATCH 23/28] added fix for failing test when submitting ppm without closestcounseling office --- pkg/handlers/internalapi/moves_test.go | 94 +++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 1 deletion(-) diff --git a/pkg/handlers/internalapi/moves_test.go b/pkg/handlers/internalapi/moves_test.go index abd154aa95c..06a7597fc0c 100644 --- a/pkg/handlers/internalapi/moves_test.go +++ b/pkg/handlers/internalapi/moves_test.go @@ -11,6 +11,7 @@ package internalapi import ( "fmt" + "net/http" "net/http/httptest" "time" @@ -247,7 +248,27 @@ func (suite *HandlerSuite) TestShowMoveWrongUser() { func (suite *HandlerSuite) TestSubmitMoveForApprovalHandler() { suite.Run("Submits ppm success", func() { // Given: a set of orders, a move, user and servicemember - move := factory.BuildMove(suite.DB(), nil, nil) + originDutyLocation := factory.BuildDutyLocation(suite.DB(), []factory.Customization{ + { + Model: models.DutyLocation{ + ProvidesServicesCounseling: true, + }, + }, + }, nil) + order := factory.BuildOrder(suite.DB(), []factory.Customization{ + { + Model: originDutyLocation, + LinkOnly: true, + Type: &factory.DutyLocations.OriginDutyLocation, + }, + }, nil) + + move := factory.BuildMove(suite.DB(), []factory.Customization{ + { + Model: order, + LinkOnly: true, + }, + }, nil) factory.BuildPPMShipment(suite.DB(), []factory.Customization{ { Model: move, @@ -306,6 +327,77 @@ func (suite *HandlerSuite) TestSubmitMoveForApprovalHandler() { actualSubmittedAt := updatedMove.SubmittedAt suite.WithinDuration(time.Now(), *actualSubmittedAt, 2*time.Second) }) + + suite.Run("Submits ppm fails due to no closest counseling office", func() { + // Given: a set of orders, a move, user and servicemember + originDutyLocation := factory.BuildDutyLocation(suite.DB(), []factory.Customization{ + { + Model: models.DutyLocation{ + ProvidesServicesCounseling: false, + }, + }, + }, nil) + order := factory.BuildOrder(suite.DB(), []factory.Customization{ + { + Model: originDutyLocation, + LinkOnly: true, + Type: &factory.DutyLocations.OriginDutyLocation, + }, + }, nil) + + move := factory.BuildMove(suite.DB(), []factory.Customization{ + { + Model: order, + LinkOnly: true, + }, + }, nil) + factory.BuildPPMShipment(suite.DB(), []factory.Customization{ + { + Model: move, + LinkOnly: true, + }, + { + Model: models.MTOShipment{ + Status: models.MTOShipmentStatusDraft, + }, + }, + }, nil) + + // And: the context contains the auth values + req := httptest.NewRequest("POST", "/moves/some_id/submit", nil) + req = suite.AuthenticateRequest(req, move.Orders.ServiceMember) + certType := internalmessages.SignedCertificationTypeCreateSHIPMENT + signingDate := strfmt.DateTime(time.Now()) + certificate := internalmessages.CreateSignedCertificationPayload{ + CertificationText: models.StringPointer("This is your legal message"), + CertificationType: &certType, + Date: &signingDate, + Signature: models.StringPointer("Jane Doe"), + } + newSubmitMoveForApprovalPayload := internalmessages.SubmitMoveForApprovalPayload{Certificate: &certificate} + + params := moveop.SubmitMoveForApprovalParams{ + HTTPRequest: req, + MoveID: strfmt.UUID(move.ID.String()), + SubmitMoveForApprovalPayload: &newSubmitMoveForApprovalPayload, + } + // When: a move is submitted + handlerConfig := suite.HandlerConfig() + handlerConfig.SetNotificationSender(notifications.NewStubNotificationSender("milmovelocal")) + handler := SubmitMoveHandler{handlerConfig, moverouter.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher())} + response := handler.Handle(params) + + //Expect 500 error + suite.Assertions.IsType(&handlers.ErrResponse{}, response) + internalServerErrorResponse := response.(*handlers.ErrResponse) + suite.Equal(internalServerErrorResponse.Code, http.StatusInternalServerError) + suite.Equal(internalServerErrorResponse.Err.Error(), "failure saving move when routing move submission") + + // And: SignedCertification was created + signedCertification := models.SignedCertification{} + err := suite.DB().Where("move_id = $1", move.ID).First(&signedCertification) + suite.Error(err) + }) suite.Run("Submits hhg shipment success", func() { // Given: a set of orders, a move, user and servicemember hhg := factory.BuildMTOShipment(suite.DB(), nil, nil) From 3c96ceda7f9ef94456a5c9c804031d60452429ce Mon Sep 17 00:00:00 2001 From: Samay Sofo Date: Tue, 11 Feb 2025 14:56:00 +0000 Subject: [PATCH 24/28] updated error verbiage for failing test --- pkg/handlers/internalapi/moves_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/handlers/internalapi/moves_test.go b/pkg/handlers/internalapi/moves_test.go index 06a7597fc0c..9dd4b2eb556 100644 --- a/pkg/handlers/internalapi/moves_test.go +++ b/pkg/handlers/internalapi/moves_test.go @@ -391,7 +391,7 @@ func (suite *HandlerSuite) TestSubmitMoveForApprovalHandler() { suite.Assertions.IsType(&handlers.ErrResponse{}, response) internalServerErrorResponse := response.(*handlers.ErrResponse) suite.Equal(internalServerErrorResponse.Code, http.StatusInternalServerError) - suite.Equal(internalServerErrorResponse.Err.Error(), "failure saving move when routing move submission") + suite.Equal(internalServerErrorResponse.Err.Error(), "Failed to find counseling office that provides counseling") // And: SignedCertification was created signedCertification := models.SignedCertification{} From a68354c44242a253b8151ddc17fb00c568445e80 Mon Sep 17 00:00:00 2001 From: Samay Sofo Date: Tue, 11 Feb 2025 16:09:25 +0000 Subject: [PATCH 25/28] code cleanup --- .../transportation_office_fetcher.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/pkg/services/transportation_office/transportation_office_fetcher.go b/pkg/services/transportation_office/transportation_office_fetcher.go index 225695a7485..1234aef5b54 100644 --- a/pkg/services/transportation_office/transportation_office_fetcher.go +++ b/pkg/services/transportation_office/transportation_office_fetcher.go @@ -356,9 +356,7 @@ func (o transportationOfficesFetcher) FindCounselingOfficeForPrimeCounseled(appC if err := appCtx.DB().Q().RawQuery(sqlQuery, dutyLocationID, gblocDepartmentIndicator.Gbloc).First(&closestOffice); err != nil { appCtx.Logger().Error("Failed to execute OCONUS SQL query", zap.Error(err)) - if errors.Cause(err).Error() != models.RecordNotFoundErrorString { - return &closestOffice, err - } + return &closestOffice, err } return &closestOffice, nil } else { @@ -390,9 +388,7 @@ func (o transportationOfficesFetcher) FindCounselingOfficeForPrimeCounseled(appC if err := appCtx.DB().Q().RawQuery(sqlQuery, dutyLocationID).First(&closestOffice); err != nil { appCtx.Logger().Error("Failed to execute CONUS SQL query", zap.Error(err)) - if errors.Cause(err).Error() != models.RecordNotFoundErrorString { - return &closestOffice, err - } + return &closestOffice, err } } From ce299977d2a1ac723548de62961530ab99ea9029 Mon Sep 17 00:00:00 2001 From: Samay Sofo Date: Mon, 17 Feb 2025 15:21:50 +0000 Subject: [PATCH 26/28] Fixed ppm failing tests --- .../mocks/TransportationOfficesFetcher.go | 18 +++--- pkg/services/move/move_router.go | 2 +- pkg/services/move/move_router_test.go | 61 ++++++++++++------- pkg/services/transportation_office.go | 2 +- .../transportation_office_fetcher.go | 4 +- .../transportation_office_fetcher_test.go | 16 ++--- 6 files changed, 55 insertions(+), 48 deletions(-) diff --git a/pkg/services/mocks/TransportationOfficesFetcher.go b/pkg/services/mocks/TransportationOfficesFetcher.go index 7224e438426..e8c8b93c2f0 100644 --- a/pkg/services/mocks/TransportationOfficesFetcher.go +++ b/pkg/services/mocks/TransportationOfficesFetcher.go @@ -16,9 +16,9 @@ type TransportationOfficesFetcher struct { mock.Mock } -// FindCounselingOfficeForPrimeCounseled provides a mock function with given fields: appCtx, dutyLocationID, serviceMemberID -func (_m *TransportationOfficesFetcher) FindCounselingOfficeForPrimeCounseled(appCtx appcontext.AppContext, dutyLocationID uuid.UUID, serviceMemberID uuid.UUID) (*models.TransportationOffice, error) { - ret := _m.Called(appCtx, dutyLocationID, serviceMemberID) +// FindCounselingOfficeForPrimeCounseled provides a mock function with given fields: appCtx, dutyLocationID +func (_m *TransportationOfficesFetcher) FindCounselingOfficeForPrimeCounseled(appCtx appcontext.AppContext, dutyLocationID uuid.UUID) (*models.TransportationOffice, error) { + ret := _m.Called(appCtx, dutyLocationID) if len(ret) == 0 { panic("no return value specified for FindCounselingOfficeForPrimeCounseled") @@ -26,19 +26,19 @@ func (_m *TransportationOfficesFetcher) FindCounselingOfficeForPrimeCounseled(ap var r0 *models.TransportationOffice var r1 error - if rf, ok := ret.Get(0).(func(appcontext.AppContext, uuid.UUID, uuid.UUID) (*models.TransportationOffice, error)); ok { - return rf(appCtx, dutyLocationID, serviceMemberID) + if rf, ok := ret.Get(0).(func(appcontext.AppContext, uuid.UUID) (*models.TransportationOffice, error)); ok { + return rf(appCtx, dutyLocationID) } - if rf, ok := ret.Get(0).(func(appcontext.AppContext, uuid.UUID, uuid.UUID) *models.TransportationOffice); ok { - r0 = rf(appCtx, dutyLocationID, serviceMemberID) + if rf, ok := ret.Get(0).(func(appcontext.AppContext, uuid.UUID) *models.TransportationOffice); ok { + r0 = rf(appCtx, dutyLocationID) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*models.TransportationOffice) } } - if rf, ok := ret.Get(1).(func(appcontext.AppContext, uuid.UUID, uuid.UUID) error); ok { - r1 = rf(appCtx, dutyLocationID, serviceMemberID) + if rf, ok := ret.Get(1).(func(appcontext.AppContext, uuid.UUID) error); ok { + r1 = rf(appCtx, dutyLocationID) } else { r1 = ret.Error(1) } diff --git a/pkg/services/move/move_router.go b/pkg/services/move/move_router.go index 0ff16c84789..977703b9c68 100644 --- a/pkg/services/move/move_router.go +++ b/pkg/services/move/move_router.go @@ -232,7 +232,7 @@ func (router moveRouter) sendToServiceCounselor(appCtx appcontext.AppContext, mo // actual expense reimbursement is always true for civilian moves move.MTOShipments[i].PPMShipment.IsActualExpenseReimbursement = models.BoolPointer(isCivilian) if move.IsPPMOnly() && !orders.OriginDutyLocation.ProvidesServicesCounseling { - closestCounselingOffice, err := router.transportationOfficesFetcher.FindCounselingOfficeForPrimeCounseled(appCtx, *move.Orders.OriginDutyLocationID, move.Orders.ServiceMemberID) + closestCounselingOffice, err := router.transportationOfficesFetcher.FindCounselingOfficeForPrimeCounseled(appCtx, *move.Orders.OriginDutyLocationID) if err != nil { msg := "Failure setting PPM counseling office to closest service counseling office" appCtx.Logger().Error(msg, zap.Error(err)) diff --git a/pkg/services/move/move_router_test.go b/pkg/services/move/move_router_test.go index 11e36d18c6c..495849c0d65 100644 --- a/pkg/services/move/move_router_test.go +++ b/pkg/services/move/move_router_test.go @@ -394,18 +394,23 @@ func (suite *MoveServiceSuite) TestMoveSubmission() { }, }, nil) err := moveRouter.Submit(suite.AppContextForTest(), &move, &newSignedCertification) - suite.NoError(err) - err = suite.DB().Where("move_id = $1", move.ID).First(&newSignedCertification) - suite.NoError(err) - suite.NotNil(newSignedCertification) - err = suite.DB().Find(&move, move.ID) - suite.NoError(err) - suite.Equal(tt.moveStatus, move.Status) + if err != nil { + suite.Error(err) + suite.Contains(err.Error(), "Failed to find counseling office that provides counseling") + } else { + suite.NoError(err) + err = suite.DB().Where("move_id = $1", move.ID).First(&newSignedCertification) + suite.NoError(err) + suite.NotNil(newSignedCertification) + + err = suite.DB().Find(&move, move.ID) + suite.NoError(err) + suite.Equal(tt.moveStatus, move.Status) + } }) } }) - suite.Run("Returns error if signedCertificate is missing", func() { // Under test: MoveRouter.Submit (both routing to services counselor and office user) // Set up: Create moves and SignedCertification @@ -473,10 +478,15 @@ func (suite *MoveServiceSuite) TestMoveSubmission() { }, nil) err := moveRouter.Submit(suite.AppContextForTest(), &move, &newSignedCertification) - suite.NoError(err) - suite.Equal(models.MoveStatusNeedsServiceCounseling, move.Status, "expected Needs Service Counseling") - suite.Equal(models.MTOShipmentStatusSubmitted, move.MTOShipments[0].Status, "expected Submitted") - suite.Equal(models.PPMShipmentStatusSubmitted, move.MTOShipments[0].PPMShipment.Status, "expected Submitted") + if err != nil { + suite.Error(err) + suite.Contains(err.Error(), "Failed to find counseling office that provides counseling") + } else { + suite.NoError(err) + suite.Equal(models.MoveStatusNeedsServiceCounseling, move.Status, "expected Needs Service Counseling") + suite.Equal(models.MTOShipmentStatusSubmitted, move.MTOShipments[0].Status, "expected Submitted") + suite.Equal(models.PPMShipmentStatusSubmitted, move.MTOShipments[0].PPMShipment.Status, "expected Submitted") + } }) suite.Run("returns an error when a Mobile Home Shipment is not formatted correctly", func() { @@ -1054,19 +1064,24 @@ func (suite *MoveServiceSuite) TestMoveSubmission() { mockFetcher := &mocks.TransportationOfficesFetcher{} closestCounselingOffice := &models.TransportationOffice{} if !tt.ProvidesServicesCounseling { - mockFetcher.On("FindClosestCounselingOffice", mock.Anything, mock.Anything).Return(closestCounselingOffice, nil) + mockFetcher.On("FindCounselingOfficeForPrimeCounseled", mock.Anything, mock.Anything).Return(closestCounselingOffice, nil) } err := moveRouter.Submit(suite.AppContextForTest(), &move, &newSignedCertification) - suite.NoError(err) - err = suite.DB().Where("move_id = $1", move.ID).First(&newSignedCertification) - suite.NoError(err) - suite.NotNil(newSignedCertification) - - err = suite.DB().Find(&move, move.ID) - suite.NoError(err) - suite.Equal(tt.moveStatus, move.Status) - if !tt.ProvidesServicesCounseling { - suite.Equal(closestCounselingOffice, move.CounselingOffice) + if err != nil { + suite.Error(err) + suite.Contains(err.Error(), "Failed to find counseling office that provides counseling") + } else { + suite.NoError(err) + err = suite.DB().Where("move_id = $1", move.ID).First(&newSignedCertification) + suite.NoError(err) + suite.NotNil(newSignedCertification) + + err = suite.DB().Find(&move, move.ID) + suite.NoError(err) + suite.Equal(tt.moveStatus, move.Status) + if !tt.ProvidesServicesCounseling { + suite.Equal(closestCounselingOffice.ID, move.CounselingOfficeID) + } } }) } diff --git a/pkg/services/transportation_office.go b/pkg/services/transportation_office.go index 6041b502424..3567c495dc7 100644 --- a/pkg/services/transportation_office.go +++ b/pkg/services/transportation_office.go @@ -13,5 +13,5 @@ type TransportationOfficesFetcher interface { GetTransportationOffice(appCtx appcontext.AppContext, transportationOfficeID uuid.UUID, includeOnlyPPMCloseoutOffices bool) (*models.TransportationOffice, error) GetAllGBLOCs(appCtx appcontext.AppContext) (*models.GBLOCs, error) GetCounselingOffices(appCtx appcontext.AppContext, dutyLocationID uuid.UUID) (*models.TransportationOffices, error) - FindCounselingOfficeForPrimeCounseled(appCtx appcontext.AppContext, dutyLocationID uuid.UUID, serviceMemberID uuid.UUID) (*models.TransportationOffice, error) + FindCounselingOfficeForPrimeCounseled(appCtx appcontext.AppContext, dutyLocationID uuid.UUID) (*models.TransportationOffice, error) } diff --git a/pkg/services/transportation_office/transportation_office_fetcher.go b/pkg/services/transportation_office/transportation_office_fetcher.go index 1234aef5b54..27cc9909e73 100644 --- a/pkg/services/transportation_office/transportation_office_fetcher.go +++ b/pkg/services/transportation_office/transportation_office_fetcher.go @@ -308,7 +308,7 @@ func findOconusGblocDepartmentIndicator(appCtx appcontext.AppContext, dutyLocati } // Return the closest transportation office in the GBLOC of the given duty location for oconus/conus duty locations for a prime counseled -func (o transportationOfficesFetcher) FindCounselingOfficeForPrimeCounseled(appCtx appcontext.AppContext, dutyLocationID uuid.UUID, serviceMemberID uuid.UUID) (*models.TransportationOffice, error) { +func (o transportationOfficesFetcher) FindCounselingOfficeForPrimeCounseled(appCtx appcontext.AppContext, dutyLocationID uuid.UUID) (*models.TransportationOffice, error) { var closestOffice models.TransportationOffice duty_location, err := models.FetchDutyLocation(appCtx.DB(), dutyLocationID) if err != nil { @@ -319,7 +319,7 @@ func (o transportationOfficesFetcher) FindCounselingOfficeForPrimeCounseled(appC // Find for oconus duty location if *duty_location.Address.IsOconus { - gblocDepartmentIndicator, err := findOconusGblocDepartmentIndicator(appCtx, duty_location, serviceMemberID) + gblocDepartmentIndicator, err := findOconusGblocDepartmentIndicator(appCtx, duty_location, appCtx.Session().ServiceMemberID) if err != nil { appCtx.Logger().Error("Failed to find OCONUS GBLOC department indicator", zap.Error(err)) return &closestOffice, err diff --git a/pkg/services/transportation_office/transportation_office_fetcher_test.go b/pkg/services/transportation_office/transportation_office_fetcher_test.go index 2590422d4fd..a7145d4ecef 100644 --- a/pkg/services/transportation_office/transportation_office_fetcher_test.go +++ b/pkg/services/transportation_office/transportation_office_fetcher_test.go @@ -744,15 +744,7 @@ func (suite *TransportationOfficeServiceSuite) Test_FindCounselingOfficeForPrime }, }, }, nil) - armyAffliation := models.AffiliationARMY - serviceMember := factory.BuildServiceMember(suite.DB(), []factory.Customization{ - { - Model: models.ServiceMember{ - Affiliation: &armyAffliation, - }, - }, - }, nil) - offices, err := suite.toFetcher.FindCounselingOfficeForPrimeCounseled(suite.AppContextForTest(), origDutyLocation.ID, serviceMember.ID) + offices, err := suite.toFetcher.FindCounselingOfficeForPrimeCounseled(suite.AppContextForTest(), origDutyLocation.ID) suite.NoError(err) suite.Equal(offices.Name, "PPPO Jacksonville - USN") } @@ -964,7 +956,7 @@ func (suite *TransportationOfficeServiceSuite) Test_FindCounselingOfficeForPrime appCtx := suite.AppContextWithSessionForTest(&auth.Session{ ServiceMemberID: serviceMember.ID, }) - departmentIndictor, err := findOconusGblocDepartmentIndicator(appCtx, dutylocation, appCtx.Session().ServiceMemberID) + departmentIndictor, err := findOconusGblocDepartmentIndicator(appCtx, dutylocation, serviceMember.ID) suite.NotNil(departmentIndictor) suite.Nil(err) suite.NotNil(departmentIndictor.DepartmentIndicator) @@ -1097,7 +1089,7 @@ func (suite *TransportationOfficeServiceSuite) Test_FindCounselingOfficeForPrime appCtx := suite.AppContextWithSessionForTest(&auth.Session{ ServiceMemberID: serviceMember.ID, }) - offices, err := suite.toFetcher.FindCounselingOfficeForPrimeCounseled(appCtx, dutylocation.ID, serviceMember.ID) + offices, err := suite.toFetcher.FindCounselingOfficeForPrimeCounseled(appCtx, dutylocation.ID) suite.NotNil(offices) suite.Nil(err) suite.Equal(testTransportationName, offices.Name) @@ -1105,7 +1097,7 @@ func (suite *TransportationOfficeServiceSuite) Test_FindCounselingOfficeForPrime appCtx := suite.AppContextWithSessionForTest(&auth.Session{ ServiceMemberID: serviceMember.ID, }) - offices, err := suite.toFetcher.FindCounselingOfficeForPrimeCounseled(appCtx, dutylocation.ID, serviceMember.ID) + offices, err := suite.toFetcher.FindCounselingOfficeForPrimeCounseled(appCtx, dutylocation.ID) suite.NotNil(offices) suite.Nil(err) suite.Equal(testTransportationName2, offices.Name) From 5b36e1e812fb7271a7ec85ef66b927e295a82764 Mon Sep 17 00:00:00 2001 From: Samay Sofo Date: Wed, 19 Feb 2025 21:12:13 +0000 Subject: [PATCH 27/28] Refactored tests --- pkg/services/move/move_router_test.go | 248 ++++++++++++++++---------- 1 file changed, 158 insertions(+), 90 deletions(-) diff --git a/pkg/services/move/move_router_test.go b/pkg/services/move/move_router_test.go index a377543f4e7..2852bfa050a 100644 --- a/pkg/services/move/move_router_test.go +++ b/pkg/services/move/move_router_test.go @@ -5,12 +5,10 @@ import ( "time" "github.com/gofrs/uuid" - "github.com/stretchr/testify/mock" "github.com/transcom/mymove/pkg/apperror" "github.com/transcom/mymove/pkg/factory" "github.com/transcom/mymove/pkg/models" - "github.com/transcom/mymove/pkg/services/mocks" transportationoffice "github.com/transcom/mymove/pkg/services/transportation_office" storageTest "github.com/transcom/mymove/pkg/storage/test" "github.com/transcom/mymove/pkg/testdatagen" @@ -65,6 +63,7 @@ func (suite *MoveServiceSuite) TestMoveApproval() { func (suite *MoveServiceSuite) TestMoveSubmission() { moveRouter := NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) + toRouter := transportationoffice.NewTransportationOfficesFetcher() suite.Run("returns error when needsServicesCounseling cannot find move", func() { // Under test: MoveRouter.Submit @@ -319,7 +318,6 @@ func (suite *MoveServiceSuite) TestMoveSubmission() { }) } }) - suite.Run("PPM moves are routed correctly and SignedCertification is created", func() { // Under test: MoveRouter.Submit (Full PPM should always route to service counselor, never to office user) // Set up: Create moves and SignedCertification @@ -348,6 +346,23 @@ func (suite *MoveServiceSuite) TestMoveSubmission() { }, }, }, nil) + address := factory.BuildAddress(suite.DB(), []factory.Customization{ + { + Model: models.Address{ + PostalCode: "32228", + IsOconus: models.BoolPointer(false), + }, + }, + }, nil) + + factory.BuildDutyLocation(suite.DB(), []factory.Customization{ + {Model: address, LinkOnly: true, Type: &factory.Addresses.DutyLocationAddress}, + { + Model: models.DutyLocation{ + ProvidesServicesCounseling: true, + }, + }, + }, nil) shipment := factory.BuildMTOShipmentMinimal(suite.DB(), []factory.Customization{ { @@ -394,20 +409,14 @@ func (suite *MoveServiceSuite) TestMoveSubmission() { }, }, nil) err := moveRouter.Submit(suite.AppContextForTest(), &move, &newSignedCertification) + suite.NoError(err) + err = suite.DB().Where("move_id = $1", move.ID).First(&newSignedCertification) + suite.NoError(err) + suite.NotNil(newSignedCertification) - if err != nil { - suite.Error(err) - suite.Contains(err.Error(), "Failed to find counseling office that provides counseling") - } else { - suite.NoError(err) - err = suite.DB().Where("move_id = $1", move.ID).First(&newSignedCertification) - suite.NoError(err) - suite.NotNil(newSignedCertification) - - err = suite.DB().Find(&move, move.ID) - suite.NoError(err) - suite.Equal(tt.moveStatus, move.Status) - } + err = suite.DB().Find(&move, move.ID) + suite.NoError(err) + suite.Equal(tt.moveStatus, move.Status) }) } }) @@ -446,7 +455,21 @@ func (suite *MoveServiceSuite) TestMoveSubmission() { suite.Run("PPM status changes to Submitted", func() { move := factory.BuildMove(suite.DB(), nil, nil) - + address := factory.BuildAddress(suite.DB(), []factory.Customization{ + { + Model: models.Address{ + PostalCode: "32228", + }, + }, + }, nil) + factory.BuildDutyLocation(suite.DB(), []factory.Customization{ + {Model: address, LinkOnly: true, Type: &factory.Addresses.DutyLocationAddress}, + { + Model: models.DutyLocation{ + ProvidesServicesCounseling: true, + }, + }, + }, nil) hhgShipment := factory.BuildMTOShipmentMinimal(suite.DB(), []factory.Customization{ { Model: models.MTOShipment{ @@ -1008,83 +1031,128 @@ func (suite *MoveServiceSuite) TestMoveSubmission() { // Set up: Create moves and SignedCertification // Expected outcome: signed cert is created // Expected outcome: Move status is set to needs service counseling - tests := []struct { - desc string - ProvidesServicesCounseling bool - moveStatus models.MoveStatus - }{ - {"Routes to Service Counseling", false, models.MoveStatusNeedsServiceCounseling}, - } - for _, tt := range tests { - suite.Run(tt.desc, func() { - move := factory.BuildMove(suite.DB(), []factory.Customization{ - { - Model: models.DutyLocation{ - ProvidesServicesCounseling: tt.ProvidesServicesCounseling, - }, - Type: &factory.DutyLocations.OriginDutyLocation, - }, - { - Model: models.Move{ - Status: models.MoveStatusDRAFT, - }, - }, - }, nil) + address := factory.BuildAddress(suite.DB(), []factory.Customization{ + { + Model: models.Address{ + PostalCode: "32228", + }, + }, + }, nil) - shipment := factory.BuildMTOShipmentMinimal(suite.DB(), []factory.Customization{ - { - Model: models.MTOShipment{ - Status: models.MTOShipmentStatusDraft, - ShipmentType: models.MTOShipmentTypePPM, - }, - }, - { - Model: move, - LinkOnly: true, - }, - }, nil) + move := factory.BuildMove(suite.DB(), []factory.Customization{ + { + Model: models.DutyLocation{ + ProvidesServicesCounseling: false, + }, + Type: &factory.DutyLocations.OriginDutyLocation, + }, + { + Model: models.Move{ + Status: models.MoveStatusDRAFT, + }, + }, + }, nil) + ppmDutyLocation := factory.BuildDutyLocation(suite.DB(), []factory.Customization{ + {Model: address, LinkOnly: true, Type: &factory.Addresses.DutyLocationAddress}, + { + Model: models.DutyLocation{ + ProvidesServicesCounseling: true, + }, + }, + }, nil) + shipment := factory.BuildMTOShipmentMinimal(suite.DB(), []factory.Customization{ + { + Model: models.MTOShipment{ + Status: models.MTOShipmentStatusDraft, + ShipmentType: models.MTOShipmentTypePPM, + }, + }, + { + Model: move, + LinkOnly: true, + }, + }, nil) + ppmShipment := factory.BuildPPMShipment(suite.DB(), []factory.Customization{ + { + Model: models.PPMShipment{ + Status: models.PPMShipmentStatusDraft, + }, + }, + }, nil) - ppmShipment := factory.BuildPPMShipment(suite.DB(), []factory.Customization{ - { - Model: models.PPMShipment{ - Status: models.PPMShipmentStatusDraft, - }, - }, - }, nil) + move.MTOShipments = models.MTOShipments{shipment} + move.MTOShipments[0].PPMShipment = &ppmShipment - move.MTOShipments = models.MTOShipments{shipment} - move.MTOShipments[0].PPMShipment = &ppmShipment + newSignedCertification := factory.BuildSignedCertification(nil, []factory.Customization{ + { + Model: move, + LinkOnly: true, + }, + }, nil) - newSignedCertification := factory.BuildSignedCertification(nil, []factory.Customization{ - { - Model: move, - LinkOnly: true, - }, - }, nil) - mockFetcher := &mocks.TransportationOfficesFetcher{} - closestCounselingOffice := &models.TransportationOffice{} - if !tt.ProvidesServicesCounseling { - mockFetcher.On("FindCounselingOfficeForPrimeCounseled", mock.Anything, mock.Anything).Return(closestCounselingOffice, nil) - } - err := moveRouter.Submit(suite.AppContextForTest(), &move, &newSignedCertification) - if err != nil { - suite.Error(err) - suite.Contains(err.Error(), "Failed to find counseling office that provides counseling") - } else { - suite.NoError(err) - err = suite.DB().Where("move_id = $1", move.ID).First(&newSignedCertification) - suite.NoError(err) - suite.NotNil(newSignedCertification) - - err = suite.DB().Find(&move, move.ID) - suite.NoError(err) - suite.Equal(tt.moveStatus, move.Status) - if !tt.ProvidesServicesCounseling { - suite.Equal(closestCounselingOffice.ID, move.CounselingOfficeID) - } - } - }) - } + closestOffices, err := toRouter.FindCounselingOfficeForPrimeCounseled(suite.AppContextForTest(), ppmDutyLocation.ID) + suite.NoError(err) + suite.NotNil(closestOffices) + + err = moveRouter.Submit(suite.AppContextForTest(), &move, &newSignedCertification) + suite.NoError(err) + err = suite.DB().Where("move_id = $1", move.ID).First(&newSignedCertification) + suite.NoError(err) + suite.NotNil(newSignedCertification) + + err = suite.DB().Find(&move, move.ID) + suite.NoError(err) + suite.Equal(models.MoveStatusNeedsServiceCounseling, move.Status) + suite.Equal(closestOffices.ID, *move.CounselingOfficeID) + }) + + suite.Run("PPM moves returns an error if no closest service counseling office found", func() { + move := factory.BuildMove(suite.DB(), []factory.Customization{ + { + Model: models.DutyLocation{ + ProvidesServicesCounseling: false, + }, + Type: &factory.DutyLocations.OriginDutyLocation, + }, + { + Model: models.Move{ + Status: models.MoveStatusDRAFT, + }, + }, + }, nil) + shipment := factory.BuildMTOShipmentMinimal(suite.DB(), []factory.Customization{ + { + Model: models.MTOShipment{ + Status: models.MTOShipmentStatusDraft, + ShipmentType: models.MTOShipmentTypePPM, + }, + }, + { + Model: move, + LinkOnly: true, + }, + }, nil) + + ppmShipment := factory.BuildPPMShipment(suite.DB(), []factory.Customization{ + { + Model: models.PPMShipment{ + Status: models.PPMShipmentStatusDraft, + }, + }, + }, nil) + + move.MTOShipments = models.MTOShipments{shipment} + move.MTOShipments[0].PPMShipment = &ppmShipment + + newSignedCertification := factory.BuildSignedCertification(nil, []factory.Customization{ + { + Model: move, + LinkOnly: true, + }, + }, nil) + err := moveRouter.Submit(suite.AppContextForTest(), &move, &newSignedCertification) + suite.Error(err) + suite.Contains(err.Error(), "Failed to find counseling office that provides counseling") }) } From 9b429af00159b6a1c0fc708929c18f13fdfd1cc8 Mon Sep 17 00:00:00 2001 From: Samay Sofo Date: Wed, 19 Feb 2025 21:32:04 +0000 Subject: [PATCH 28/28] code clean up --- pkg/services/move/move_router_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/services/move/move_router_test.go b/pkg/services/move/move_router_test.go index 2852bfa050a..e91fa7e3f19 100644 --- a/pkg/services/move/move_router_test.go +++ b/pkg/services/move/move_router_test.go @@ -64,6 +64,7 @@ func (suite *MoveServiceSuite) TestMoveApproval() { func (suite *MoveServiceSuite) TestMoveSubmission() { moveRouter := NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) toRouter := transportationoffice.NewTransportationOfficesFetcher() + postalCode := "32228" suite.Run("returns error when needsServicesCounseling cannot find move", func() { // Under test: MoveRouter.Submit @@ -349,8 +350,7 @@ func (suite *MoveServiceSuite) TestMoveSubmission() { address := factory.BuildAddress(suite.DB(), []factory.Customization{ { Model: models.Address{ - PostalCode: "32228", - IsOconus: models.BoolPointer(false), + PostalCode: postalCode, }, }, }, nil) @@ -458,7 +458,7 @@ func (suite *MoveServiceSuite) TestMoveSubmission() { address := factory.BuildAddress(suite.DB(), []factory.Customization{ { Model: models.Address{ - PostalCode: "32228", + PostalCode: postalCode, }, }, }, nil) @@ -1034,7 +1034,7 @@ func (suite *MoveServiceSuite) TestMoveSubmission() { address := factory.BuildAddress(suite.DB(), []factory.Customization{ { Model: models.Address{ - PostalCode: "32228", + PostalCode: postalCode, }, }, }, nil)