From a89fca014da7183dbe35b8522a58721165a56750 Mon Sep 17 00:00:00 2001 From: loganwc Date: Tue, 29 Oct 2024 16:07:30 +0000 Subject: [PATCH 01/21] estimated prices now calculates for NTS-R shipments --- pkg/services/mto_service_item/mto_service_item_creator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/services/mto_service_item/mto_service_item_creator.go b/pkg/services/mto_service_item/mto_service_item_creator.go index 647cd2d641c..c14ebc4a573 100644 --- a/pkg/services/mto_service_item/mto_service_item_creator.go +++ b/pkg/services/mto_service_item/mto_service_item_creator.go @@ -580,7 +580,7 @@ func (o *mtoServiceItemCreator) CreateMTOServiceItem(appCtx appcontext.AppContex // DLH, DPK, DOP, DDP, DUPK // NTS-release requested pickup dates are for handle out, their pricing is handled differently as their locations are based on storage facilities, not pickup locations - if mtoShipment.PrimeEstimatedWeight != nil && mtoShipment.RequestedPickupDate != nil && mtoShipment.ShipmentType != models.MTOShipmentTypeHHGOutOfNTSDom { + if mtoShipment.PrimeEstimatedWeight != nil && mtoShipment.RequestedPickupDate != nil { serviceItemEstimatedPrice, err := o.findEstimatedPrice(appCtx, serviceItem, mtoShipment) if serviceItemEstimatedPrice != 0 && err == nil { serviceItem.PricingEstimate = &serviceItemEstimatedPrice From 78efbd4f686964b15c293662ef19c8a143c1a375 Mon Sep 17 00:00:00 2001 From: loganwc Date: Wed, 30 Oct 2024 22:00:53 +0000 Subject: [PATCH 02/21] updated comment --- pkg/services/mto_service_item/mto_service_item_creator.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/pkg/services/mto_service_item/mto_service_item_creator.go b/pkg/services/mto_service_item/mto_service_item_creator.go index c14ebc4a573..11433cb8378 100644 --- a/pkg/services/mto_service_item/mto_service_item_creator.go +++ b/pkg/services/mto_service_item/mto_service_item_creator.go @@ -578,8 +578,6 @@ func (o *mtoServiceItemCreator) CreateMTOServiceItem(appCtx appcontext.AppContex // if estimated weight for shipment provided by the prime, calculate the estimated prices for // DLH, DPK, DOP, DDP, DUPK - - // NTS-release requested pickup dates are for handle out, their pricing is handled differently as their locations are based on storage facilities, not pickup locations if mtoShipment.PrimeEstimatedWeight != nil && mtoShipment.RequestedPickupDate != nil { serviceItemEstimatedPrice, err := o.findEstimatedPrice(appCtx, serviceItem, mtoShipment) if serviceItemEstimatedPrice != 0 && err == nil { From 0c62a1460ddf6316d350dfd57eda4f4308e52600 Mon Sep 17 00:00:00 2001 From: loganwc Date: Tue, 12 Nov 2024 16:44:49 +0000 Subject: [PATCH 03/21] now using 110% of estimated weight for NTS-R --- .../mto_service_item_creator.go | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/pkg/services/mto_service_item/mto_service_item_creator.go b/pkg/services/mto_service_item/mto_service_item_creator.go index 11433cb8378..b50a46eb615 100644 --- a/pkg/services/mto_service_item/mto_service_item_creator.go +++ b/pkg/services/mto_service_item/mto_service_item_creator.go @@ -54,7 +54,12 @@ func (o *mtoServiceItemCreator) findEstimatedPrice(appCtx appcontext.AppContext, requestedPickupDate := *mtoShipment.RequestedPickupDate currTime := time.Now() var distance int - primeEstimatedWeight := *mtoShipment.PrimeEstimatedWeight + primeEstimatedWeightForFSC := *mtoShipment.PrimeEstimatedWeight + primeEstimatedWeight := mtoShipment.PrimeEstimatedWeight + if mtoShipment.ShipmentType == models.MTOShipmentTypeHHGOutOfNTSDom { + newWeight := int(primeEstimatedWeight.Float64() * 1.1) + primeEstimatedWeight = (*unit.Pound)(&newWeight) + } contractCode, err := FetchContractCode(appCtx, currTime) if err != nil { @@ -73,7 +78,7 @@ func (o *mtoServiceItemCreator) findEstimatedPrice(appCtx appcontext.AppContext, return 0, err } - price, _, err = o.originPricer.Price(appCtx, contractCode, requestedPickupDate, *mtoShipment.PrimeEstimatedWeight, domesticServiceArea.ServiceArea, isPPM) + price, _, err = o.originPricer.Price(appCtx, contractCode, requestedPickupDate, *primeEstimatedWeight, domesticServiceArea.ServiceArea, isPPM) if err != nil { return 0, err } @@ -86,7 +91,7 @@ func (o *mtoServiceItemCreator) findEstimatedPrice(appCtx appcontext.AppContext, servicesScheduleOrigin := domesticServiceArea.ServicesSchedule - price, _, err = o.packPricer.Price(appCtx, contractCode, requestedPickupDate, *mtoShipment.PrimeEstimatedWeight, servicesScheduleOrigin, isPPM) + price, _, err = o.packPricer.Price(appCtx, contractCode, requestedPickupDate, *primeEstimatedWeight, servicesScheduleOrigin, isPPM) if err != nil { return 0, err } @@ -101,7 +106,7 @@ func (o *mtoServiceItemCreator) findEstimatedPrice(appCtx appcontext.AppContext, } } - price, _, err = o.destinationPricer.Price(appCtx, contractCode, requestedPickupDate, *mtoShipment.PrimeEstimatedWeight, domesticServiceArea.ServiceArea, isPPM) + price, _, err = o.destinationPricer.Price(appCtx, contractCode, requestedPickupDate, *primeEstimatedWeight, domesticServiceArea.ServiceArea, isPPM) if err != nil { return 0, err } @@ -114,7 +119,7 @@ func (o *mtoServiceItemCreator) findEstimatedPrice(appCtx appcontext.AppContext, serviceScheduleDestination := domesticServiceArea.ServicesSchedule - price, _, err = o.unpackPricer.Price(appCtx, contractCode, requestedPickupDate, *mtoShipment.PrimeEstimatedWeight, serviceScheduleDestination, isPPM) + price, _, err = o.unpackPricer.Price(appCtx, contractCode, requestedPickupDate, *primeEstimatedWeight, serviceScheduleDestination, isPPM) if err != nil { return 0, err } @@ -132,7 +137,7 @@ func (o *mtoServiceItemCreator) findEstimatedPrice(appCtx appcontext.AppContext, return 0, err } } - price, _, err = o.linehaulPricer.Price(appCtx, contractCode, requestedPickupDate, unit.Miles(distance), *mtoShipment.PrimeEstimatedWeight, domesticServiceArea.ServiceArea, isPPM) + price, _, err = o.linehaulPricer.Price(appCtx, contractCode, requestedPickupDate, unit.Miles(distance), *primeEstimatedWeight, domesticServiceArea.ServiceArea, isPPM) if err != nil { return 0, err } @@ -148,7 +153,7 @@ func (o *mtoServiceItemCreator) findEstimatedPrice(appCtx appcontext.AppContext, return 0, err } } - price, _, err = o.shorthaulPricer.Price(appCtx, contractCode, requestedPickupDate, unit.Miles(distance), *mtoShipment.PrimeEstimatedWeight, domesticServiceArea.ServiceArea) + price, _, err = o.shorthaulPricer.Price(appCtx, contractCode, requestedPickupDate, unit.Miles(distance), *primeEstimatedWeight, domesticServiceArea.ServiceArea) if err != nil { return 0, err } @@ -172,7 +177,7 @@ func (o *mtoServiceItemCreator) findEstimatedPrice(appCtx appcontext.AppContext, } } - fscWeightBasedDistanceMultiplier, err := LookupFSCWeightBasedDistanceMultiplier(appCtx, primeEstimatedWeight) + fscWeightBasedDistanceMultiplier, err := LookupFSCWeightBasedDistanceMultiplier(appCtx, primeEstimatedWeightForFSC) if err != nil { return 0, err } @@ -184,7 +189,7 @@ func (o *mtoServiceItemCreator) findEstimatedPrice(appCtx appcontext.AppContext, if err != nil { return 0, err } - price, _, err = o.fuelSurchargePricer.Price(appCtx, pickupDateForFSC, unit.Miles(distance), primeEstimatedWeight, fscWeightBasedDistanceMultiplierFloat, eiaFuelPrice, isPPM) + price, _, err = o.fuelSurchargePricer.Price(appCtx, pickupDateForFSC, unit.Miles(distance), primeEstimatedWeightForFSC, fscWeightBasedDistanceMultiplierFloat, eiaFuelPrice, isPPM) if err != nil { return 0, err } From f41962515f9bb573a9b847b21e9016068a30d83c Mon Sep 17 00:00:00 2001 From: loganwc Date: Wed, 13 Nov 2024 15:14:37 +0000 Subject: [PATCH 04/21] most of the tests but they don't work --- pkg/db/sequence/random_sequencer_test.go | 70 ++--- pkg/db/sequence/sequencer_test.go | 42 +-- .../ghcrateengine/pricer_query_helpers.go | 1 + pkg/services/mocks/MTOServiceItemCreator.go | 30 ++ pkg/services/mto_service_item.go | 2 + .../mto_service_item_creator.go | 15 +- .../mto_service_item_creator_test.go | 269 ++++++++++++++++++ 7 files changed, 368 insertions(+), 61 deletions(-) diff --git a/pkg/db/sequence/random_sequencer_test.go b/pkg/db/sequence/random_sequencer_test.go index 053060ce54e..b5c31481c0e 100644 --- a/pkg/db/sequence/random_sequencer_test.go +++ b/pkg/db/sequence/random_sequencer_test.go @@ -1,37 +1,37 @@ package sequence -const testMin int64 = 10 -const testMax int64 = 99 - -func (suite *SequenceSuite) TestRandomNextVal() { - sequencer, err := NewRandomSequencer(testMin, testMax) - suite.FatalNoError(err) - - // Try 100 random numbers and make sure they're all between min and max, inclusive. - for i := 0; i < 100; i++ { - nextVal, err := sequencer.NextVal(suite.AppContextForTest()) - suite.NoError(err, "Error getting next value of sequence") - - suite.True(nextVal >= testMin && nextVal <= testMax, - "NextVal returned %d, but range was %d to %d inclusive", nextVal, testMin, testMax) - } -} - -func (suite *SequenceSuite) TestRandomSetVal() { - sequencer, err := NewRandomSequencer(testMin, testMax) - suite.FatalNoError(err) - - // This should be a no-op; just make sure it doesn't throw any errors. - err = sequencer.SetVal(suite.AppContextForTest(), 30) - suite.NoError(err, "Error setting value of sequence") -} - -func (suite *SequenceSuite) TestRandomConstructorErrors() { - sequencer, err := NewRandomSequencer(-3, 10) - suite.Nil(sequencer) - suite.Error(err) - - sequencer, err = NewRandomSequencer(20, 10) - suite.Nil(sequencer) - suite.Error(err) -} +// const testMin int64 = 10 +// const testMax int64 = 99 + +// func (suite *SequenceSuite) TestRandomNextVal() { +// sequencer, err := NewRandomSequencer(testMin, testMax) +// suite.FatalNoError(err) + +// // Try 100 random numbers and make sure they're all between min and max, inclusive. +// for i := 0; i < 100; i++ { +// nextVal, err := sequencer.NextVal(suite.AppContextForTest()) +// suite.NoError(err, "Error getting next value of sequence") + +// suite.True(nextVal >= testMin && nextVal <= testMax, +// "NextVal returned %d, but range was %d to %d inclusive", nextVal, testMin, testMax) +// } +// } + +// func (suite *SequenceSuite) TestRandomSetVal() { +// sequencer, err := NewRandomSequencer(testMin, testMax) +// suite.FatalNoError(err) + +// // This should be a no-op; just make sure it doesn't throw any errors. +// err = sequencer.SetVal(suite.AppContextForTest(), 30) +// suite.NoError(err, "Error setting value of sequence") +// } + +// func (suite *SequenceSuite) TestRandomConstructorErrors() { +// sequencer, err := NewRandomSequencer(-3, 10) +// suite.Nil(sequencer) +// suite.Error(err) + +// sequencer, err = NewRandomSequencer(20, 10) +// suite.Nil(sequencer) +// suite.Error(err) +// } diff --git a/pkg/db/sequence/sequencer_test.go b/pkg/db/sequence/sequencer_test.go index 5dd06751e01..c3976d5ba0e 100644 --- a/pkg/db/sequence/sequencer_test.go +++ b/pkg/db/sequence/sequencer_test.go @@ -1,29 +1,29 @@ package sequence -import ( - "testing" +// import ( +// "testing" - "github.com/stretchr/testify/suite" +// "github.com/stretchr/testify/suite" - "github.com/transcom/mymove/pkg/testingsuite" -) +// "github.com/transcom/mymove/pkg/testingsuite" +// ) -type SequenceSuite struct { - *testingsuite.PopTestSuite -} +// type SequenceSuite struct { +// *testingsuite.PopTestSuite +// } -func (suite *SequenceSuite) SetupTest() { - err := suite.DB().RawQuery("CREATE SEQUENCE IF NOT EXISTS test_sequence;").Exec() - suite.NoError(err, "Error creating test sequence") - err = suite.DB().RawQuery("SELECT setval($1, 1);", testSequence).Exec() - suite.NoError(err, "Error resetting sequence") -} +// func (suite *SequenceSuite) SetupTest() { +// err := suite.DB().RawQuery("CREATE SEQUENCE IF NOT EXISTS test_sequence;").Exec() +// suite.NoError(err, "Error creating test sequence") +// err = suite.DB().RawQuery("SELECT setval($1, 1);", testSequence).Exec() +// suite.NoError(err, "Error resetting sequence") +// } -func TestSequenceSuite(t *testing.T) { +// func TestSequenceSuite(t *testing.T) { - hs := &SequenceSuite{ - PopTestSuite: testingsuite.NewPopTestSuite(testingsuite.CurrentPackage(), testingsuite.WithPerTestTransaction()), - } - suite.Run(t, hs) - hs.PopTestSuite.TearDown() -} +// hs := &SequenceSuite{ +// PopTestSuite: testingsuite.NewPopTestSuite(testingsuite.CurrentPackage(), testingsuite.WithPerTestTransaction()), +// } +// suite.Run(t, hs) +// hs.PopTestSuite.TearDown() +// } diff --git a/pkg/services/ghcrateengine/pricer_query_helpers.go b/pkg/services/ghcrateengine/pricer_query_helpers.go index e2b6f91810a..400e25b0feb 100644 --- a/pkg/services/ghcrateengine/pricer_query_helpers.go +++ b/pkg/services/ghcrateengine/pricer_query_helpers.go @@ -47,6 +47,7 @@ func fetchDomOtherPrice(appCtx appcontext.AppContext, contractCode string, servi func fetchDomServiceAreaPrice(appCtx appcontext.AppContext, contractCode string, serviceCode models.ReServiceCode, serviceArea string, isPeakPeriod bool) (models.ReDomesticServiceAreaPrice, error) { var domServiceAreaPrice models.ReDomesticServiceAreaPrice + print("\n\n\n6. ", contractCode, " ", serviceCode, " ", serviceArea, "\n\n\n") err := appCtx.DB().Q(). Join("re_domestic_service_areas sa", "domestic_service_area_id = sa.id"). Join("re_services", "service_id = re_services.id"). diff --git a/pkg/services/mocks/MTOServiceItemCreator.go b/pkg/services/mocks/MTOServiceItemCreator.go index ae6e7d230e7..ab7cd5f1deb 100644 --- a/pkg/services/mocks/MTOServiceItemCreator.go +++ b/pkg/services/mocks/MTOServiceItemCreator.go @@ -8,6 +8,8 @@ import ( models "github.com/transcom/mymove/pkg/models" + unit "github.com/transcom/mymove/pkg/unit" + validate "github.com/gobuffalo/validate/v3" ) @@ -55,6 +57,34 @@ func (_m *MTOServiceItemCreator) CreateMTOServiceItem(appCtx appcontext.AppConte return r0, r1, r2 } +// FindEstimatedPrice provides a mock function with given fields: appCtx, serviceItem, mtoShipment +func (_m *MTOServiceItemCreator) FindEstimatedPrice(appCtx appcontext.AppContext, serviceItem *models.MTOServiceItem, mtoShipment models.MTOShipment) (unit.Cents, error) { + ret := _m.Called(appCtx, serviceItem, mtoShipment) + + if len(ret) == 0 { + panic("no return value specified for FindEstimatedPrice") + } + + var r0 unit.Cents + var r1 error + if rf, ok := ret.Get(0).(func(appcontext.AppContext, *models.MTOServiceItem, models.MTOShipment) (unit.Cents, error)); ok { + return rf(appCtx, serviceItem, mtoShipment) + } + if rf, ok := ret.Get(0).(func(appcontext.AppContext, *models.MTOServiceItem, models.MTOShipment) unit.Cents); ok { + r0 = rf(appCtx, serviceItem, mtoShipment) + } else { + r0 = ret.Get(0).(unit.Cents) + } + + if rf, ok := ret.Get(1).(func(appcontext.AppContext, *models.MTOServiceItem, models.MTOShipment) error); ok { + r1 = rf(appCtx, serviceItem, mtoShipment) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // NewMTOServiceItemCreator creates a new instance of MTOServiceItemCreator. 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 NewMTOServiceItemCreator(t interface { diff --git a/pkg/services/mto_service_item.go b/pkg/services/mto_service_item.go index 25926ae3fca..fd403b7875c 100644 --- a/pkg/services/mto_service_item.go +++ b/pkg/services/mto_service_item.go @@ -9,6 +9,7 @@ import ( "github.com/transcom/mymove/pkg/appcontext" "github.com/transcom/mymove/pkg/models" "github.com/transcom/mymove/pkg/route" + "github.com/transcom/mymove/pkg/unit" ) // MTOServiceItemFetcher is the exported interface for fetching a mto service item @@ -23,6 +24,7 @@ type MTOServiceItemFetcher interface { //go:generate mockery --name MTOServiceItemCreator type MTOServiceItemCreator interface { CreateMTOServiceItem(appCtx appcontext.AppContext, serviceItem *models.MTOServiceItem) (*models.MTOServiceItems, *validate.Errors, error) + FindEstimatedPrice(appCtx appcontext.AppContext, serviceItem *models.MTOServiceItem, mtoShipment models.MTOShipment) (unit.Cents, error) } // MTOServiceItemUpdater is the exported interface for updating an mto service item diff --git a/pkg/services/mto_service_item/mto_service_item_creator.go b/pkg/services/mto_service_item/mto_service_item_creator.go index 095a186da1d..460df8e19c0 100644 --- a/pkg/services/mto_service_item/mto_service_item_creator.go +++ b/pkg/services/mto_service_item/mto_service_item_creator.go @@ -39,7 +39,9 @@ type mtoServiceItemCreator struct { fuelSurchargePricer services.FuelSurchargePricer } -func (o *mtoServiceItemCreator) findEstimatedPrice(appCtx appcontext.AppContext, serviceItem *models.MTOServiceItem, mtoShipment models.MTOShipment) (unit.Cents, error) { +func (o *mtoServiceItemCreator) FindEstimatedPrice(appCtx appcontext.AppContext, serviceItem *models.MTOServiceItem, mtoShipment models.MTOShipment) (unit.Cents, error) { + print("\n\n\nStart: ", serviceItem.ReService.Code, " 1. \n") + if serviceItem.ReService.Code == models.ReServiceCodeDOP || serviceItem.ReService.Code == models.ReServiceCodeDPK || serviceItem.ReService.Code == models.ReServiceCodeDDP || @@ -55,7 +57,6 @@ func (o *mtoServiceItemCreator) findEstimatedPrice(appCtx appcontext.AppContext, requestedPickupDate := *mtoShipment.RequestedPickupDate currTime := time.Now() var distance int - primeEstimatedWeightForFSC := *mtoShipment.PrimeEstimatedWeight primeEstimatedWeight := mtoShipment.PrimeEstimatedWeight if mtoShipment.ShipmentType == models.MTOShipmentTypeHHGOutOfNTSDom { newWeight := int(primeEstimatedWeight.Float64() * 1.1) @@ -64,8 +65,10 @@ func (o *mtoServiceItemCreator) findEstimatedPrice(appCtx appcontext.AppContext, contractCode, err := FetchContractCode(appCtx, currTime) if err != nil { + print(err.Error(), " 2. \n\n\n") contractCode, err = FetchContractCode(appCtx, requestedPickupDate) if err != nil { + print(err.Error(), " 3. \n\n\n") return 0, err } } @@ -76,11 +79,13 @@ func (o *mtoServiceItemCreator) findEstimatedPrice(appCtx appcontext.AppContext, if serviceItem.ReService.Code == models.ReServiceCodeDOP { domesticServiceArea, err := fetchDomesticServiceArea(appCtx, contractCode, mtoShipment.PickupAddress.PostalCode) if err != nil { + print(err.Error(), " 4. \n\n\n") return 0, err } price, _, err = o.originPricer.Price(appCtx, contractCode, requestedPickupDate, *primeEstimatedWeight, domesticServiceArea.ServiceArea, isPPM) if err != nil { + print(err.Error(), " 5. \n\n\n") return 0, err } } @@ -178,7 +183,7 @@ func (o *mtoServiceItemCreator) findEstimatedPrice(appCtx appcontext.AppContext, } } - fscWeightBasedDistanceMultiplier, err := LookupFSCWeightBasedDistanceMultiplier(appCtx, primeEstimatedWeightForFSC) + fscWeightBasedDistanceMultiplier, err := LookupFSCWeightBasedDistanceMultiplier(appCtx, *primeEstimatedWeight) if err != nil { return 0, err } @@ -190,7 +195,7 @@ func (o *mtoServiceItemCreator) findEstimatedPrice(appCtx appcontext.AppContext, if err != nil { return 0, err } - price, _, err = o.fuelSurchargePricer.Price(appCtx, pickupDateForFSC, unit.Miles(distance), primeEstimatedWeightForFSC, fscWeightBasedDistanceMultiplierFloat, eiaFuelPrice, isPPM) + price, _, err = o.fuelSurchargePricer.Price(appCtx, pickupDateForFSC, unit.Miles(distance), *primeEstimatedWeight, fscWeightBasedDistanceMultiplierFloat, eiaFuelPrice, isPPM) if err != nil { return 0, err } @@ -609,7 +614,7 @@ func (o *mtoServiceItemCreator) CreateMTOServiceItem(appCtx appcontext.AppContex // if estimated weight for shipment provided by the prime, calculate the estimated prices for // DLH, DPK, DOP, DDP, DUPK if mtoShipment.PrimeEstimatedWeight != nil && mtoShipment.RequestedPickupDate != nil { - serviceItemEstimatedPrice, err := o.findEstimatedPrice(appCtx, serviceItem, mtoShipment) + serviceItemEstimatedPrice, err := o.FindEstimatedPrice(appCtx, serviceItem, mtoShipment) if serviceItemEstimatedPrice != 0 && err == nil { serviceItem.PricingEstimate = &serviceItemEstimatedPrice } 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 458e98f87c2..f2a8b3eec4e 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 @@ -1041,6 +1041,275 @@ func (suite *MTOServiceItemServiceSuite) TestCreateOriginSITServiceItem() { }) + suite.Run("Calcuating price estimated on creation for ReServiceCodeDOP ", func() { + + var reServiceCodeDOP models.ReService + var reServiceCodeDPK models.ReService + var reServiceCodeDDP models.ReService + var reServiceCodeDUPK models.ReService + + setupTestData := func() models.MTOShipment { + // Set up data to use for all Origin SIT Service Item tests + + move := factory.BuildAvailableToPrimeMove(suite.DB(), nil, nil) + estimatedPrimeWeight := unit.Pound(6000) + pickupDate := time.Date(2024, time.July, 31, 12, 0, 0, 0, time.UTC) + pickupAddress := factory.BuildAddress(suite.DB(), nil, []factory.Trait{factory.GetTraitAddress2}) + deliveryAddress := factory.BuildAddress(suite.DB(), nil, []factory.Trait{factory.GetTraitAddress3}) + + mtoShipment := factory.BuildMTOShipmentMinimal(suite.DB(), []factory.Customization{ + { + Model: move, + LinkOnly: true, + }, + { + Model: pickupAddress, + LinkOnly: true, + Type: &factory.Addresses.PickupAddress, + }, + { + Model: deliveryAddress, + LinkOnly: true, + Type: &factory.Addresses.DeliveryAddress, + }, + { + Model: models.MTOShipment{ + PrimeEstimatedWeight: &estimatedPrimeWeight, + RequestedPickupDate: &pickupDate, + }, + }, + }, nil) + + return mtoShipment + } + + reServiceCodeDOP = factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeDOP) + reServiceCodeDPK = factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeDPK) + reServiceCodeDDP = factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeDDP) + reServiceCodeDUPK = factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeDUPK) + + startDate := time.Now().AddDate(-1, 0, 0) + endDate := startDate.AddDate(1, 1, 1) + + contract := testdatagen.FetchOrMakeReContract(suite.DB(), testdatagen.Assertions{}) + testdatagen.FetchOrMakeReContractYear(suite.DB(), testdatagen.Assertions{ + ReContractYear: models.ReContractYear{ + Contract: contract, + ContractID: contract.ID, + StartDate: startDate, + EndDate: endDate, + Escalation: 1.0, + EscalationCompounded: 1.0, + }, + }) + + serviceArea := testdatagen.FetchOrMakeReDomesticServiceArea(suite.DB(), testdatagen.Assertions{ + ReDomesticServiceArea: models.ReDomesticServiceArea{ + ContractID: contract.ID, + ServiceArea: "945", + ServicesSchedule: 2, + CreatedAt: time.Now(), + UpdatedAt: time.Now(), + }, + }) + + testdatagen.MakeReZip3(suite.DB(), testdatagen.Assertions{ + ReZip3: models.ReZip3{ + Contract: contract, + ContractID: contract.ID, + DomesticServiceArea: serviceArea, + Zip3: "945", + }, + }) + + shipment := setupTestData() + actualPickupAddress := factory.BuildAddress(suite.DB(), nil, []factory.Trait{factory.GetTraitAddress2}) + serviceItemDOP := models.MTOServiceItem{ + MoveTaskOrder: shipment.MoveTaskOrder, + MoveTaskOrderID: shipment.MoveTaskOrderID, + MTOShipment: shipment, + MTOShipmentID: &shipment.ID, + ReService: reServiceCodeDOP, + SITEntryDate: &sitEntryDate, + SITPostalCode: &sitPostalCode, + Reason: &reason, + SITOriginHHGActualAddress: &actualPickupAddress, + Status: models.MTOServiceItemStatusSubmitted, + } + + serviceItemDPK := models.MTOServiceItem{ + MoveTaskOrder: shipment.MoveTaskOrder, + MoveTaskOrderID: shipment.MoveTaskOrderID, + MTOShipment: shipment, + MTOShipmentID: &shipment.ID, + ReService: reServiceCodeDPK, + SITEntryDate: &sitEntryDate, + SITPostalCode: &sitPostalCode, + Reason: &reason, + SITOriginHHGActualAddress: &actualPickupAddress, + Status: models.MTOServiceItemStatusSubmitted, + } + + serviceItemDDP := models.MTOServiceItem{ + MoveTaskOrder: shipment.MoveTaskOrder, + MoveTaskOrderID: shipment.MoveTaskOrderID, + MTOShipment: shipment, + MTOShipmentID: &shipment.ID, + ReService: reServiceCodeDDP, + SITEntryDate: &sitEntryDate, + SITPostalCode: &sitPostalCode, + Reason: &reason, + SITOriginHHGActualAddress: &actualPickupAddress, + Status: models.MTOServiceItemStatusSubmitted, + } + + serviceItemDUPK := models.MTOServiceItem{ + MoveTaskOrder: shipment.MoveTaskOrder, + MoveTaskOrderID: shipment.MoveTaskOrderID, + MTOShipment: shipment, + MTOShipmentID: &shipment.ID, + ReService: reServiceCodeDUPK, + SITEntryDate: &sitEntryDate, + SITPostalCode: &sitPostalCode, + Reason: &reason, + SITOriginHHGActualAddress: &actualPickupAddress, + Status: models.MTOServiceItemStatusSubmitted, + } + + builder := query.NewQueryBuilder() + moveRouter := moverouter.NewMoveRouter() + planner := &mocks.Planner{} + planner.On("ZipTransitDistance", + mock.AnythingOfType("*appcontext.appContext"), + mock.Anything, + mock.Anything, + ).Return(400, nil) + creator := NewMTOServiceItemCreator(planner, builder, moveRouter, ghcrateengine.NewDomesticUnpackPricer(), ghcrateengine.NewDomesticPackPricer(), ghcrateengine.NewDomesticLinehaulPricer(), ghcrateengine.NewDomesticShorthaulPricer(), ghcrateengine.NewDomesticOriginPricer(), ghcrateengine.NewDomesticDestinationPricer(), ghcrateengine.NewFuelSurchargePricer()) + + dopEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDOP, shipment) + suite.Equal(unit.Cents(47760), dopEstimatedPriceInCents) + + dpkEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDPK, shipment) + suite.Equal(unit.Cents(47760), dpkEstimatedPriceInCents) + + ddpEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDDP, shipment) + suite.Equal(unit.Cents(47760), ddpEstimatedPriceInCents) + + dupkEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDUPK, shipment) + suite.Equal(unit.Cents(47760), dupkEstimatedPriceInCents) + }) + + suite.Run("Calcuating price estimated on creation for NTS shipment ", func() { + + var reServiceCodeDOP models.ReService + + setupTestData := func() models.MTOShipment { + // Set up data to use for all Origin SIT Service Item tests + + move := factory.BuildAvailableToPrimeMove(suite.DB(), nil, nil) + estimatedPrimeWeight := unit.Pound(6000) + pickupDate := time.Date(2024, time.July, 31, 12, 0, 0, 0, time.UTC) + pickupAddress := factory.BuildAddress(suite.DB(), nil, []factory.Trait{factory.GetTraitAddress2}) + deliveryAddress := factory.BuildAddress(suite.DB(), nil, []factory.Trait{factory.GetTraitAddress3}) + + customMTOShipmentTypeHHGOutOfNTSDom := factory.BuildMTOShipmentMinimal(suite.DB(), []factory.Customization{ + { + Model: move, + LinkOnly: true, + }, + { + Model: pickupAddress, + LinkOnly: true, + Type: &factory.Addresses.PickupAddress, + }, + { + Model: deliveryAddress, + LinkOnly: true, + Type: &factory.Addresses.DeliveryAddress, + }, + { + Model: models.MTOShipment{ + PrimeEstimatedWeight: &estimatedPrimeWeight, + RequestedPickupDate: &pickupDate, + ShipmentType: models.MTOShipmentTypeHHGOutOfNTSDom, + }, + }, + }, nil) + + reServiceCodeDOP = factory.BuildReService(suite.DB(), []factory.Customization{ + { + Model: models.ReService{ + Code: "DOP", + }, + }, + }, nil) + + startDate := time.Now().AddDate(-1, 0, 0) + endDate := startDate.AddDate(1, 1, 1) + contract := testdatagen.FetchOrMakeReContract(suite.DB(), testdatagen.Assertions{}) + testdatagen.FetchOrMakeReContractYear(suite.DB(), testdatagen.Assertions{ + ReContractYear: models.ReContractYear{ + Contract: contract, + ContractID: contract.ID, + StartDate: startDate, + EndDate: endDate, + Escalation: 1.0, + EscalationCompounded: 1.0, + }, + }) + testdatagen.MakeReZip3(suite.DB(), testdatagen.Assertions{ + ReZip3: models.ReZip3{ + Contract: contract, + ContractID: contract.ID, + DomesticServiceArea: testdatagen.FetchOrMakeReDomesticServiceArea(suite.DB(), testdatagen.Assertions{ + ReDomesticServiceArea: models.ReDomesticServiceArea{ + ContractID: contract.ID, + ServiceArea: "674", + ServicesSchedule: 2, + CreatedAt: time.Now(), + UpdatedAt: time.Now(), + }, + }), + Zip3: "674", + }, + }) + testdatagen.MakeReDomesticServiceAreaPrice(suite.DB(), testdatagen.Assertions{ReService: models.ReService{Code: "DOP"}}) + + return customMTOShipmentTypeHHGOutOfNTSDom + } + + shipment := setupTestData() + actualPickupAddress := factory.BuildAddress(suite.DB(), nil, []factory.Trait{factory.GetTraitAddress2}) + actualPickupAddress.PostalCode = "67449" + + serviceItemDOP := models.MTOServiceItem{ + MoveTaskOrder: shipment.MoveTaskOrder, + MoveTaskOrderID: shipment.MoveTaskOrderID, + MTOShipment: shipment, + MTOShipmentID: &shipment.ID, + ReService: reServiceCodeDOP, + SITEntryDate: &sitEntryDate, + SITPostalCode: &sitPostalCode, + Reason: &reason, + SITOriginHHGActualAddress: &actualPickupAddress, + Status: models.MTOServiceItemStatusSubmitted, + } + + builder := query.NewQueryBuilder() + moveRouter := moverouter.NewMoveRouter() + planner := &mocks.Planner{} + planner.On("ZipTransitDistance", + mock.AnythingOfType("*appcontext.appContext"), + mock.Anything, + mock.Anything, + ).Return(400, nil) + creator := NewMTOServiceItemCreator(planner, builder, moveRouter, ghcrateengine.NewDomesticUnpackPricer(), ghcrateengine.NewDomesticPackPricer(), ghcrateengine.NewDomesticLinehaulPricer(), ghcrateengine.NewDomesticShorthaulPricer(), ghcrateengine.NewDomesticOriginPricer(), ghcrateengine.NewDomesticDestinationPricer(), ghcrateengine.NewFuelSurchargePricer()) + + estimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDOP, shipment) + estimatedPriceForMTOShipmentTypeHHGOutOfNTSDom := estimatedPriceInCents.Float64() * 1.1 + suite.Equal(estimatedPriceInCents, unit.Cents(estimatedPriceForMTOShipmentTypeHHGOutOfNTSDom)) + }) + suite.Run("Create DOFSIT service item and auto-create DOASIT, DOPSIT, DOSFSC", func() { // TESTCASE SCENARIO // Under test: CreateMTOServiceItem function From 6783ebc522f7edd6d96e28e1662936674bf8a7b4 Mon Sep 17 00:00:00 2001 From: loganwc Date: Wed, 13 Nov 2024 18:26:55 +0000 Subject: [PATCH 05/21] tests now workgit add . --- pkg/db/sequence/random_sequencer_test.go | 70 +- pkg/db/sequence/sequencer_test.go | 42 +- .../ghcrateengine/pricer_query_helpers.go | 1 - .../mto_service_item_creator.go | 6 - .../mto_service_item_creator_test.go | 1202 +++++++++++++---- 5 files changed, 989 insertions(+), 332 deletions(-) diff --git a/pkg/db/sequence/random_sequencer_test.go b/pkg/db/sequence/random_sequencer_test.go index b5c31481c0e..053060ce54e 100644 --- a/pkg/db/sequence/random_sequencer_test.go +++ b/pkg/db/sequence/random_sequencer_test.go @@ -1,37 +1,37 @@ package sequence -// const testMin int64 = 10 -// const testMax int64 = 99 - -// func (suite *SequenceSuite) TestRandomNextVal() { -// sequencer, err := NewRandomSequencer(testMin, testMax) -// suite.FatalNoError(err) - -// // Try 100 random numbers and make sure they're all between min and max, inclusive. -// for i := 0; i < 100; i++ { -// nextVal, err := sequencer.NextVal(suite.AppContextForTest()) -// suite.NoError(err, "Error getting next value of sequence") - -// suite.True(nextVal >= testMin && nextVal <= testMax, -// "NextVal returned %d, but range was %d to %d inclusive", nextVal, testMin, testMax) -// } -// } - -// func (suite *SequenceSuite) TestRandomSetVal() { -// sequencer, err := NewRandomSequencer(testMin, testMax) -// suite.FatalNoError(err) - -// // This should be a no-op; just make sure it doesn't throw any errors. -// err = sequencer.SetVal(suite.AppContextForTest(), 30) -// suite.NoError(err, "Error setting value of sequence") -// } - -// func (suite *SequenceSuite) TestRandomConstructorErrors() { -// sequencer, err := NewRandomSequencer(-3, 10) -// suite.Nil(sequencer) -// suite.Error(err) - -// sequencer, err = NewRandomSequencer(20, 10) -// suite.Nil(sequencer) -// suite.Error(err) -// } +const testMin int64 = 10 +const testMax int64 = 99 + +func (suite *SequenceSuite) TestRandomNextVal() { + sequencer, err := NewRandomSequencer(testMin, testMax) + suite.FatalNoError(err) + + // Try 100 random numbers and make sure they're all between min and max, inclusive. + for i := 0; i < 100; i++ { + nextVal, err := sequencer.NextVal(suite.AppContextForTest()) + suite.NoError(err, "Error getting next value of sequence") + + suite.True(nextVal >= testMin && nextVal <= testMax, + "NextVal returned %d, but range was %d to %d inclusive", nextVal, testMin, testMax) + } +} + +func (suite *SequenceSuite) TestRandomSetVal() { + sequencer, err := NewRandomSequencer(testMin, testMax) + suite.FatalNoError(err) + + // This should be a no-op; just make sure it doesn't throw any errors. + err = sequencer.SetVal(suite.AppContextForTest(), 30) + suite.NoError(err, "Error setting value of sequence") +} + +func (suite *SequenceSuite) TestRandomConstructorErrors() { + sequencer, err := NewRandomSequencer(-3, 10) + suite.Nil(sequencer) + suite.Error(err) + + sequencer, err = NewRandomSequencer(20, 10) + suite.Nil(sequencer) + suite.Error(err) +} diff --git a/pkg/db/sequence/sequencer_test.go b/pkg/db/sequence/sequencer_test.go index c3976d5ba0e..5dd06751e01 100644 --- a/pkg/db/sequence/sequencer_test.go +++ b/pkg/db/sequence/sequencer_test.go @@ -1,29 +1,29 @@ package sequence -// import ( -// "testing" +import ( + "testing" -// "github.com/stretchr/testify/suite" + "github.com/stretchr/testify/suite" -// "github.com/transcom/mymove/pkg/testingsuite" -// ) + "github.com/transcom/mymove/pkg/testingsuite" +) -// type SequenceSuite struct { -// *testingsuite.PopTestSuite -// } +type SequenceSuite struct { + *testingsuite.PopTestSuite +} -// func (suite *SequenceSuite) SetupTest() { -// err := suite.DB().RawQuery("CREATE SEQUENCE IF NOT EXISTS test_sequence;").Exec() -// suite.NoError(err, "Error creating test sequence") -// err = suite.DB().RawQuery("SELECT setval($1, 1);", testSequence).Exec() -// suite.NoError(err, "Error resetting sequence") -// } +func (suite *SequenceSuite) SetupTest() { + err := suite.DB().RawQuery("CREATE SEQUENCE IF NOT EXISTS test_sequence;").Exec() + suite.NoError(err, "Error creating test sequence") + err = suite.DB().RawQuery("SELECT setval($1, 1);", testSequence).Exec() + suite.NoError(err, "Error resetting sequence") +} -// func TestSequenceSuite(t *testing.T) { +func TestSequenceSuite(t *testing.T) { -// hs := &SequenceSuite{ -// PopTestSuite: testingsuite.NewPopTestSuite(testingsuite.CurrentPackage(), testingsuite.WithPerTestTransaction()), -// } -// suite.Run(t, hs) -// hs.PopTestSuite.TearDown() -// } + hs := &SequenceSuite{ + PopTestSuite: testingsuite.NewPopTestSuite(testingsuite.CurrentPackage(), testingsuite.WithPerTestTransaction()), + } + suite.Run(t, hs) + hs.PopTestSuite.TearDown() +} diff --git a/pkg/services/ghcrateengine/pricer_query_helpers.go b/pkg/services/ghcrateengine/pricer_query_helpers.go index 400e25b0feb..e2b6f91810a 100644 --- a/pkg/services/ghcrateengine/pricer_query_helpers.go +++ b/pkg/services/ghcrateengine/pricer_query_helpers.go @@ -47,7 +47,6 @@ func fetchDomOtherPrice(appCtx appcontext.AppContext, contractCode string, servi func fetchDomServiceAreaPrice(appCtx appcontext.AppContext, contractCode string, serviceCode models.ReServiceCode, serviceArea string, isPeakPeriod bool) (models.ReDomesticServiceAreaPrice, error) { var domServiceAreaPrice models.ReDomesticServiceAreaPrice - print("\n\n\n6. ", contractCode, " ", serviceCode, " ", serviceArea, "\n\n\n") err := appCtx.DB().Q(). Join("re_domestic_service_areas sa", "domestic_service_area_id = sa.id"). Join("re_services", "service_id = re_services.id"). diff --git a/pkg/services/mto_service_item/mto_service_item_creator.go b/pkg/services/mto_service_item/mto_service_item_creator.go index 460df8e19c0..40f78600fec 100644 --- a/pkg/services/mto_service_item/mto_service_item_creator.go +++ b/pkg/services/mto_service_item/mto_service_item_creator.go @@ -40,8 +40,6 @@ type mtoServiceItemCreator struct { } func (o *mtoServiceItemCreator) FindEstimatedPrice(appCtx appcontext.AppContext, serviceItem *models.MTOServiceItem, mtoShipment models.MTOShipment) (unit.Cents, error) { - print("\n\n\nStart: ", serviceItem.ReService.Code, " 1. \n") - if serviceItem.ReService.Code == models.ReServiceCodeDOP || serviceItem.ReService.Code == models.ReServiceCodeDPK || serviceItem.ReService.Code == models.ReServiceCodeDDP || @@ -65,10 +63,8 @@ func (o *mtoServiceItemCreator) FindEstimatedPrice(appCtx appcontext.AppContext, contractCode, err := FetchContractCode(appCtx, currTime) if err != nil { - print(err.Error(), " 2. \n\n\n") contractCode, err = FetchContractCode(appCtx, requestedPickupDate) if err != nil { - print(err.Error(), " 3. \n\n\n") return 0, err } } @@ -79,13 +75,11 @@ func (o *mtoServiceItemCreator) FindEstimatedPrice(appCtx appcontext.AppContext, if serviceItem.ReService.Code == models.ReServiceCodeDOP { domesticServiceArea, err := fetchDomesticServiceArea(appCtx, contractCode, mtoShipment.PickupAddress.PostalCode) if err != nil { - print(err.Error(), " 4. \n\n\n") return 0, err } price, _, err = o.originPricer.Price(appCtx, contractCode, requestedPickupDate, *primeEstimatedWeight, domesticServiceArea.ServiceArea, isPPM) if err != nil { - print(err.Error(), " 5. \n\n\n") return 0, err } } 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 f2a8b3eec4e..e6084a7f8d1 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 @@ -1041,275 +1041,6 @@ func (suite *MTOServiceItemServiceSuite) TestCreateOriginSITServiceItem() { }) - suite.Run("Calcuating price estimated on creation for ReServiceCodeDOP ", func() { - - var reServiceCodeDOP models.ReService - var reServiceCodeDPK models.ReService - var reServiceCodeDDP models.ReService - var reServiceCodeDUPK models.ReService - - setupTestData := func() models.MTOShipment { - // Set up data to use for all Origin SIT Service Item tests - - move := factory.BuildAvailableToPrimeMove(suite.DB(), nil, nil) - estimatedPrimeWeight := unit.Pound(6000) - pickupDate := time.Date(2024, time.July, 31, 12, 0, 0, 0, time.UTC) - pickupAddress := factory.BuildAddress(suite.DB(), nil, []factory.Trait{factory.GetTraitAddress2}) - deliveryAddress := factory.BuildAddress(suite.DB(), nil, []factory.Trait{factory.GetTraitAddress3}) - - mtoShipment := factory.BuildMTOShipmentMinimal(suite.DB(), []factory.Customization{ - { - Model: move, - LinkOnly: true, - }, - { - Model: pickupAddress, - LinkOnly: true, - Type: &factory.Addresses.PickupAddress, - }, - { - Model: deliveryAddress, - LinkOnly: true, - Type: &factory.Addresses.DeliveryAddress, - }, - { - Model: models.MTOShipment{ - PrimeEstimatedWeight: &estimatedPrimeWeight, - RequestedPickupDate: &pickupDate, - }, - }, - }, nil) - - return mtoShipment - } - - reServiceCodeDOP = factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeDOP) - reServiceCodeDPK = factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeDPK) - reServiceCodeDDP = factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeDDP) - reServiceCodeDUPK = factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeDUPK) - - startDate := time.Now().AddDate(-1, 0, 0) - endDate := startDate.AddDate(1, 1, 1) - - contract := testdatagen.FetchOrMakeReContract(suite.DB(), testdatagen.Assertions{}) - testdatagen.FetchOrMakeReContractYear(suite.DB(), testdatagen.Assertions{ - ReContractYear: models.ReContractYear{ - Contract: contract, - ContractID: contract.ID, - StartDate: startDate, - EndDate: endDate, - Escalation: 1.0, - EscalationCompounded: 1.0, - }, - }) - - serviceArea := testdatagen.FetchOrMakeReDomesticServiceArea(suite.DB(), testdatagen.Assertions{ - ReDomesticServiceArea: models.ReDomesticServiceArea{ - ContractID: contract.ID, - ServiceArea: "945", - ServicesSchedule: 2, - CreatedAt: time.Now(), - UpdatedAt: time.Now(), - }, - }) - - testdatagen.MakeReZip3(suite.DB(), testdatagen.Assertions{ - ReZip3: models.ReZip3{ - Contract: contract, - ContractID: contract.ID, - DomesticServiceArea: serviceArea, - Zip3: "945", - }, - }) - - shipment := setupTestData() - actualPickupAddress := factory.BuildAddress(suite.DB(), nil, []factory.Trait{factory.GetTraitAddress2}) - serviceItemDOP := models.MTOServiceItem{ - MoveTaskOrder: shipment.MoveTaskOrder, - MoveTaskOrderID: shipment.MoveTaskOrderID, - MTOShipment: shipment, - MTOShipmentID: &shipment.ID, - ReService: reServiceCodeDOP, - SITEntryDate: &sitEntryDate, - SITPostalCode: &sitPostalCode, - Reason: &reason, - SITOriginHHGActualAddress: &actualPickupAddress, - Status: models.MTOServiceItemStatusSubmitted, - } - - serviceItemDPK := models.MTOServiceItem{ - MoveTaskOrder: shipment.MoveTaskOrder, - MoveTaskOrderID: shipment.MoveTaskOrderID, - MTOShipment: shipment, - MTOShipmentID: &shipment.ID, - ReService: reServiceCodeDPK, - SITEntryDate: &sitEntryDate, - SITPostalCode: &sitPostalCode, - Reason: &reason, - SITOriginHHGActualAddress: &actualPickupAddress, - Status: models.MTOServiceItemStatusSubmitted, - } - - serviceItemDDP := models.MTOServiceItem{ - MoveTaskOrder: shipment.MoveTaskOrder, - MoveTaskOrderID: shipment.MoveTaskOrderID, - MTOShipment: shipment, - MTOShipmentID: &shipment.ID, - ReService: reServiceCodeDDP, - SITEntryDate: &sitEntryDate, - SITPostalCode: &sitPostalCode, - Reason: &reason, - SITOriginHHGActualAddress: &actualPickupAddress, - Status: models.MTOServiceItemStatusSubmitted, - } - - serviceItemDUPK := models.MTOServiceItem{ - MoveTaskOrder: shipment.MoveTaskOrder, - MoveTaskOrderID: shipment.MoveTaskOrderID, - MTOShipment: shipment, - MTOShipmentID: &shipment.ID, - ReService: reServiceCodeDUPK, - SITEntryDate: &sitEntryDate, - SITPostalCode: &sitPostalCode, - Reason: &reason, - SITOriginHHGActualAddress: &actualPickupAddress, - Status: models.MTOServiceItemStatusSubmitted, - } - - builder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() - planner := &mocks.Planner{} - planner.On("ZipTransitDistance", - mock.AnythingOfType("*appcontext.appContext"), - mock.Anything, - mock.Anything, - ).Return(400, nil) - creator := NewMTOServiceItemCreator(planner, builder, moveRouter, ghcrateengine.NewDomesticUnpackPricer(), ghcrateengine.NewDomesticPackPricer(), ghcrateengine.NewDomesticLinehaulPricer(), ghcrateengine.NewDomesticShorthaulPricer(), ghcrateengine.NewDomesticOriginPricer(), ghcrateengine.NewDomesticDestinationPricer(), ghcrateengine.NewFuelSurchargePricer()) - - dopEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDOP, shipment) - suite.Equal(unit.Cents(47760), dopEstimatedPriceInCents) - - dpkEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDPK, shipment) - suite.Equal(unit.Cents(47760), dpkEstimatedPriceInCents) - - ddpEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDDP, shipment) - suite.Equal(unit.Cents(47760), ddpEstimatedPriceInCents) - - dupkEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDUPK, shipment) - suite.Equal(unit.Cents(47760), dupkEstimatedPriceInCents) - }) - - suite.Run("Calcuating price estimated on creation for NTS shipment ", func() { - - var reServiceCodeDOP models.ReService - - setupTestData := func() models.MTOShipment { - // Set up data to use for all Origin SIT Service Item tests - - move := factory.BuildAvailableToPrimeMove(suite.DB(), nil, nil) - estimatedPrimeWeight := unit.Pound(6000) - pickupDate := time.Date(2024, time.July, 31, 12, 0, 0, 0, time.UTC) - pickupAddress := factory.BuildAddress(suite.DB(), nil, []factory.Trait{factory.GetTraitAddress2}) - deliveryAddress := factory.BuildAddress(suite.DB(), nil, []factory.Trait{factory.GetTraitAddress3}) - - customMTOShipmentTypeHHGOutOfNTSDom := factory.BuildMTOShipmentMinimal(suite.DB(), []factory.Customization{ - { - Model: move, - LinkOnly: true, - }, - { - Model: pickupAddress, - LinkOnly: true, - Type: &factory.Addresses.PickupAddress, - }, - { - Model: deliveryAddress, - LinkOnly: true, - Type: &factory.Addresses.DeliveryAddress, - }, - { - Model: models.MTOShipment{ - PrimeEstimatedWeight: &estimatedPrimeWeight, - RequestedPickupDate: &pickupDate, - ShipmentType: models.MTOShipmentTypeHHGOutOfNTSDom, - }, - }, - }, nil) - - reServiceCodeDOP = factory.BuildReService(suite.DB(), []factory.Customization{ - { - Model: models.ReService{ - Code: "DOP", - }, - }, - }, nil) - - startDate := time.Now().AddDate(-1, 0, 0) - endDate := startDate.AddDate(1, 1, 1) - contract := testdatagen.FetchOrMakeReContract(suite.DB(), testdatagen.Assertions{}) - testdatagen.FetchOrMakeReContractYear(suite.DB(), testdatagen.Assertions{ - ReContractYear: models.ReContractYear{ - Contract: contract, - ContractID: contract.ID, - StartDate: startDate, - EndDate: endDate, - Escalation: 1.0, - EscalationCompounded: 1.0, - }, - }) - testdatagen.MakeReZip3(suite.DB(), testdatagen.Assertions{ - ReZip3: models.ReZip3{ - Contract: contract, - ContractID: contract.ID, - DomesticServiceArea: testdatagen.FetchOrMakeReDomesticServiceArea(suite.DB(), testdatagen.Assertions{ - ReDomesticServiceArea: models.ReDomesticServiceArea{ - ContractID: contract.ID, - ServiceArea: "674", - ServicesSchedule: 2, - CreatedAt: time.Now(), - UpdatedAt: time.Now(), - }, - }), - Zip3: "674", - }, - }) - testdatagen.MakeReDomesticServiceAreaPrice(suite.DB(), testdatagen.Assertions{ReService: models.ReService{Code: "DOP"}}) - - return customMTOShipmentTypeHHGOutOfNTSDom - } - - shipment := setupTestData() - actualPickupAddress := factory.BuildAddress(suite.DB(), nil, []factory.Trait{factory.GetTraitAddress2}) - actualPickupAddress.PostalCode = "67449" - - serviceItemDOP := models.MTOServiceItem{ - MoveTaskOrder: shipment.MoveTaskOrder, - MoveTaskOrderID: shipment.MoveTaskOrderID, - MTOShipment: shipment, - MTOShipmentID: &shipment.ID, - ReService: reServiceCodeDOP, - SITEntryDate: &sitEntryDate, - SITPostalCode: &sitPostalCode, - Reason: &reason, - SITOriginHHGActualAddress: &actualPickupAddress, - Status: models.MTOServiceItemStatusSubmitted, - } - - builder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() - planner := &mocks.Planner{} - planner.On("ZipTransitDistance", - mock.AnythingOfType("*appcontext.appContext"), - mock.Anything, - mock.Anything, - ).Return(400, nil) - creator := NewMTOServiceItemCreator(planner, builder, moveRouter, ghcrateengine.NewDomesticUnpackPricer(), ghcrateengine.NewDomesticPackPricer(), ghcrateengine.NewDomesticLinehaulPricer(), ghcrateengine.NewDomesticShorthaulPricer(), ghcrateengine.NewDomesticOriginPricer(), ghcrateengine.NewDomesticDestinationPricer(), ghcrateengine.NewFuelSurchargePricer()) - - estimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDOP, shipment) - estimatedPriceForMTOShipmentTypeHHGOutOfNTSDom := estimatedPriceInCents.Float64() * 1.1 - suite.Equal(estimatedPriceInCents, unit.Cents(estimatedPriceForMTOShipmentTypeHHGOutOfNTSDom)) - }) - suite.Run("Create DOFSIT service item and auto-create DOASIT, DOPSIT, DOSFSC", func() { // TESTCASE SCENARIO // Under test: CreateMTOServiceItem function @@ -2090,3 +1821,936 @@ func (suite *MTOServiceItemServiceSuite) TestCreateDestSITServiceItem() { suite.Contains(invalidInputError.ValidationErrors.Keys(), "reServiceCode") }) } + +func (suite *MTOServiceItemServiceSuite) TestPriceEstimator() { + suite.Run("Calcuating price estimated on creation for HHG ", func() { + setupTestData := func() models.MTOShipment { + // Set up data to use for all Origin SIT Service Item tests + + move := factory.BuildAvailableToPrimeMove(suite.DB(), nil, nil) + estimatedPrimeWeight := unit.Pound(6000) + pickupDate := time.Date(2024, time.July, 31, 12, 0, 0, 0, time.UTC) + pickupAddress := factory.BuildAddress(suite.DB(), nil, []factory.Trait{factory.GetTraitAddress2}) + deliveryAddress := factory.BuildAddress(suite.DB(), nil, []factory.Trait{factory.GetTraitAddress3}) + + mtoShipment := factory.BuildMTOShipmentMinimal(suite.DB(), []factory.Customization{ + { + Model: move, + LinkOnly: true, + }, + { + Model: pickupAddress, + LinkOnly: true, + Type: &factory.Addresses.PickupAddress, + }, + { + Model: deliveryAddress, + LinkOnly: true, + Type: &factory.Addresses.DeliveryAddress, + }, + { + Model: models.MTOShipment{ + PrimeEstimatedWeight: &estimatedPrimeWeight, + RequestedPickupDate: &pickupDate, + }, + }, + }, nil) + + return mtoShipment + } + + reServiceCodeDOP := factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeDOP) + reServiceCodeDPK := factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeDPK) + reServiceCodeDDP := factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeDDP) + reServiceCodeDUPK := factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeDUPK) + reServiceCodeDLH := factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeDLH) + reServiceCodeDSH := factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeDSH) + reServiceCodeFSC := factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeFSC) + + startDate := time.Now().AddDate(-1, 0, 0) + endDate := startDate.AddDate(1, 1, 1) + sitEntryDate := time.Date(2020, time.October, 24, 0, 0, 0, 0, time.UTC) + sitPostalCode := "99999" + reason := "lorem ipsum" + + contract := testdatagen.FetchOrMakeReContract(suite.DB(), testdatagen.Assertions{}) + contractYear := testdatagen.MakeReContractYear(suite.DB(), + testdatagen.Assertions{ + ReContractYear: models.ReContractYear{ + Name: "Test Contract Year", + EscalationCompounded: 1.125, + StartDate: startDate, + EndDate: endDate, + }, + }) + + serviceArea := testdatagen.MakeReDomesticServiceArea(suite.DB(), + testdatagen.Assertions{ + ReDomesticServiceArea: models.ReDomesticServiceArea{ + Contract: contractYear.Contract, + ServiceArea: "945", + ServicesSchedule: 1, + }, + }) + + serviceAreaDest := testdatagen.MakeReDomesticServiceArea(suite.DB(), + testdatagen.Assertions{ + ReDomesticServiceArea: models.ReDomesticServiceArea{ + Contract: contractYear.Contract, + ServiceArea: "503", + ServicesSchedule: 1, + }, + }) + + serviceAreaPriceDOP := models.ReDomesticServiceAreaPrice{ + ContractID: contractYear.Contract.ID, + ServiceID: reServiceCodeDOP.ID, + IsPeakPeriod: true, + DomesticServiceAreaID: serviceArea.ID, + PriceCents: unit.Cents(1234), + } + + serviceAreaPriceDPK := models.ReDomesticOtherPrice{ + ContractID: contractYear.Contract.ID, + ServiceID: reServiceCodeDPK.ID, + IsPeakPeriod: true, + Schedule: 1, + PriceCents: unit.Cents(121), + } + + serviceAreaPriceDDP := models.ReDomesticServiceAreaPrice{ + ContractID: contractYear.Contract.ID, + ServiceID: reServiceCodeDDP.ID, + IsPeakPeriod: true, + DomesticServiceAreaID: serviceAreaDest.ID, + PriceCents: unit.Cents(482), + } + + serviceAreaPriceDUPK := models.ReDomesticOtherPrice{ + ContractID: contractYear.Contract.ID, + ServiceID: reServiceCodeDUPK.ID, + IsPeakPeriod: true, + Schedule: 1, + PriceCents: unit.Cents(945), + } + + serviceAreaPriceDLH := models.ReDomesticLinehaulPrice{ + ContractID: contractYear.Contract.ID, + WeightLower: 500, + WeightUpper: 10000, + MilesLower: 1, + MilesUpper: 10000, + IsPeakPeriod: true, + DomesticServiceAreaID: serviceArea.ID, + PriceMillicents: unit.Millicents(482), + } + + serviceAreaPriceDSH := models.ReDomesticServiceAreaPrice{ + ContractID: contractYear.Contract.ID, + ServiceID: reServiceCodeDSH.ID, + IsPeakPeriod: true, + DomesticServiceAreaID: serviceArea.ID, + PriceCents: unit.Cents(999), + } + + testdatagen.MakeGHCDieselFuelPrice(suite.DB(), testdatagen.Assertions{ + GHCDieselFuelPrice: models.GHCDieselFuelPrice{ + FuelPriceInMillicents: unit.Millicents(281400), + PublicationDate: time.Date(2020, time.March, 9, 0, 0, 0, 0, time.UTC), + EffectiveDate: time.Date(2020, time.March, 10, 0, 0, 0, 0, time.UTC), + EndDate: time.Date(2025, time.March, 17, 0, 0, 0, 0, time.UTC), + }, + }) + + suite.MustSave(&serviceAreaPriceDOP) + suite.MustSave(&serviceAreaPriceDPK) + suite.MustSave(&serviceAreaPriceDDP) + suite.MustSave(&serviceAreaPriceDUPK) + suite.MustSave(&serviceAreaPriceDLH) + suite.MustSave(&serviceAreaPriceDSH) + + testdatagen.MakeReZip3(suite.DB(), testdatagen.Assertions{ + ReZip3: models.ReZip3{ + Contract: contract, + ContractID: contract.ID, + DomesticServiceArea: serviceArea, + Zip3: "945", + }, + }) + + testdatagen.MakeReZip3(suite.DB(), testdatagen.Assertions{ + ReZip3: models.ReZip3{ + Contract: contract, + ContractID: contract.ID, + DomesticServiceArea: serviceAreaDest, + Zip3: "503", + }, + }) + + shipment := setupTestData() + actualPickupAddress := factory.BuildAddress(suite.DB(), nil, []factory.Trait{factory.GetTraitAddress2}) + serviceItemDOP := models.MTOServiceItem{ + MoveTaskOrder: shipment.MoveTaskOrder, + MoveTaskOrderID: shipment.MoveTaskOrderID, + MTOShipment: shipment, + MTOShipmentID: &shipment.ID, + ReService: reServiceCodeDOP, + SITEntryDate: &sitEntryDate, + SITPostalCode: &sitPostalCode, + Reason: &reason, + SITOriginHHGActualAddress: &actualPickupAddress, + Status: models.MTOServiceItemStatusSubmitted, + } + + serviceItemDPK := models.MTOServiceItem{ + MoveTaskOrder: shipment.MoveTaskOrder, + MoveTaskOrderID: shipment.MoveTaskOrderID, + MTOShipment: shipment, + MTOShipmentID: &shipment.ID, + ReService: reServiceCodeDPK, + SITEntryDate: &sitEntryDate, + SITPostalCode: &sitPostalCode, + Reason: &reason, + SITOriginHHGActualAddress: &actualPickupAddress, + Status: models.MTOServiceItemStatusSubmitted, + } + + serviceItemDDP := models.MTOServiceItem{ + MoveTaskOrder: shipment.MoveTaskOrder, + MoveTaskOrderID: shipment.MoveTaskOrderID, + MTOShipment: shipment, + MTOShipmentID: &shipment.ID, + ReService: reServiceCodeDDP, + SITEntryDate: &sitEntryDate, + SITPostalCode: &sitPostalCode, + Reason: &reason, + SITOriginHHGActualAddress: &actualPickupAddress, + Status: models.MTOServiceItemStatusSubmitted, + } + + serviceItemDUPK := models.MTOServiceItem{ + MoveTaskOrder: shipment.MoveTaskOrder, + MoveTaskOrderID: shipment.MoveTaskOrderID, + MTOShipment: shipment, + MTOShipmentID: &shipment.ID, + ReService: reServiceCodeDUPK, + SITEntryDate: &sitEntryDate, + SITPostalCode: &sitPostalCode, + Reason: &reason, + SITOriginHHGActualAddress: &actualPickupAddress, + Status: models.MTOServiceItemStatusSubmitted, + } + + serviceItemDLH := models.MTOServiceItem{ + MoveTaskOrder: shipment.MoveTaskOrder, + MoveTaskOrderID: shipment.MoveTaskOrderID, + MTOShipment: shipment, + MTOShipmentID: &shipment.ID, + ReService: reServiceCodeDLH, + SITEntryDate: &sitEntryDate, + SITPostalCode: &sitPostalCode, + Reason: &reason, + SITOriginHHGActualAddress: &actualPickupAddress, + Status: models.MTOServiceItemStatusSubmitted, + } + + serviceItemDSH := models.MTOServiceItem{ + MoveTaskOrder: shipment.MoveTaskOrder, + MoveTaskOrderID: shipment.MoveTaskOrderID, + MTOShipment: shipment, + MTOShipmentID: &shipment.ID, + ReService: reServiceCodeDSH, + SITEntryDate: &sitEntryDate, + SITPostalCode: &sitPostalCode, + Reason: &reason, + SITOriginHHGActualAddress: &actualPickupAddress, + Status: models.MTOServiceItemStatusSubmitted, + } + + serviceItemFSC := models.MTOServiceItem{ + MoveTaskOrder: shipment.MoveTaskOrder, + MoveTaskOrderID: shipment.MoveTaskOrderID, + MTOShipment: shipment, + MTOShipmentID: &shipment.ID, + ReService: reServiceCodeFSC, + SITEntryDate: &sitEntryDate, + SITPostalCode: &sitPostalCode, + Reason: &reason, + SITOriginHHGActualAddress: &actualPickupAddress, + Status: models.MTOServiceItemStatusSubmitted, + } + + builder := query.NewQueryBuilder() + moveRouter := moverouter.NewMoveRouter() + planner := &mocks.Planner{} + planner.On("ZipTransitDistance", + mock.AnythingOfType("*appcontext.appContext"), + mock.Anything, + mock.Anything, + ).Return(400, nil) + creator := NewMTOServiceItemCreator(planner, builder, moveRouter, ghcrateengine.NewDomesticUnpackPricer(), ghcrateengine.NewDomesticPackPricer(), ghcrateengine.NewDomesticLinehaulPricer(), ghcrateengine.NewDomesticShorthaulPricer(), ghcrateengine.NewDomesticOriginPricer(), ghcrateengine.NewDomesticDestinationPricer(), ghcrateengine.NewFuelSurchargePricer()) + + dopEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDOP, shipment) + suite.Equal(unit.Cents(83280), dopEstimatedPriceInCents) + + dpkEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDPK, shipment) + suite.Equal(unit.Cents(8160), dpkEstimatedPriceInCents) + + ddpEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDDP, shipment) + suite.Equal(unit.Cents(32520), ddpEstimatedPriceInCents) + + dupkEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDUPK, shipment) + suite.Equal(unit.Cents(63780), dupkEstimatedPriceInCents) + + dlhEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDLH, shipment) + suite.Equal(unit.Cents(14400), dlhEstimatedPriceInCents) + + dshEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDSH, shipment) + suite.Equal(unit.Cents(26976000), dshEstimatedPriceInCents) + + fscEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemFSC, shipment) + suite.Equal(unit.Cents(786), fscEstimatedPriceInCents) + }) + + suite.Run("Calcuating price estimated on creation for NTS shipment ", func() { + setupTestData := func() models.MTOShipment { + // Set up data to use for all Origin SIT Service Item tests + + move := factory.BuildAvailableToPrimeMove(suite.DB(), nil, nil) + estimatedPrimeWeight := unit.Pound(6000) + pickupDate := time.Date(2024, time.July, 31, 12, 0, 0, 0, time.UTC) + pickupAddress := factory.BuildAddress(suite.DB(), nil, []factory.Trait{factory.GetTraitAddress2}) + deliveryAddress := factory.BuildAddress(suite.DB(), nil, []factory.Trait{factory.GetTraitAddress3}) + + mtoShipment := factory.BuildMTOShipmentMinimal(suite.DB(), []factory.Customization{ + { + Model: move, + LinkOnly: true, + }, + { + Model: pickupAddress, + LinkOnly: true, + Type: &factory.Addresses.PickupAddress, + }, + { + Model: deliveryAddress, + LinkOnly: true, + Type: &factory.Addresses.DeliveryAddress, + }, + { + Model: models.MTOShipment{ + PrimeEstimatedWeight: &estimatedPrimeWeight, + RequestedPickupDate: &pickupDate, + ShipmentType: models.MTOShipmentTypeHHGOutOfNTSDom, + }, + }, + }, nil) + + return mtoShipment + } + + reServiceCodeDOP := factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeDOP) + reServiceCodeDPK := factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeDPK) + reServiceCodeDDP := factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeDDP) + reServiceCodeDUPK := factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeDUPK) + reServiceCodeDLH := factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeDLH) + reServiceCodeDSH := factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeDSH) + reServiceCodeFSC := factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeFSC) + + startDate := time.Now().AddDate(-1, 0, 0) + endDate := startDate.AddDate(1, 1, 1) + sitEntryDate := time.Date(2020, time.October, 24, 0, 0, 0, 0, time.UTC) + sitPostalCode := "99999" + reason := "lorem ipsum" + + contract := testdatagen.FetchOrMakeReContract(suite.DB(), testdatagen.Assertions{}) + contractYear := testdatagen.MakeReContractYear(suite.DB(), + testdatagen.Assertions{ + ReContractYear: models.ReContractYear{ + Name: "Test Contract Year", + EscalationCompounded: 1.125, + StartDate: startDate, + EndDate: endDate, + }, + }) + + serviceArea := testdatagen.MakeReDomesticServiceArea(suite.DB(), + testdatagen.Assertions{ + ReDomesticServiceArea: models.ReDomesticServiceArea{ + Contract: contractYear.Contract, + ServiceArea: "945", + ServicesSchedule: 1, + }, + }) + + serviceAreaDest := testdatagen.MakeReDomesticServiceArea(suite.DB(), + testdatagen.Assertions{ + ReDomesticServiceArea: models.ReDomesticServiceArea{ + Contract: contractYear.Contract, + ServiceArea: "503", + ServicesSchedule: 1, + }, + }) + + serviceAreaPriceDOP := models.ReDomesticServiceAreaPrice{ + ContractID: contractYear.Contract.ID, + ServiceID: reServiceCodeDOP.ID, + IsPeakPeriod: true, + DomesticServiceAreaID: serviceArea.ID, + PriceCents: unit.Cents(1234), + } + + serviceAreaPriceDPK := models.ReDomesticOtherPrice{ + ContractID: contractYear.Contract.ID, + ServiceID: reServiceCodeDPK.ID, + IsPeakPeriod: true, + Schedule: 1, + PriceCents: unit.Cents(121), + } + + serviceAreaPriceDDP := models.ReDomesticServiceAreaPrice{ + ContractID: contractYear.Contract.ID, + ServiceID: reServiceCodeDDP.ID, + IsPeakPeriod: true, + DomesticServiceAreaID: serviceAreaDest.ID, + PriceCents: unit.Cents(482), + } + + serviceAreaPriceDUPK := models.ReDomesticOtherPrice{ + ContractID: contractYear.Contract.ID, + ServiceID: reServiceCodeDUPK.ID, + IsPeakPeriod: true, + Schedule: 1, + PriceCents: unit.Cents(945), + } + + serviceAreaPriceDLH := models.ReDomesticLinehaulPrice{ + ContractID: contractYear.Contract.ID, + WeightLower: 500, + WeightUpper: 10000, + MilesLower: 1, + MilesUpper: 10000, + IsPeakPeriod: true, + DomesticServiceAreaID: serviceArea.ID, + PriceMillicents: unit.Millicents(482), + } + + serviceAreaPriceDSH := models.ReDomesticServiceAreaPrice{ + ContractID: contractYear.Contract.ID, + ServiceID: reServiceCodeDSH.ID, + IsPeakPeriod: true, + DomesticServiceAreaID: serviceArea.ID, + PriceCents: unit.Cents(999), + } + + testdatagen.MakeGHCDieselFuelPrice(suite.DB(), testdatagen.Assertions{ + GHCDieselFuelPrice: models.GHCDieselFuelPrice{ + FuelPriceInMillicents: unit.Millicents(281400), + PublicationDate: time.Date(2020, time.March, 9, 0, 0, 0, 0, time.UTC), + EffectiveDate: time.Date(2020, time.March, 10, 0, 0, 0, 0, time.UTC), + EndDate: time.Date(2025, time.March, 17, 0, 0, 0, 0, time.UTC), + }, + }) + + suite.MustSave(&serviceAreaPriceDOP) + suite.MustSave(&serviceAreaPriceDPK) + suite.MustSave(&serviceAreaPriceDDP) + suite.MustSave(&serviceAreaPriceDUPK) + suite.MustSave(&serviceAreaPriceDLH) + suite.MustSave(&serviceAreaPriceDSH) + + testdatagen.MakeReZip3(suite.DB(), testdatagen.Assertions{ + ReZip3: models.ReZip3{ + Contract: contract, + ContractID: contract.ID, + DomesticServiceArea: serviceArea, + Zip3: "945", + }, + }) + + testdatagen.MakeReZip3(suite.DB(), testdatagen.Assertions{ + ReZip3: models.ReZip3{ + Contract: contract, + ContractID: contract.ID, + DomesticServiceArea: serviceAreaDest, + Zip3: "503", + }, + }) + + shipment := setupTestData() + actualPickupAddress := factory.BuildAddress(suite.DB(), nil, []factory.Trait{factory.GetTraitAddress2}) + serviceItemDOP := models.MTOServiceItem{ + MoveTaskOrder: shipment.MoveTaskOrder, + MoveTaskOrderID: shipment.MoveTaskOrderID, + MTOShipment: shipment, + MTOShipmentID: &shipment.ID, + ReService: reServiceCodeDOP, + SITEntryDate: &sitEntryDate, + SITPostalCode: &sitPostalCode, + Reason: &reason, + SITOriginHHGActualAddress: &actualPickupAddress, + Status: models.MTOServiceItemStatusSubmitted, + } + + serviceItemDPK := models.MTOServiceItem{ + MoveTaskOrder: shipment.MoveTaskOrder, + MoveTaskOrderID: shipment.MoveTaskOrderID, + MTOShipment: shipment, + MTOShipmentID: &shipment.ID, + ReService: reServiceCodeDPK, + SITEntryDate: &sitEntryDate, + SITPostalCode: &sitPostalCode, + Reason: &reason, + SITOriginHHGActualAddress: &actualPickupAddress, + Status: models.MTOServiceItemStatusSubmitted, + } + + serviceItemDDP := models.MTOServiceItem{ + MoveTaskOrder: shipment.MoveTaskOrder, + MoveTaskOrderID: shipment.MoveTaskOrderID, + MTOShipment: shipment, + MTOShipmentID: &shipment.ID, + ReService: reServiceCodeDDP, + SITEntryDate: &sitEntryDate, + SITPostalCode: &sitPostalCode, + Reason: &reason, + SITOriginHHGActualAddress: &actualPickupAddress, + Status: models.MTOServiceItemStatusSubmitted, + } + + serviceItemDUPK := models.MTOServiceItem{ + MoveTaskOrder: shipment.MoveTaskOrder, + MoveTaskOrderID: shipment.MoveTaskOrderID, + MTOShipment: shipment, + MTOShipmentID: &shipment.ID, + ReService: reServiceCodeDUPK, + SITEntryDate: &sitEntryDate, + SITPostalCode: &sitPostalCode, + Reason: &reason, + SITOriginHHGActualAddress: &actualPickupAddress, + Status: models.MTOServiceItemStatusSubmitted, + } + + serviceItemDLH := models.MTOServiceItem{ + MoveTaskOrder: shipment.MoveTaskOrder, + MoveTaskOrderID: shipment.MoveTaskOrderID, + MTOShipment: shipment, + MTOShipmentID: &shipment.ID, + ReService: reServiceCodeDLH, + SITEntryDate: &sitEntryDate, + SITPostalCode: &sitPostalCode, + Reason: &reason, + SITOriginHHGActualAddress: &actualPickupAddress, + Status: models.MTOServiceItemStatusSubmitted, + } + + serviceItemDSH := models.MTOServiceItem{ + MoveTaskOrder: shipment.MoveTaskOrder, + MoveTaskOrderID: shipment.MoveTaskOrderID, + MTOShipment: shipment, + MTOShipmentID: &shipment.ID, + ReService: reServiceCodeDSH, + SITEntryDate: &sitEntryDate, + SITPostalCode: &sitPostalCode, + Reason: &reason, + SITOriginHHGActualAddress: &actualPickupAddress, + Status: models.MTOServiceItemStatusSubmitted, + } + + serviceItemFSC := models.MTOServiceItem{ + MoveTaskOrder: shipment.MoveTaskOrder, + MoveTaskOrderID: shipment.MoveTaskOrderID, + MTOShipment: shipment, + MTOShipmentID: &shipment.ID, + ReService: reServiceCodeFSC, + SITEntryDate: &sitEntryDate, + SITPostalCode: &sitPostalCode, + Reason: &reason, + SITOriginHHGActualAddress: &actualPickupAddress, + Status: models.MTOServiceItemStatusSubmitted, + } + + builder := query.NewQueryBuilder() + moveRouter := moverouter.NewMoveRouter() + planner := &mocks.Planner{} + planner.On("ZipTransitDistance", + mock.AnythingOfType("*appcontext.appContext"), + mock.Anything, + mock.Anything, + ).Return(400, nil) + creator := NewMTOServiceItemCreator(planner, builder, moveRouter, ghcrateengine.NewDomesticUnpackPricer(), ghcrateengine.NewDomesticPackPricer(), ghcrateengine.NewDomesticLinehaulPricer(), ghcrateengine.NewDomesticShorthaulPricer(), ghcrateengine.NewDomesticOriginPricer(), ghcrateengine.NewDomesticDestinationPricer(), ghcrateengine.NewFuelSurchargePricer()) + + dopEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDOP, shipment) + suite.Equal(unit.Cents(91608), dopEstimatedPriceInCents) + + dpkEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDPK, shipment) + suite.Equal(unit.Cents(8976), dpkEstimatedPriceInCents) + + ddpEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDDP, shipment) + suite.Equal(unit.Cents(35772), ddpEstimatedPriceInCents) + + dupkEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDUPK, shipment) + suite.Equal(unit.Cents(70158), dupkEstimatedPriceInCents) + + dlhEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDLH, shipment) + suite.Equal(unit.Cents(15840), dlhEstimatedPriceInCents) + + dshEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDSH, shipment) + suite.Equal(unit.Cents(29673600), dshEstimatedPriceInCents) + + fscEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemFSC, shipment) + suite.Equal(unit.Cents(786), fscEstimatedPriceInCents) + }) + +} + +/**** + + +func (suite *MTOServiceItemServiceSuite) TestPriceEstimator() { + setupTestData := func() models.MTOShipment { + // Set up data to use for all Origin SIT Service Item tests + + move := factory.BuildAvailableToPrimeMove(suite.DB(), nil, nil) + estimatedPrimeWeight := unit.Pound(6000) + pickupDate := time.Date(2024, time.July, 31, 12, 0, 0, 0, time.UTC) + pickupAddress := factory.BuildAddress(suite.DB(), nil, []factory.Trait{factory.GetTraitAddress2}) + deliveryAddress := factory.BuildAddress(suite.DB(), nil, []factory.Trait{factory.GetTraitAddress3}) + + mtoShipment := factory.BuildMTOShipmentMinimal(suite.DB(), []factory.Customization{ + { + Model: move, + LinkOnly: true, + }, + { + Model: pickupAddress, + LinkOnly: true, + Type: &factory.Addresses.PickupAddress, + }, + { + Model: deliveryAddress, + LinkOnly: true, + Type: &factory.Addresses.DeliveryAddress, + }, + { + Model: models.MTOShipment{ + PrimeEstimatedWeight: &estimatedPrimeWeight, + RequestedPickupDate: &pickupDate, + }, + }, + }, nil) + + return mtoShipment + } + + shipment := setupTestData() + actualPickupAddress := factory.BuildAddress(suite.DB(), nil, []factory.Trait{factory.GetTraitAddress2}) + sitEntryDate := time.Date(2020, time.October, 24, 0, 0, 0, 0, time.UTC) + sitPostalCode := "99999" + reason := "lorem ipsum" + + var reServiceCodeDOP models.ReService + var reServiceCodeDPK models.ReService + var reServiceCodeDDP models.ReService + var reServiceCodeDUPK models.ReService + + startDate := time.Now().AddDate(-1, 0, 0) + endDate := startDate.AddDate(1, 1, 1) + + contract := testdatagen.FetchOrMakeReContract(suite.DB(), testdatagen.Assertions{}) + contractYear := testdatagen.MakeReContractYear(suite.DB(), + testdatagen.Assertions{ + ReContractYear: models.ReContractYear{ + Name: "Test Contract Year", + EscalationCompounded: 1.125, + StartDate: startDate, + EndDate: endDate, + }, + }) + + serviceArea := testdatagen.MakeReDomesticServiceArea(suite.DB(), + testdatagen.Assertions{ + ReDomesticServiceArea: models.ReDomesticServiceArea{ + Contract: contractYear.Contract, + ServiceArea: "945", + }, + }) + + testdatagen.MakeReZip3(suite.DB(), testdatagen.Assertions{ + ReZip3: models.ReZip3{ + Contract: contract, + ContractID: contract.ID, + DomesticServiceArea: serviceArea, + Zip3: "945", + }, + }) + + serviceAreaPriceDOP := models.ReDomesticServiceAreaPrice{ + ContractID: contract.ID, + ServiceID: reServiceCodeDOP.ID, + IsPeakPeriod: true, + DomesticServiceAreaID: serviceArea.ID, + PriceCents: unit.Cents(1234), + } + + serviceAreaPriceDPK := models.ReDomesticServiceAreaPrice{ + ContractID: contract.ID, + ServiceID: reServiceCodeDPK.ID, + IsPeakPeriod: true, + DomesticServiceAreaID: serviceArea.ID, + PriceCents: unit.Cents(121), + } + + serviceAreaPriceDDP := models.ReDomesticServiceAreaPrice{ + ContractID: contract.ID, + ServiceID: reServiceCodeDDP.ID, + IsPeakPeriod: true, + DomesticServiceAreaID: serviceArea.ID, + PriceCents: unit.Cents(482), + } + + serviceAreaPriceDUPK := models.ReDomesticServiceAreaPrice{ + ContractID: contract.ID, + ServiceID: reServiceCodeDUPK.ID, + IsPeakPeriod: true, + DomesticServiceAreaID: serviceArea.ID, + PriceCents: unit.Cents(945), + } + + reServiceCodeDOP = factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeDOP) + reServiceCodeDPK = factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeDPK) + reServiceCodeDDP = factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeDDP) + reServiceCodeDUPK = factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeDUPK) + + serviceItemDOP := models.MTOServiceItem{ + MoveTaskOrder: shipment.MoveTaskOrder, + MoveTaskOrderID: shipment.MoveTaskOrderID, + MTOShipment: shipment, + MTOShipmentID: &shipment.ID, + ReService: reServiceCodeDOP, + SITEntryDate: &sitEntryDate, + SITPostalCode: &sitPostalCode, + Reason: &reason, + SITOriginHHGActualAddress: &actualPickupAddress, + Status: models.MTOServiceItemStatusSubmitted, + } + + serviceItemDPK := models.MTOServiceItem{ + MoveTaskOrder: shipment.MoveTaskOrder, + MoveTaskOrderID: shipment.MoveTaskOrderID, + MTOShipment: shipment, + MTOShipmentID: &shipment.ID, + ReService: reServiceCodeDPK, + SITEntryDate: &sitEntryDate, + SITPostalCode: &sitPostalCode, + Reason: &reason, + SITOriginHHGActualAddress: &actualPickupAddress, + Status: models.MTOServiceItemStatusSubmitted, + } + + serviceItemDDP := models.MTOServiceItem{ + MoveTaskOrder: shipment.MoveTaskOrder, + MoveTaskOrderID: shipment.MoveTaskOrderID, + MTOShipment: shipment, + MTOShipmentID: &shipment.ID, + ReService: reServiceCodeDDP, + SITEntryDate: &sitEntryDate, + SITPostalCode: &sitPostalCode, + Reason: &reason, + SITOriginHHGActualAddress: &actualPickupAddress, + Status: models.MTOServiceItemStatusSubmitted, + } + + serviceItemDUPK := models.MTOServiceItem{ + MoveTaskOrder: shipment.MoveTaskOrder, + MoveTaskOrderID: shipment.MoveTaskOrderID, + MTOShipment: shipment, + MTOShipmentID: &shipment.ID, + ReService: reServiceCodeDUPK, + SITEntryDate: &sitEntryDate, + SITPostalCode: &sitPostalCode, + Reason: &reason, + SITOriginHHGActualAddress: &actualPickupAddress, + Status: models.MTOServiceItemStatusSubmitted, + } + + suite.Run("Calcuating price estimated on creation for DOP", func() { + builder := query.NewQueryBuilder() + moveRouter := moverouter.NewMoveRouter() + planner := &mocks.Planner{} + planner.On("ZipTransitDistance", + mock.AnythingOfType("*appcontext.appContext"), + mock.Anything, + mock.Anything, + ).Return(400, nil) + creator := NewMTOServiceItemCreator(planner, builder, moveRouter, ghcrateengine.NewDomesticUnpackPricer(), ghcrateengine.NewDomesticPackPricer(), ghcrateengine.NewDomesticLinehaulPricer(), ghcrateengine.NewDomesticShorthaulPricer(), ghcrateengine.NewDomesticOriginPricer(), ghcrateengine.NewDomesticDestinationPricer(), ghcrateengine.NewFuelSurchargePricer()) + + suite.MustSave(&serviceAreaPriceDOP) + + dopEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDOP, shipment) + suite.Equal(unit.Cents(83280), dopEstimatedPriceInCents) + }) + + suite.Run("Calcuating price estimated on creation for DPK", func() { + builder := query.NewQueryBuilder() + moveRouter := moverouter.NewMoveRouter() + planner := &mocks.Planner{} + planner.On("ZipTransitDistance", + mock.AnythingOfType("*appcontext.appContext"), + mock.Anything, + mock.Anything, + ).Return(400, nil) + creator := NewMTOServiceItemCreator(planner, builder, moveRouter, ghcrateengine.NewDomesticUnpackPricer(), ghcrateengine.NewDomesticPackPricer(), ghcrateengine.NewDomesticLinehaulPricer(), ghcrateengine.NewDomesticShorthaulPricer(), ghcrateengine.NewDomesticOriginPricer(), ghcrateengine.NewDomesticDestinationPricer(), ghcrateengine.NewFuelSurchargePricer()) + + suite.MustSave(&serviceAreaPriceDPK) + + dpkEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDPK, shipment) + suite.Equal(unit.Cents(47760), dpkEstimatedPriceInCents) + }) + + suite.Run("Calcuating price estimated on creation for DDP", func() { + builder := query.NewQueryBuilder() + moveRouter := moverouter.NewMoveRouter() + planner := &mocks.Planner{} + planner.On("ZipTransitDistance", + mock.AnythingOfType("*appcontext.appContext"), + mock.Anything, + mock.Anything, + ).Return(400, nil) + creator := NewMTOServiceItemCreator(planner, builder, moveRouter, ghcrateengine.NewDomesticUnpackPricer(), ghcrateengine.NewDomesticPackPricer(), ghcrateengine.NewDomesticLinehaulPricer(), ghcrateengine.NewDomesticShorthaulPricer(), ghcrateengine.NewDomesticOriginPricer(), ghcrateengine.NewDomesticDestinationPricer(), ghcrateengine.NewFuelSurchargePricer()) + + suite.MustSave(&serviceAreaPriceDDP) + + ddpEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDDP, shipment) + suite.Equal(unit.Cents(47760), ddpEstimatedPriceInCents) + }) + + suite.Run("Calcuating price estimated on creation for DUPK", func() { + builder := query.NewQueryBuilder() + moveRouter := moverouter.NewMoveRouter() + planner := &mocks.Planner{} + planner.On("ZipTransitDistance", + mock.AnythingOfType("*appcontext.appContext"), + mock.Anything, + mock.Anything, + ).Return(400, nil) + creator := NewMTOServiceItemCreator(planner, builder, moveRouter, ghcrateengine.NewDomesticUnpackPricer(), ghcrateengine.NewDomesticPackPricer(), ghcrateengine.NewDomesticLinehaulPricer(), ghcrateengine.NewDomesticShorthaulPricer(), ghcrateengine.NewDomesticOriginPricer(), ghcrateengine.NewDomesticDestinationPricer(), ghcrateengine.NewFuelSurchargePricer()) + + suite.MustSave(&serviceAreaPriceDUPK) + + dupkEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDUPK, shipment) + suite.Equal(unit.Cents(47760), dupkEstimatedPriceInCents) + }) + + /** + // suite.Run("Calcuating price estimated on creation for NTS shipment ", func() { + // var reServiceCodeDOP models.ReService + + // setupTestData := func() models.MTOShipment { + // // Set up data to use for all Origin SIT Service Item tests + + // move := factory.BuildAvailableToPrimeMove(suite.DB(), nil, nil) + // estimatedPrimeWeight := unit.Pound(6000) + // pickupDate := time.Date(2024, time.July, 31, 12, 0, 0, 0, time.UTC) + // pickupAddress := factory.BuildAddress(suite.DB(), nil, []factory.Trait{factory.GetTraitAddress2}) + // deliveryAddress := factory.BuildAddress(suite.DB(), nil, []factory.Trait{factory.GetTraitAddress3}) + + // customMTOShipmentTypeHHGOutOfNTSDom := factory.BuildMTOShipmentMinimal(suite.DB(), []factory.Customization{ + // { + // Model: move, + // LinkOnly: true, + // }, + // { + // Model: pickupAddress, + // LinkOnly: true, + // Type: &factory.Addresses.PickupAddress, + // }, + // { + // Model: deliveryAddress, + // LinkOnly: true, + // Type: &factory.Addresses.DeliveryAddress, + // }, + // { + // Model: models.MTOShipment{ + // PrimeEstimatedWeight: &estimatedPrimeWeight, + // RequestedPickupDate: &pickupDate, + // ShipmentType: models.MTOShipmentTypeHHGOutOfNTSDom, + // }, + // }, + // }, nil) + + // reServiceCodeDOP = factory.BuildReService(suite.DB(), []factory.Customization{ + // { + // Model: models.ReService{ + // Code: "DOP", + // }, + // }, + // }, nil) + + // startDate := time.Now().AddDate(-1, 0, 0) + // endDate := startDate.AddDate(1, 1, 1) + // contract := testdatagen.FetchOrMakeReContract(suite.DB(), testdatagen.Assertions{}) + // testdatagen.FetchOrMakeReContractYear(suite.DB(), testdatagen.Assertions{ + // ReContractYear: models.ReContractYear{ + // Contract: contract, + // ContractID: contract.ID, + // StartDate: startDate, + // EndDate: endDate, + // Escalation: 1.0, + // EscalationCompounded: 1.0, + // }, + // }) + // testdatagen.MakeReZip3(suite.DB(), testdatagen.Assertions{ + // ReZip3: models.ReZip3{ + // Contract: contract, + // ContractID: contract.ID, + // DomesticServiceArea: testdatagen.FetchOrMakeReDomesticServiceArea(suite.DB(), testdatagen.Assertions{ + // ReDomesticServiceArea: models.ReDomesticServiceArea{ + // ContractID: contract.ID, + // ServiceArea: "674", + // ServicesSchedule: 2, + // CreatedAt: time.Now(), + // UpdatedAt: time.Now(), + // }, + // }), + // Zip3: "674", + // }, + // }) + // testdatagen.MakeReDomesticServiceAreaPrice(suite.DB(), testdatagen.Assertions{ReService: models.ReService{Code: "DOP"}}) + + // return customMTOShipmentTypeHHGOutOfNTSDom + // } + + // shipment := setupTestData() + // actualPickupAddress := factory.BuildAddress(suite.DB(), nil, []factory.Trait{factory.GetTraitAddress2}) + // actualPickupAddress.PostalCode = "67449" + + // serviceItemDOP := models.MTOServiceItem{ + // MoveTaskOrder: shipment.MoveTaskOrder, + // MoveTaskOrderID: shipment.MoveTaskOrderID, + // MTOShipment: shipment, + // MTOShipmentID: &shipment.ID, + // ReService: reServiceCodeDOP, + // SITEntryDate: &sitEntryDate, + // SITPostalCode: &sitPostalCode, + // Reason: &reason, + // SITOriginHHGActualAddress: &actualPickupAddress, + // Status: models.MTOServiceItemStatusSubmitted, + // } + + // builder := query.NewQueryBuilder() + // moveRouter := moverouter.NewMoveRouter() + // planner := &mocks.Planner{} + // planner.On("ZipTransitDistance", + // mock.AnythingOfType("*appcontext.appContext"), + // mock.Anything, + // mock.Anything, + // ).Return(400, nil) + // creator := NewMTOServiceItemCreator(planner, builder, moveRouter, ghcrateengine.NewDomesticUnpackPricer(), ghcrateengine.NewDomesticPackPricer(), ghcrateengine.NewDomesticLinehaulPricer(), ghcrateengine.NewDomesticShorthaulPricer(), ghcrateengine.NewDomesticOriginPricer(), ghcrateengine.NewDomesticDestinationPricer(), ghcrateengine.NewFuelSurchargePricer()) + + // estimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDOP, shipment) + // estimatedPriceForMTOShipmentTypeHHGOutOfNTSDom := estimatedPriceInCents.Float64() * 1.1 + // suite.Equal(estimatedPriceInCents, unit.Cents(estimatedPriceForMTOShipmentTypeHHGOutOfNTSDom)) + // }) + **/ +//} From 529b1403b72f05a4d98de07044bf523ad17eded1 Mon Sep 17 00:00:00 2001 From: loganwc Date: Wed, 13 Nov 2024 18:52:51 +0000 Subject: [PATCH 06/21] someone deleted a thing i wanted --- .../mto_service_item_creator_test.go | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 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 aa9c691fe76..97b9e7407d0 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 @@ -1856,13 +1856,13 @@ func (suite *MTOServiceItemServiceSuite) TestPriceEstimator() { return mtoShipment } - reServiceCodeDOP := factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeDOP) - reServiceCodeDPK := factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeDPK) - reServiceCodeDDP := factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeDDP) - reServiceCodeDUPK := factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeDUPK) - reServiceCodeDLH := factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeDLH) - reServiceCodeDSH := factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeDSH) - reServiceCodeFSC := factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeFSC) + reServiceCodeDOP := factory.FetchReServiceByCode(suite.DB(), models.ReServiceCodeDOP) + reServiceCodeDPK := factory.FetchReServiceByCode(suite.DB(), models.ReServiceCodeDPK) + reServiceCodeDDP := factory.FetchReServiceByCode(suite.DB(), models.ReServiceCodeDDP) + reServiceCodeDUPK := factory.FetchReServiceByCode(suite.DB(), models.ReServiceCodeDUPK) + reServiceCodeDLH := factory.FetchReServiceByCode(suite.DB(), models.ReServiceCodeDLH) + reServiceCodeDSH := factory.FetchReServiceByCode(suite.DB(), models.ReServiceCodeDSH) + reServiceCodeFSC := factory.FetchReServiceByCode(suite.DB(), models.ReServiceCodeFSC) startDate := time.Now().AddDate(-1, 0, 0) endDate := startDate.AddDate(1, 1, 1) @@ -2146,13 +2146,13 @@ func (suite *MTOServiceItemServiceSuite) TestPriceEstimator() { return mtoShipment } - reServiceCodeDOP := factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeDOP) - reServiceCodeDPK := factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeDPK) - reServiceCodeDDP := factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeDDP) - reServiceCodeDUPK := factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeDUPK) - reServiceCodeDLH := factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeDLH) - reServiceCodeDSH := factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeDSH) - reServiceCodeFSC := factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeFSC) + reServiceCodeDOP := factory.FetchReServiceByCode(suite.DB(), models.ReServiceCodeDOP) + reServiceCodeDPK := factory.FetchReServiceByCode(suite.DB(), models.ReServiceCodeDPK) + reServiceCodeDDP := factory.FetchReServiceByCode(suite.DB(), models.ReServiceCodeDDP) + reServiceCodeDUPK := factory.FetchReServiceByCode(suite.DB(), models.ReServiceCodeDUPK) + reServiceCodeDLH := factory.FetchReServiceByCode(suite.DB(), models.ReServiceCodeDLH) + reServiceCodeDSH := factory.FetchReServiceByCode(suite.DB(), models.ReServiceCodeDSH) + reServiceCodeFSC := factory.FetchReServiceByCode(suite.DB(), models.ReServiceCodeFSC) startDate := time.Now().AddDate(-1, 0, 0) endDate := startDate.AddDate(1, 1, 1) From ab2950c41f0af646b3aa1f4028f9ac6e07b6c23b Mon Sep 17 00:00:00 2001 From: Logan Cunningham <148146808+loganwc@users.noreply.github.com> Date: Thu, 14 Nov 2024 12:30:25 -0600 Subject: [PATCH 07/21] Update mto_service_item_creator_test.go --- .../mto_service_item_creator_test.go | 350 ------------------ 1 file changed, 350 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 97b9e7407d0..b3cf305f3f3 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 @@ -2401,353 +2401,3 @@ func (suite *MTOServiceItemServiceSuite) TestPriceEstimator() { } -/**** - - -func (suite *MTOServiceItemServiceSuite) TestPriceEstimator() { - setupTestData := func() models.MTOShipment { - // Set up data to use for all Origin SIT Service Item tests - - move := factory.BuildAvailableToPrimeMove(suite.DB(), nil, nil) - estimatedPrimeWeight := unit.Pound(6000) - pickupDate := time.Date(2024, time.July, 31, 12, 0, 0, 0, time.UTC) - pickupAddress := factory.BuildAddress(suite.DB(), nil, []factory.Trait{factory.GetTraitAddress2}) - deliveryAddress := factory.BuildAddress(suite.DB(), nil, []factory.Trait{factory.GetTraitAddress3}) - - mtoShipment := factory.BuildMTOShipmentMinimal(suite.DB(), []factory.Customization{ - { - Model: move, - LinkOnly: true, - }, - { - Model: pickupAddress, - LinkOnly: true, - Type: &factory.Addresses.PickupAddress, - }, - { - Model: deliveryAddress, - LinkOnly: true, - Type: &factory.Addresses.DeliveryAddress, - }, - { - Model: models.MTOShipment{ - PrimeEstimatedWeight: &estimatedPrimeWeight, - RequestedPickupDate: &pickupDate, - }, - }, - }, nil) - - return mtoShipment - } - - shipment := setupTestData() - actualPickupAddress := factory.BuildAddress(suite.DB(), nil, []factory.Trait{factory.GetTraitAddress2}) - sitEntryDate := time.Date(2020, time.October, 24, 0, 0, 0, 0, time.UTC) - sitPostalCode := "99999" - reason := "lorem ipsum" - - var reServiceCodeDOP models.ReService - var reServiceCodeDPK models.ReService - var reServiceCodeDDP models.ReService - var reServiceCodeDUPK models.ReService - - startDate := time.Now().AddDate(-1, 0, 0) - endDate := startDate.AddDate(1, 1, 1) - - contract := testdatagen.FetchOrMakeReContract(suite.DB(), testdatagen.Assertions{}) - contractYear := testdatagen.MakeReContractYear(suite.DB(), - testdatagen.Assertions{ - ReContractYear: models.ReContractYear{ - Name: "Test Contract Year", - EscalationCompounded: 1.125, - StartDate: startDate, - EndDate: endDate, - }, - }) - - serviceArea := testdatagen.MakeReDomesticServiceArea(suite.DB(), - testdatagen.Assertions{ - ReDomesticServiceArea: models.ReDomesticServiceArea{ - Contract: contractYear.Contract, - ServiceArea: "945", - }, - }) - - testdatagen.MakeReZip3(suite.DB(), testdatagen.Assertions{ - ReZip3: models.ReZip3{ - Contract: contract, - ContractID: contract.ID, - DomesticServiceArea: serviceArea, - Zip3: "945", - }, - }) - - serviceAreaPriceDOP := models.ReDomesticServiceAreaPrice{ - ContractID: contract.ID, - ServiceID: reServiceCodeDOP.ID, - IsPeakPeriod: true, - DomesticServiceAreaID: serviceArea.ID, - PriceCents: unit.Cents(1234), - } - - serviceAreaPriceDPK := models.ReDomesticServiceAreaPrice{ - ContractID: contract.ID, - ServiceID: reServiceCodeDPK.ID, - IsPeakPeriod: true, - DomesticServiceAreaID: serviceArea.ID, - PriceCents: unit.Cents(121), - } - - serviceAreaPriceDDP := models.ReDomesticServiceAreaPrice{ - ContractID: contract.ID, - ServiceID: reServiceCodeDDP.ID, - IsPeakPeriod: true, - DomesticServiceAreaID: serviceArea.ID, - PriceCents: unit.Cents(482), - } - - serviceAreaPriceDUPK := models.ReDomesticServiceAreaPrice{ - ContractID: contract.ID, - ServiceID: reServiceCodeDUPK.ID, - IsPeakPeriod: true, - DomesticServiceAreaID: serviceArea.ID, - PriceCents: unit.Cents(945), - } - - reServiceCodeDOP = factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeDOP) - reServiceCodeDPK = factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeDPK) - reServiceCodeDDP = factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeDDP) - reServiceCodeDUPK = factory.BuildReServiceByCode(suite.DB(), models.ReServiceCodeDUPK) - - serviceItemDOP := models.MTOServiceItem{ - MoveTaskOrder: shipment.MoveTaskOrder, - MoveTaskOrderID: shipment.MoveTaskOrderID, - MTOShipment: shipment, - MTOShipmentID: &shipment.ID, - ReService: reServiceCodeDOP, - SITEntryDate: &sitEntryDate, - SITPostalCode: &sitPostalCode, - Reason: &reason, - SITOriginHHGActualAddress: &actualPickupAddress, - Status: models.MTOServiceItemStatusSubmitted, - } - - serviceItemDPK := models.MTOServiceItem{ - MoveTaskOrder: shipment.MoveTaskOrder, - MoveTaskOrderID: shipment.MoveTaskOrderID, - MTOShipment: shipment, - MTOShipmentID: &shipment.ID, - ReService: reServiceCodeDPK, - SITEntryDate: &sitEntryDate, - SITPostalCode: &sitPostalCode, - Reason: &reason, - SITOriginHHGActualAddress: &actualPickupAddress, - Status: models.MTOServiceItemStatusSubmitted, - } - - serviceItemDDP := models.MTOServiceItem{ - MoveTaskOrder: shipment.MoveTaskOrder, - MoveTaskOrderID: shipment.MoveTaskOrderID, - MTOShipment: shipment, - MTOShipmentID: &shipment.ID, - ReService: reServiceCodeDDP, - SITEntryDate: &sitEntryDate, - SITPostalCode: &sitPostalCode, - Reason: &reason, - SITOriginHHGActualAddress: &actualPickupAddress, - Status: models.MTOServiceItemStatusSubmitted, - } - - serviceItemDUPK := models.MTOServiceItem{ - MoveTaskOrder: shipment.MoveTaskOrder, - MoveTaskOrderID: shipment.MoveTaskOrderID, - MTOShipment: shipment, - MTOShipmentID: &shipment.ID, - ReService: reServiceCodeDUPK, - SITEntryDate: &sitEntryDate, - SITPostalCode: &sitPostalCode, - Reason: &reason, - SITOriginHHGActualAddress: &actualPickupAddress, - Status: models.MTOServiceItemStatusSubmitted, - } - - suite.Run("Calcuating price estimated on creation for DOP", func() { - builder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() - planner := &mocks.Planner{} - planner.On("ZipTransitDistance", - mock.AnythingOfType("*appcontext.appContext"), - mock.Anything, - mock.Anything, - ).Return(400, nil) - creator := NewMTOServiceItemCreator(planner, builder, moveRouter, ghcrateengine.NewDomesticUnpackPricer(), ghcrateengine.NewDomesticPackPricer(), ghcrateengine.NewDomesticLinehaulPricer(), ghcrateengine.NewDomesticShorthaulPricer(), ghcrateengine.NewDomesticOriginPricer(), ghcrateengine.NewDomesticDestinationPricer(), ghcrateengine.NewFuelSurchargePricer()) - - suite.MustSave(&serviceAreaPriceDOP) - - dopEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDOP, shipment) - suite.Equal(unit.Cents(83280), dopEstimatedPriceInCents) - }) - - suite.Run("Calcuating price estimated on creation for DPK", func() { - builder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() - planner := &mocks.Planner{} - planner.On("ZipTransitDistance", - mock.AnythingOfType("*appcontext.appContext"), - mock.Anything, - mock.Anything, - ).Return(400, nil) - creator := NewMTOServiceItemCreator(planner, builder, moveRouter, ghcrateengine.NewDomesticUnpackPricer(), ghcrateengine.NewDomesticPackPricer(), ghcrateengine.NewDomesticLinehaulPricer(), ghcrateengine.NewDomesticShorthaulPricer(), ghcrateengine.NewDomesticOriginPricer(), ghcrateengine.NewDomesticDestinationPricer(), ghcrateengine.NewFuelSurchargePricer()) - - suite.MustSave(&serviceAreaPriceDPK) - - dpkEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDPK, shipment) - suite.Equal(unit.Cents(47760), dpkEstimatedPriceInCents) - }) - - suite.Run("Calcuating price estimated on creation for DDP", func() { - builder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() - planner := &mocks.Planner{} - planner.On("ZipTransitDistance", - mock.AnythingOfType("*appcontext.appContext"), - mock.Anything, - mock.Anything, - ).Return(400, nil) - creator := NewMTOServiceItemCreator(planner, builder, moveRouter, ghcrateengine.NewDomesticUnpackPricer(), ghcrateengine.NewDomesticPackPricer(), ghcrateengine.NewDomesticLinehaulPricer(), ghcrateengine.NewDomesticShorthaulPricer(), ghcrateengine.NewDomesticOriginPricer(), ghcrateengine.NewDomesticDestinationPricer(), ghcrateengine.NewFuelSurchargePricer()) - - suite.MustSave(&serviceAreaPriceDDP) - - ddpEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDDP, shipment) - suite.Equal(unit.Cents(47760), ddpEstimatedPriceInCents) - }) - - suite.Run("Calcuating price estimated on creation for DUPK", func() { - builder := query.NewQueryBuilder() - moveRouter := moverouter.NewMoveRouter() - planner := &mocks.Planner{} - planner.On("ZipTransitDistance", - mock.AnythingOfType("*appcontext.appContext"), - mock.Anything, - mock.Anything, - ).Return(400, nil) - creator := NewMTOServiceItemCreator(planner, builder, moveRouter, ghcrateengine.NewDomesticUnpackPricer(), ghcrateengine.NewDomesticPackPricer(), ghcrateengine.NewDomesticLinehaulPricer(), ghcrateengine.NewDomesticShorthaulPricer(), ghcrateengine.NewDomesticOriginPricer(), ghcrateengine.NewDomesticDestinationPricer(), ghcrateengine.NewFuelSurchargePricer()) - - suite.MustSave(&serviceAreaPriceDUPK) - - dupkEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDUPK, shipment) - suite.Equal(unit.Cents(47760), dupkEstimatedPriceInCents) - }) - - /** - // suite.Run("Calcuating price estimated on creation for NTS shipment ", func() { - // var reServiceCodeDOP models.ReService - - // setupTestData := func() models.MTOShipment { - // // Set up data to use for all Origin SIT Service Item tests - - // move := factory.BuildAvailableToPrimeMove(suite.DB(), nil, nil) - // estimatedPrimeWeight := unit.Pound(6000) - // pickupDate := time.Date(2024, time.July, 31, 12, 0, 0, 0, time.UTC) - // pickupAddress := factory.BuildAddress(suite.DB(), nil, []factory.Trait{factory.GetTraitAddress2}) - // deliveryAddress := factory.BuildAddress(suite.DB(), nil, []factory.Trait{factory.GetTraitAddress3}) - - // customMTOShipmentTypeHHGOutOfNTSDom := factory.BuildMTOShipmentMinimal(suite.DB(), []factory.Customization{ - // { - // Model: move, - // LinkOnly: true, - // }, - // { - // Model: pickupAddress, - // LinkOnly: true, - // Type: &factory.Addresses.PickupAddress, - // }, - // { - // Model: deliveryAddress, - // LinkOnly: true, - // Type: &factory.Addresses.DeliveryAddress, - // }, - // { - // Model: models.MTOShipment{ - // PrimeEstimatedWeight: &estimatedPrimeWeight, - // RequestedPickupDate: &pickupDate, - // ShipmentType: models.MTOShipmentTypeHHGOutOfNTSDom, - // }, - // }, - // }, nil) - - // reServiceCodeDOP = factory.BuildReService(suite.DB(), []factory.Customization{ - // { - // Model: models.ReService{ - // Code: "DOP", - // }, - // }, - // }, nil) - - // startDate := time.Now().AddDate(-1, 0, 0) - // endDate := startDate.AddDate(1, 1, 1) - // contract := testdatagen.FetchOrMakeReContract(suite.DB(), testdatagen.Assertions{}) - // testdatagen.FetchOrMakeReContractYear(suite.DB(), testdatagen.Assertions{ - // ReContractYear: models.ReContractYear{ - // Contract: contract, - // ContractID: contract.ID, - // StartDate: startDate, - // EndDate: endDate, - // Escalation: 1.0, - // EscalationCompounded: 1.0, - // }, - // }) - // testdatagen.MakeReZip3(suite.DB(), testdatagen.Assertions{ - // ReZip3: models.ReZip3{ - // Contract: contract, - // ContractID: contract.ID, - // DomesticServiceArea: testdatagen.FetchOrMakeReDomesticServiceArea(suite.DB(), testdatagen.Assertions{ - // ReDomesticServiceArea: models.ReDomesticServiceArea{ - // ContractID: contract.ID, - // ServiceArea: "674", - // ServicesSchedule: 2, - // CreatedAt: time.Now(), - // UpdatedAt: time.Now(), - // }, - // }), - // Zip3: "674", - // }, - // }) - // testdatagen.MakeReDomesticServiceAreaPrice(suite.DB(), testdatagen.Assertions{ReService: models.ReService{Code: "DOP"}}) - - // return customMTOShipmentTypeHHGOutOfNTSDom - // } - - // shipment := setupTestData() - // actualPickupAddress := factory.BuildAddress(suite.DB(), nil, []factory.Trait{factory.GetTraitAddress2}) - // actualPickupAddress.PostalCode = "67449" - - // serviceItemDOP := models.MTOServiceItem{ - // MoveTaskOrder: shipment.MoveTaskOrder, - // MoveTaskOrderID: shipment.MoveTaskOrderID, - // MTOShipment: shipment, - // MTOShipmentID: &shipment.ID, - // ReService: reServiceCodeDOP, - // SITEntryDate: &sitEntryDate, - // SITPostalCode: &sitPostalCode, - // Reason: &reason, - // SITOriginHHGActualAddress: &actualPickupAddress, - // Status: models.MTOServiceItemStatusSubmitted, - // } - - // builder := query.NewQueryBuilder() - // moveRouter := moverouter.NewMoveRouter() - // planner := &mocks.Planner{} - // planner.On("ZipTransitDistance", - // mock.AnythingOfType("*appcontext.appContext"), - // mock.Anything, - // mock.Anything, - // ).Return(400, nil) - // creator := NewMTOServiceItemCreator(planner, builder, moveRouter, ghcrateengine.NewDomesticUnpackPricer(), ghcrateengine.NewDomesticPackPricer(), ghcrateengine.NewDomesticLinehaulPricer(), ghcrateengine.NewDomesticShorthaulPricer(), ghcrateengine.NewDomesticOriginPricer(), ghcrateengine.NewDomesticDestinationPricer(), ghcrateengine.NewFuelSurchargePricer()) - - // estimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDOP, shipment) - // estimatedPriceForMTOShipmentTypeHHGOutOfNTSDom := estimatedPriceInCents.Float64() * 1.1 - // suite.Equal(estimatedPriceInCents, unit.Cents(estimatedPriceForMTOShipmentTypeHHGOutOfNTSDom)) - // }) - **/ -//} From 7e9693ae4d85bad5d465256c34b7e452d3379045 Mon Sep 17 00:00:00 2001 From: Elizabeth Perkins Date: Mon, 16 Dec 2024 15:04:03 +0000 Subject: [PATCH 08/21] 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 09/21] 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 10/21] 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 11/21] 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 0cb1e19eca018a31cb93b0ec3e4db35859056b78 Mon Sep 17 00:00:00 2001 From: loganwc Date: Wed, 8 Jan 2025 20:16:06 +0000 Subject: [PATCH 12/21] update tests so they work with Dan the Mans changes --- .../mto_service_item/mto_service_item_creator_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 57090017648..cd6cb32b248 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 @@ -2106,6 +2106,8 @@ func (suite *MTOServiceItemServiceSuite) TestPriceEstimator() { mock.AnythingOfType("*appcontext.appContext"), mock.Anything, mock.Anything, + false, + false, ).Return(400, nil) creator := NewMTOServiceItemCreator(planner, builder, moveRouter, ghcrateengine.NewDomesticUnpackPricer(), ghcrateengine.NewDomesticPackPricer(), ghcrateengine.NewDomesticLinehaulPricer(), ghcrateengine.NewDomesticShorthaulPricer(), ghcrateengine.NewDomesticOriginPricer(), ghcrateengine.NewDomesticDestinationPricer(), ghcrateengine.NewFuelSurchargePricer()) @@ -2396,6 +2398,8 @@ func (suite *MTOServiceItemServiceSuite) TestPriceEstimator() { mock.AnythingOfType("*appcontext.appContext"), mock.Anything, mock.Anything, + false, + false, ).Return(400, nil) creator := NewMTOServiceItemCreator(planner, builder, moveRouter, ghcrateengine.NewDomesticUnpackPricer(), ghcrateengine.NewDomesticPackPricer(), ghcrateengine.NewDomesticLinehaulPricer(), ghcrateengine.NewDomesticShorthaulPricer(), ghcrateengine.NewDomesticOriginPricer(), ghcrateengine.NewDomesticDestinationPricer(), ghcrateengine.NewFuelSurchargePricer()) @@ -2422,4 +2426,3 @@ func (suite *MTOServiceItemServiceSuite) TestPriceEstimator() { }) } - From 7608779d2aab497354e9407935c82181d9836dc6 Mon Sep 17 00:00:00 2001 From: loganwc Date: Wed, 8 Jan 2025 23:10:03 +0000 Subject: [PATCH 13/21] more daniel madness --- .../mto_service_item_creator_test.go | 118 ++++++++++-------- 1 file changed, 67 insertions(+), 51 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 cd6cb32b248..c707eba0c96 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 @@ -1929,13 +1929,17 @@ func (suite *MTOServiceItemServiceSuite) TestPriceEstimator() { PriceCents: unit.Cents(1234), } - serviceAreaPriceDPK := models.ReDomesticOtherPrice{ - ContractID: contractYear.Contract.ID, - ServiceID: reServiceCodeDPK.ID, - IsPeakPeriod: true, - Schedule: 1, - PriceCents: unit.Cents(121), - } + serviceAreaPriceDPK := factory.FetchOrMakeDomesticOtherPrice(suite.DB(), []factory.Customization{ + { + Model: models.ReDomesticOtherPrice{ + ContractID: contractYear.Contract.ID, + ServiceID: reServiceCodeDPK.ID, + IsPeakPeriod: true, + Schedule: 1, + PriceCents: unit.Cents(121), + }, + }, + }, nil) serviceAreaPriceDDP := models.ReDomesticServiceAreaPrice{ ContractID: contractYear.Contract.ID, @@ -1945,13 +1949,17 @@ func (suite *MTOServiceItemServiceSuite) TestPriceEstimator() { PriceCents: unit.Cents(482), } - serviceAreaPriceDUPK := models.ReDomesticOtherPrice{ - ContractID: contractYear.Contract.ID, - ServiceID: reServiceCodeDUPK.ID, - IsPeakPeriod: true, - Schedule: 1, - PriceCents: unit.Cents(945), - } + serviceAreaPriceDUPK := factory.FetchOrMakeDomesticOtherPrice(suite.DB(), []factory.Customization{ + { + Model: models.ReDomesticOtherPrice{ + ContractID: contractYear.Contract.ID, + ServiceID: reServiceCodeDUPK.ID, + IsPeakPeriod: true, + Schedule: 1, + PriceCents: unit.Cents(945), + }, + }, + }, nil) serviceAreaPriceDLH := models.ReDomesticLinehaulPrice{ ContractID: contractYear.Contract.ID, @@ -1972,7 +1980,7 @@ func (suite *MTOServiceItemServiceSuite) TestPriceEstimator() { PriceCents: unit.Cents(999), } - testdatagen.MakeGHCDieselFuelPrice(suite.DB(), testdatagen.Assertions{ + testdatagen.FetchOrMakeGHCDieselFuelPrice(suite.DB(), testdatagen.Assertions{ GHCDieselFuelPrice: models.GHCDieselFuelPrice{ FuelPriceInMillicents: unit.Millicents(281400), PublicationDate: time.Date(2020, time.March, 9, 0, 0, 0, 0, time.UTC), @@ -1988,7 +1996,7 @@ func (suite *MTOServiceItemServiceSuite) TestPriceEstimator() { suite.MustSave(&serviceAreaPriceDLH) suite.MustSave(&serviceAreaPriceDSH) - testdatagen.MakeReZip3(suite.DB(), testdatagen.Assertions{ + testdatagen.FetchOrMakeReZip3(suite.DB(), testdatagen.Assertions{ ReZip3: models.ReZip3{ Contract: contract, ContractID: contract.ID, @@ -1997,7 +2005,7 @@ func (suite *MTOServiceItemServiceSuite) TestPriceEstimator() { }, }) - testdatagen.MakeReZip3(suite.DB(), testdatagen.Assertions{ + testdatagen.FetchOrMakeReZip3(suite.DB(), testdatagen.Assertions{ ReZip3: models.ReZip3{ Contract: contract, ContractID: contract.ID, @@ -2112,25 +2120,25 @@ func (suite *MTOServiceItemServiceSuite) TestPriceEstimator() { creator := NewMTOServiceItemCreator(planner, builder, moveRouter, ghcrateengine.NewDomesticUnpackPricer(), ghcrateengine.NewDomesticPackPricer(), ghcrateengine.NewDomesticLinehaulPricer(), ghcrateengine.NewDomesticShorthaulPricer(), ghcrateengine.NewDomesticOriginPricer(), ghcrateengine.NewDomesticDestinationPricer(), ghcrateengine.NewFuelSurchargePricer()) dopEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDOP, shipment) - suite.Equal(unit.Cents(83280), dopEstimatedPriceInCents) + suite.Equal(unit.Cents(61080), dopEstimatedPriceInCents) dpkEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDPK, shipment) - suite.Equal(unit.Cents(8160), dpkEstimatedPriceInCents) + suite.Equal(unit.Cents(540000), dpkEstimatedPriceInCents) ddpEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDDP, shipment) - suite.Equal(unit.Cents(32520), ddpEstimatedPriceInCents) + suite.Equal(unit.Cents(42240), ddpEstimatedPriceInCents) dupkEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDUPK, shipment) - suite.Equal(unit.Cents(63780), dupkEstimatedPriceInCents) + suite.Equal(unit.Cents(43860), dupkEstimatedPriceInCents) dlhEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDLH, shipment) - suite.Equal(unit.Cents(14400), dlhEstimatedPriceInCents) + suite.Equal(unit.Cents(12381600), dlhEstimatedPriceInCents) dshEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDSH, shipment) - suite.Equal(unit.Cents(26976000), dshEstimatedPriceInCents) + suite.Equal(unit.Cents(10080000), dshEstimatedPriceInCents) fscEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemFSC, shipment) - suite.Equal(unit.Cents(786), fscEstimatedPriceInCents) + suite.Equal(unit.Cents(-168), fscEstimatedPriceInCents) }) suite.Run("Calcuating price estimated on creation for NTS shipment ", func() { @@ -2185,7 +2193,7 @@ func (suite *MTOServiceItemServiceSuite) TestPriceEstimator() { reason := "lorem ipsum" contract := testdatagen.FetchOrMakeReContract(suite.DB(), testdatagen.Assertions{}) - contractYear := testdatagen.MakeReContractYear(suite.DB(), + contractYear := testdatagen.FetchOrMakeReContractYear(suite.DB(), testdatagen.Assertions{ ReContractYear: models.ReContractYear{ Name: "Test Contract Year", @@ -2195,7 +2203,7 @@ func (suite *MTOServiceItemServiceSuite) TestPriceEstimator() { }, }) - serviceArea := testdatagen.MakeReDomesticServiceArea(suite.DB(), + serviceArea := testdatagen.FetchOrMakeReDomesticServiceArea(suite.DB(), testdatagen.Assertions{ ReDomesticServiceArea: models.ReDomesticServiceArea{ Contract: contractYear.Contract, @@ -2221,13 +2229,17 @@ func (suite *MTOServiceItemServiceSuite) TestPriceEstimator() { PriceCents: unit.Cents(1234), } - serviceAreaPriceDPK := models.ReDomesticOtherPrice{ - ContractID: contractYear.Contract.ID, - ServiceID: reServiceCodeDPK.ID, - IsPeakPeriod: true, - Schedule: 1, - PriceCents: unit.Cents(121), - } + serviceAreaPriceDPK := factory.FetchOrMakeDomesticOtherPrice(suite.DB(), []factory.Customization{ + { + Model: models.ReDomesticOtherPrice{ + ContractID: contractYear.Contract.ID, + ServiceID: reServiceCodeDPK.ID, + IsPeakPeriod: true, + Schedule: 1, + PriceCents: unit.Cents(121), + }, + }, + }, nil) serviceAreaPriceDDP := models.ReDomesticServiceAreaPrice{ ContractID: contractYear.Contract.ID, @@ -2237,13 +2249,17 @@ func (suite *MTOServiceItemServiceSuite) TestPriceEstimator() { PriceCents: unit.Cents(482), } - serviceAreaPriceDUPK := models.ReDomesticOtherPrice{ - ContractID: contractYear.Contract.ID, - ServiceID: reServiceCodeDUPK.ID, - IsPeakPeriod: true, - Schedule: 1, - PriceCents: unit.Cents(945), - } + serviceAreaPriceDUPK := factory.FetchOrMakeDomesticOtherPrice(suite.DB(), []factory.Customization{ + { + Model: models.ReDomesticOtherPrice{ + ContractID: contractYear.Contract.ID, + ServiceID: reServiceCodeDUPK.ID, + IsPeakPeriod: true, + Schedule: 1, + PriceCents: unit.Cents(945), + }, + }, + }, nil) serviceAreaPriceDLH := models.ReDomesticLinehaulPrice{ ContractID: contractYear.Contract.ID, @@ -2264,7 +2280,7 @@ func (suite *MTOServiceItemServiceSuite) TestPriceEstimator() { PriceCents: unit.Cents(999), } - testdatagen.MakeGHCDieselFuelPrice(suite.DB(), testdatagen.Assertions{ + testdatagen.FetchOrMakeGHCDieselFuelPrice(suite.DB(), testdatagen.Assertions{ GHCDieselFuelPrice: models.GHCDieselFuelPrice{ FuelPriceInMillicents: unit.Millicents(281400), PublicationDate: time.Date(2020, time.March, 9, 0, 0, 0, 0, time.UTC), @@ -2280,7 +2296,7 @@ func (suite *MTOServiceItemServiceSuite) TestPriceEstimator() { suite.MustSave(&serviceAreaPriceDLH) suite.MustSave(&serviceAreaPriceDSH) - testdatagen.MakeReZip3(suite.DB(), testdatagen.Assertions{ + testdatagen.FetchOrMakeReZip3(suite.DB(), testdatagen.Assertions{ ReZip3: models.ReZip3{ Contract: contract, ContractID: contract.ID, @@ -2289,7 +2305,7 @@ func (suite *MTOServiceItemServiceSuite) TestPriceEstimator() { }, }) - testdatagen.MakeReZip3(suite.DB(), testdatagen.Assertions{ + testdatagen.FetchOrMakeReZip3(suite.DB(), testdatagen.Assertions{ ReZip3: models.ReZip3{ Contract: contract, ContractID: contract.ID, @@ -2400,29 +2416,29 @@ func (suite *MTOServiceItemServiceSuite) TestPriceEstimator() { mock.Anything, false, false, - ).Return(400, nil) + ).Return(800, nil) creator := NewMTOServiceItemCreator(planner, builder, moveRouter, ghcrateengine.NewDomesticUnpackPricer(), ghcrateengine.NewDomesticPackPricer(), ghcrateengine.NewDomesticLinehaulPricer(), ghcrateengine.NewDomesticShorthaulPricer(), ghcrateengine.NewDomesticOriginPricer(), ghcrateengine.NewDomesticDestinationPricer(), ghcrateengine.NewFuelSurchargePricer()) dopEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDOP, shipment) - suite.Equal(unit.Cents(91608), dopEstimatedPriceInCents) + suite.Equal(unit.Cents(67188), dopEstimatedPriceInCents) dpkEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDPK, shipment) - suite.Equal(unit.Cents(8976), dpkEstimatedPriceInCents) + suite.Equal(unit.Cents(594000), dpkEstimatedPriceInCents) ddpEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDDP, shipment) - suite.Equal(unit.Cents(35772), ddpEstimatedPriceInCents) + suite.Equal(unit.Cents(46464), ddpEstimatedPriceInCents) dupkEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDUPK, shipment) - suite.Equal(unit.Cents(70158), dupkEstimatedPriceInCents) + suite.Equal(unit.Cents(48246), dupkEstimatedPriceInCents) dlhEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDLH, shipment) - suite.Equal(unit.Cents(15840), dlhEstimatedPriceInCents) + suite.Equal(unit.Cents(29990400), dlhEstimatedPriceInCents) dshEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemDSH, shipment) - suite.Equal(unit.Cents(29673600), dshEstimatedPriceInCents) + suite.Equal(unit.Cents(22176000), dshEstimatedPriceInCents) fscEstimatedPriceInCents, _ := creator.FindEstimatedPrice(suite.AppContextForTest(), &serviceItemFSC, shipment) - suite.Equal(unit.Cents(786), fscEstimatedPriceInCents) + suite.Equal(unit.Cents(-335), fscEstimatedPriceInCents) }) } From 78581e2b452afcbe3553358ae72d243c5a5db78a Mon Sep 17 00:00:00 2001 From: Samay Sofo Date: Thu, 9 Jan 2025 15:18:39 +0000 Subject: [PATCH 14/21] 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 15/21] 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 16/21] 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 2c201cfc2a76fa49775b013fa96720db82265f8a Mon Sep 17 00:00:00 2001 From: Samay Sofo Date: Mon, 13 Jan 2025 14:42:13 +0000 Subject: [PATCH 17/21] fixed merge conflicts --- swagger/prime.yaml | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/swagger/prime.yaml b/swagger/prime.yaml index 46ba99df2e3..100c889a9b4 100644 --- a/swagger/prime.yaml +++ b/swagger/prime.yaml @@ -1082,33 +1082,6 @@ paths: - POEFSC (Port of Embarkation can be updated) - At a MINIMUM, the payload for updating the port should contain the - reServiceCode (PODFSC or POEFSC), modelType - (UpdateMTOServiceItemInternationalPortFSC), portCode, and id for the - service item. - - Please see the example payload below: - - ```json - - { - "id": "1ed224b6-c65e-4616-b88e-8304d26c9562", - "modelType": "UpdateMTOServiceItemInternationalPortFSC", - "portCode": "SEA", - "reServiceCode": "POEFSC" - } - - ``` - - - The following service items allow you to update the Port that the - shipment will use: - - - PODFSC (Port of Debarkation can be updated) - - - POEFSC (Port of Embarkation can be updated) - - At a MINIMUM, the payload for updating the port should contain the reServiceCode (PODFSC or POEFSC), modelType (UpdateMTOServiceItemInternationalPortFSC), portCode, and id for the From ec9946b34e5988de48c0dec917589abbac5ad9d3 Mon Sep 17 00:00:00 2001 From: Samay Sofo Date: Mon, 13 Jan 2025 17:10:21 +0000 Subject: [PATCH 18/21] 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 19/21] 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 ee4d8d9edc262fb9d46dbaf48461ec6b3c263918 Mon Sep 17 00:00:00 2001 From: Samay Sofo Date: Mon, 13 Jan 2025 20:25:32 +0000 Subject: [PATCH 20/21] reverted changes --- .../shipment_address_update_requester_test.go | 1 - 1 file changed, 1 deletion(-) 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 fcf28564aa0..bb74650deca 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 @@ -1679,7 +1679,6 @@ func (suite *ShipmentAddressUpdateServiceSuite) TestTOOApprovedShipmentAddressUp ).Return(2500, nil).Once() mockPlanner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"), - "90210", "94535", "94535", false, From 7ffa9b4244b79103197ddb80cf19c43a81f43fea Mon Sep 17 00:00:00 2001 From: Samay Sofo Date: Tue, 14 Jan 2025 21:27:46 +0000 Subject: [PATCH 21/21] fixed server tests --- pkg/services/mto_shipment/mto_shipment_updater_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/services/mto_shipment/mto_shipment_updater_test.go b/pkg/services/mto_shipment/mto_shipment_updater_test.go index a8bb0125f41..e56e58d08ef 100644 --- a/pkg/services/mto_shipment/mto_shipment_updater_test.go +++ b/pkg/services/mto_shipment/mto_shipment_updater_test.go @@ -3496,7 +3496,7 @@ func (suite *MTOShipmentServiceSuite) TestUpdateDomesticServiceItems() { } builder := query.NewQueryBuilder() - moveRouter := moveservices.NewMoveRouter() + moveRouter := moveservices.NewMoveRouter(transportationoffice.NewTransportationOfficesFetcher()) planner := &mocks.Planner{} planner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"),