From a89fca014da7183dbe35b8522a58721165a56750 Mon Sep 17 00:00:00 2001 From: loganwc Date: Tue, 29 Oct 2024 16:07:30 +0000 Subject: [PATCH 01/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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 0cb1e19eca018a31cb93b0ec3e4db35859056b78 Mon Sep 17 00:00:00 2001 From: loganwc Date: Wed, 8 Jan 2025 20:16:06 +0000 Subject: [PATCH 08/23] 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 09/23] 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 0841ec136ed38a12459a32bc1ec4e0b729865d99 Mon Sep 17 00:00:00 2001 From: joeydoyecaci Date: Fri, 10 Jan 2025 21:07:38 +0000 Subject: [PATCH 10/23] Update to allow shipment weight to update when TOO updates an estimated weight when there was already one added --- pkg/handlers/ghcapi/mto_shipment.go | 2 +- pkg/services/orchestrators/shipment/shipment_updater.go | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/handlers/ghcapi/mto_shipment.go b/pkg/handlers/ghcapi/mto_shipment.go index cfc4dbf5312..081556d0605 100644 --- a/pkg/handlers/ghcapi/mto_shipment.go +++ b/pkg/handlers/ghcapi/mto_shipment.go @@ -409,7 +409,7 @@ func (h UpdateShipmentHandler) Handle(params mtoshipmentops.UpdateMTOShipmentPar mtoShipment.PrimeEstimatedWeight = &previouslyRecordedWeight } - updatedMtoShipment, err := h.ShipmentUpdater.UpdateShipment(appCtx, mtoShipment, params.IfMatch, "ghc", nil) + updatedMtoShipment, err := h.ShipmentUpdater.UpdateShipment(appCtx, mtoShipment, params.IfMatch, "ghc", h.HandlerConfig.HHGPlanner()) if err != nil { return handleError(err) } diff --git a/pkg/services/orchestrators/shipment/shipment_updater.go b/pkg/services/orchestrators/shipment/shipment_updater.go index 53a20840e5e..e65aa023f80 100644 --- a/pkg/services/orchestrators/shipment/shipment_updater.go +++ b/pkg/services/orchestrators/shipment/shipment_updater.go @@ -56,10 +56,17 @@ func (s *shipmentUpdater) UpdateShipment(appCtx appcontext.AppContext, shipment } else { estimatedWeightToUse = *mtoShipment.PrimeEstimatedWeight } + estimatedWeightToUse = unit.Pound(estimatedWeightToUse.Float64() * 1.1) mtoShipment.MTOServiceItems[index].EstimatedWeight = &estimatedWeightToUse serviceItemEstimatedPrice, err := s.mtoServiceItemCreator.FindEstimatedPrice(appCtx, &serviceItem, *mtoShipment) + if serviceItemEstimatedPrice != 0 && err == nil { - mtoShipment.MTOServiceItems[index].PricingEstimate = &serviceItemEstimatedPrice + + priceResult := serviceItemEstimatedPrice + if mtoShipment.MTOServiceItems[index].PricingEstimate.Float64() > 0.0 { + priceResult = priceResult.MultiplyFloat64(1.1) + } + mtoShipment.MTOServiceItems[index].PricingEstimate = &priceResult } if err != nil { return err From 28d9700c13ccaef89a17e20b92910a137f1df32e Mon Sep 17 00:00:00 2001 From: joeydoyecaci Date: Mon, 13 Jan 2025 19:55:44 +0000 Subject: [PATCH 11/23] Broke out update shipment pricing addition into AddPricingEstimatesToMTOServiceItems. --- .../shipment/shipment_updater.go | 57 +++++++++++-------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/pkg/services/orchestrators/shipment/shipment_updater.go b/pkg/services/orchestrators/shipment/shipment_updater.go index e65aa023f80..d7ba3a7c4af 100644 --- a/pkg/services/orchestrators/shipment/shipment_updater.go +++ b/pkg/services/orchestrators/shipment/shipment_updater.go @@ -47,31 +47,10 @@ func (s *shipmentUpdater) UpdateShipment(appCtx appcontext.AppContext, shipment return err } - if mtoShipment != nil && planner != nil { - if mtoShipment.ShipmentType != models.MTOShipmentTypePPM && (shipment.PrimeEstimatedWeight != nil || mtoShipment.PrimeEstimatedWeight != nil) && mtoShipment.Status == models.MTOShipmentStatusApproved { - for index, serviceItem := range mtoShipment.MTOServiceItems { - var estimatedWeightToUse unit.Pound - if shipment.PrimeEstimatedWeight != nil { - estimatedWeightToUse = *shipment.PrimeEstimatedWeight - } else { - estimatedWeightToUse = *mtoShipment.PrimeEstimatedWeight - } - estimatedWeightToUse = unit.Pound(estimatedWeightToUse.Float64() * 1.1) - mtoShipment.MTOServiceItems[index].EstimatedWeight = &estimatedWeightToUse - serviceItemEstimatedPrice, err := s.mtoServiceItemCreator.FindEstimatedPrice(appCtx, &serviceItem, *mtoShipment) - - if serviceItemEstimatedPrice != 0 && err == nil { - - priceResult := serviceItemEstimatedPrice - if mtoShipment.MTOServiceItems[index].PricingEstimate.Float64() > 0.0 { - priceResult = priceResult.MultiplyFloat64(1.1) - } - mtoShipment.MTOServiceItems[index].PricingEstimate = &priceResult - } - if err != nil { - return err - } - } + if mtoShipment != nil && (mtoShipment.ShipmentType != models.MTOShipmentTypePPM) && (shipment.PrimeEstimatedWeight != nil || mtoShipment.PrimeEstimatedWeight != nil) && mtoShipment.Status == models.MTOShipmentStatusApproved { + mtoShipment, err = AddPricingEstimatesToMTOServiceItems(appCtx, *s, mtoShipment, shipment) + if err != nil { + return err } } @@ -161,3 +140,31 @@ func (s *shipmentUpdater) UpdateShipment(appCtx appcontext.AppContext, shipment return mtoShipment, nil } + +func AddPricingEstimatesToMTOServiceItems(appCtx appcontext.AppContext, shipmentUpdater shipmentUpdater, mtoShipment *models.MTOShipment, shipmentDelta *models.MTOShipment) (*models.MTOShipment, error) { + mtoShipmentCopy := mtoShipment + + for index, serviceItem := range mtoShipmentCopy.MTOServiceItems { + var estimatedWeightToUse unit.Pound + if shipmentDelta.PrimeEstimatedWeight != nil { + estimatedWeightToUse = *shipmentDelta.PrimeEstimatedWeight + } else { + estimatedWeightToUse = *mtoShipmentCopy.PrimeEstimatedWeight + } + estimatedWeightToUse = unit.Pound(estimatedWeightToUse.Float64() * 1.1) + mtoShipmentCopy.MTOServiceItems[index].EstimatedWeight = &estimatedWeightToUse + serviceItemEstimatedPrice, err := shipmentUpdater.mtoServiceItemCreator.FindEstimatedPrice(appCtx, &serviceItem, *mtoShipment) + + if serviceItemEstimatedPrice != 0 && err == nil { + + // multiply price by 110% of estimated weight + priceResult := serviceItemEstimatedPrice.MultiplyFloat64(1.1) + + mtoShipmentCopy.MTOServiceItems[index].PricingEstimate = &priceResult + } + if err != nil { + return mtoShipmentCopy, err + } + } + return mtoShipmentCopy, nil +} From 22434b6124a4ac88c9adedc3c995005b7fc2f88f Mon Sep 17 00:00:00 2001 From: joeydoyecaci Date: Tue, 14 Jan 2025 21:04:24 +0000 Subject: [PATCH 12/23] Removed counseling-flows unrelated changes --- .../servicesCounselingFlows.spec.js | 2 -- .../AddOrdersForm/AddOrdersForm.test.jsx | 21 ------------------- 2 files changed, 23 deletions(-) diff --git a/playwright/tests/office/servicescounseling/servicesCounselingFlows.spec.js b/playwright/tests/office/servicescounseling/servicesCounselingFlows.spec.js index 5d8736e16e9..16db36fbc3c 100644 --- a/playwright/tests/office/servicescounseling/servicesCounselingFlows.spec.js +++ b/playwright/tests/office/servicescounseling/servicesCounselingFlows.spec.js @@ -323,8 +323,6 @@ test.describe('Services counselor user', () => { await expect(page.getByText(LocationLookup, { exact: true })).toBeVisible(); await page.keyboard.press('Enter'); await page.locator('select[name="destinationType"]').selectOption({ label: 'Home of selection (HOS)' }); - await page.getByLabel('Requested pickup date').fill('16 Mar 2022'); - await page.locator('[data-testid="submitForm"]').click(); await scPage.waitForLoading(); diff --git a/src/components/Office/AddOrdersForm/AddOrdersForm.test.jsx b/src/components/Office/AddOrdersForm/AddOrdersForm.test.jsx index 7fe7c5bc413..f721c689e7c 100644 --- a/src/components/Office/AddOrdersForm/AddOrdersForm.test.jsx +++ b/src/components/Office/AddOrdersForm/AddOrdersForm.test.jsx @@ -261,27 +261,6 @@ describe('AddOrdersForm - OCONUS and Accompanied Tour Test', () => { }); }); -describe('AddOrdersForm - Edge Cases and Additional Scenarios', () => { - it('disables orders type when safety move is selected', async () => { - render( - - - , - ); - - expect(screen.getByLabelText('Orders type')).toBeDisabled(); - }); - - it('disables orders type when bluebark move is selected', async () => { - render( - - - , - ); - expect(screen.getByLabelText('Orders type')).toBeDisabled(); - }); -}); - describe('AddOrdersForm - Student Travel, Early Return of Dependents Test', () => { it('has dependents is yes and disabled when order type is student travel', async () => { isBooleanFlagEnabled.mockImplementation(() => Promise.resolve(true)); From 787068f00b2c9e8d22bce46a11630557a5b243bd Mon Sep 17 00:00:00 2001 From: joeydoyecaci Date: Tue, 14 Jan 2025 22:19:06 +0000 Subject: [PATCH 13/23] Removed AddOrders unrelated changes 2 --- .../AddOrdersForm/AddOrdersForm.test.jsx | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/src/components/Office/AddOrdersForm/AddOrdersForm.test.jsx b/src/components/Office/AddOrdersForm/AddOrdersForm.test.jsx index 46312ff387a..99e3b6bb260 100644 --- a/src/components/Office/AddOrdersForm/AddOrdersForm.test.jsx +++ b/src/components/Office/AddOrdersForm/AddOrdersForm.test.jsx @@ -432,23 +432,3 @@ describe('AddOrdersForm - With Counseling Office', () => { expect(nextBtn.getAttribute('disabled')).toBeFalsy(); }); }); -describe('AddOrdersForm - Edge Cases and Additional Scenarios', () => { - it('disables orders type when safety move is selected', async () => { - render( - - - , - ); - - expect(screen.getByLabelText('Orders type')).toBeDisabled(); - }); - - it('disables orders type when bluebark move is selected', async () => { - render( - - - , - ); - expect(screen.getByLabelText('Orders type')).toBeDisabled(); - }); -}); From 733c346e1d87f895e52d76af9967ed6837a36863 Mon Sep 17 00:00:00 2001 From: joeydoyecaci Date: Wed, 15 Jan 2025 01:49:07 +0000 Subject: [PATCH 14/23] Added back test case --- .../AddOrdersForm/AddOrdersForm.test.jsx | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/components/Office/AddOrdersForm/AddOrdersForm.test.jsx b/src/components/Office/AddOrdersForm/AddOrdersForm.test.jsx index 99e3b6bb260..22df7c03b96 100644 --- a/src/components/Office/AddOrdersForm/AddOrdersForm.test.jsx +++ b/src/components/Office/AddOrdersForm/AddOrdersForm.test.jsx @@ -261,6 +261,27 @@ describe('AddOrdersForm - OCONUS and Accompanied Tour Test', () => { }); }); +describe('AddOrdersForm - Edge Cases and Additional Scenarios', () => { + it('disables orders type when safety move is selected', async () => { + render( + + + , + ); + + expect(screen.getByLabelText('Orders type')).toBeDisabled(); + }); + + it('disables orders type when bluebark move is selected', async () => { + render( + + + , + ); + expect(screen.getByLabelText('Orders type')).toBeDisabled(); + }); +}); + describe('AddOrdersForm - Student Travel, Early Return of Dependents Test', () => { it('has dependents is yes and disabled when order type is student travel', async () => { isBooleanFlagEnabled.mockImplementation(() => Promise.resolve(true)); From 172c643274be4424399e7310803517e7f122f642 Mon Sep 17 00:00:00 2001 From: joeydoyecaci Date: Thu, 16 Jan 2025 01:31:05 +0000 Subject: [PATCH 15/23] Removed Planner, removed price result --- pkg/handlers/ghcapi/mto_service_items.go | 4 ++-- pkg/handlers/ghcapi/mto_shipment.go | 6 +++--- pkg/handlers/internalapi/mto_shipment.go | 2 +- pkg/handlers/primeapiv2/mto_shipment.go | 2 +- pkg/handlers/primeapiv3/mto_shipment.go | 2 +- pkg/services/mocks/ShipmentUpdater.go | 20 +++++++++---------- .../shipment/shipment_updater.go | 9 ++------- .../shipment/shipment_updater_test.go | 12 +++++------ pkg/services/shipment_orchestrator.go | 3 +-- 9 files changed, 26 insertions(+), 34 deletions(-) diff --git a/pkg/handlers/ghcapi/mto_service_items.go b/pkg/handlers/ghcapi/mto_service_items.go index 35b390c3eec..60b8db84c04 100644 --- a/pkg/handlers/ghcapi/mto_service_items.go +++ b/pkg/handlers/ghcapi/mto_service_items.go @@ -153,7 +153,7 @@ func (h UpdateServiceItemSitEntryDateHandler) Handle(params mtoserviceitemop.Upd existingETag := etag.GenerateEtag(shipment.UpdatedAt) - shipment, err = h.UpdateShipment(appCtx, &shipmentWithSITInfo, existingETag, "ghc", nil) + shipment, err = h.UpdateShipment(appCtx, &shipmentWithSITInfo, existingETag, "ghc") if err != nil { appCtx.Logger().Error(fmt.Sprintf("Could not update the shipment SIT auth end date for shipment ID: %s: %s", shipment.ID, err)) } @@ -266,7 +266,7 @@ func (h UpdateMTOServiceItemStatusHandler) Handle(params mtoserviceitemop.Update existingETag := etag.GenerateEtag(shipment.UpdatedAt) - shipment, err = h.UpdateShipment(appCtx, &shipmentWithSITInfo, existingETag, "ghc", nil) + shipment, err = h.UpdateShipment(appCtx, &shipmentWithSITInfo, existingETag, "ghc") if err != nil { appCtx.Logger().Error(fmt.Sprintf("Could not update the shipment SIT auth end date for shipment ID: %s: %s", shipment.ID, err)) } diff --git a/pkg/handlers/ghcapi/mto_shipment.go b/pkg/handlers/ghcapi/mto_shipment.go index 081556d0605..0ab30d6ed1a 100644 --- a/pkg/handlers/ghcapi/mto_shipment.go +++ b/pkg/handlers/ghcapi/mto_shipment.go @@ -409,7 +409,7 @@ func (h UpdateShipmentHandler) Handle(params mtoshipmentops.UpdateMTOShipmentPar mtoShipment.PrimeEstimatedWeight = &previouslyRecordedWeight } - updatedMtoShipment, err := h.ShipmentUpdater.UpdateShipment(appCtx, mtoShipment, params.IfMatch, "ghc", h.HandlerConfig.HHGPlanner()) + updatedMtoShipment, err := h.ShipmentUpdater.UpdateShipment(appCtx, mtoShipment, params.IfMatch, "ghc") if err != nil { return handleError(err) } @@ -1124,7 +1124,7 @@ func (h ApproveSITExtensionHandler) Handle(params shipmentops.ApproveSITExtensio existingETag := etag.GenerateEtag(updatedShipment.UpdatedAt) - updatedShipment, err = h.UpdateShipment(appCtx, &shipmentWithSITInfo, existingETag, "ghc", nil) + updatedShipment, err = h.UpdateShipment(appCtx, &shipmentWithSITInfo, existingETag, "ghc") if err != nil { return handleError(err) } @@ -1371,7 +1371,7 @@ func (h CreateApprovedSITDurationUpdateHandler) Handle(params shipmentops.Create existingETag := etag.GenerateEtag(shipment.UpdatedAt) - shipment, err = h.UpdateShipment(appCtx, &shipmentWithSITInfo, existingETag, "ghc", nil) + shipment, err = h.UpdateShipment(appCtx, &shipmentWithSITInfo, existingETag, "ghc") if err != nil { return handleError(err) } diff --git a/pkg/handlers/internalapi/mto_shipment.go b/pkg/handlers/internalapi/mto_shipment.go index 5b401190232..dc23374a6af 100644 --- a/pkg/handlers/internalapi/mto_shipment.go +++ b/pkg/handlers/internalapi/mto_shipment.go @@ -169,7 +169,7 @@ func (h UpdateMTOShipmentHandler) Handle(params mtoshipmentops.UpdateMTOShipment h.GetTraceIDFromRequest(params.HTTPRequest))), invalidShipmentStatusErr } - updatedMTOShipment, err := h.shipmentUpdater.UpdateShipment(appCtx, mtoShipment, params.IfMatch, "internal", nil) + updatedMTOShipment, err := h.shipmentUpdater.UpdateShipment(appCtx, mtoShipment, params.IfMatch, "internal") if err != nil { appCtx.Logger().Error("internalapi.UpdateMTOShipmentHandler", zap.Error(err)) diff --git a/pkg/handlers/primeapiv2/mto_shipment.go b/pkg/handlers/primeapiv2/mto_shipment.go index e4f2c41748a..d4a5e5012da 100644 --- a/pkg/handlers/primeapiv2/mto_shipment.go +++ b/pkg/handlers/primeapiv2/mto_shipment.go @@ -204,7 +204,7 @@ func (h UpdateMTOShipmentHandler) Handle(params mtoshipmentops.UpdateMTOShipment mtoShipment.ShipmentType = dbShipment.ShipmentType appCtx.Logger().Info("primeapi.UpdateMTOShipmentHandler info", zap.String("pointOfContact", params.Body.PointOfContact)) - mtoShipment, err = h.ShipmentUpdater.UpdateShipment(appCtx, mtoShipment, params.IfMatch, "prime-v2", h.planner) + mtoShipment, err = h.ShipmentUpdater.UpdateShipment(appCtx, mtoShipment, params.IfMatch, "prime-v2") if err != nil { appCtx.Logger().Error("primeapi.UpdateMTOShipmentHandler error", zap.Error(err)) switch e := err.(type) { diff --git a/pkg/handlers/primeapiv3/mto_shipment.go b/pkg/handlers/primeapiv3/mto_shipment.go index aa8476f6267..d2f6221ac9f 100644 --- a/pkg/handlers/primeapiv3/mto_shipment.go +++ b/pkg/handlers/primeapiv3/mto_shipment.go @@ -207,7 +207,7 @@ func (h UpdateMTOShipmentHandler) Handle(params mtoshipmentops.UpdateMTOShipment mtoShipment.ShipmentType = dbShipment.ShipmentType appCtx.Logger().Info("primeapi.UpdateMTOShipmentHandler info", zap.String("pointOfContact", params.Body.PointOfContact)) - mtoShipment, err = h.ShipmentUpdater.UpdateShipment(appCtx, mtoShipment, params.IfMatch, "prime-v3", h.planner) + mtoShipment, err = h.ShipmentUpdater.UpdateShipment(appCtx, mtoShipment, params.IfMatch, "prime-v3") if err != nil { appCtx.Logger().Error("primeapi.UpdateMTOShipmentHandler error", zap.Error(err)) switch e := err.(type) { diff --git a/pkg/services/mocks/ShipmentUpdater.go b/pkg/services/mocks/ShipmentUpdater.go index 83e0f17d197..94bc241b543 100644 --- a/pkg/services/mocks/ShipmentUpdater.go +++ b/pkg/services/mocks/ShipmentUpdater.go @@ -7,8 +7,6 @@ import ( appcontext "github.com/transcom/mymove/pkg/appcontext" models "github.com/transcom/mymove/pkg/models" - - route "github.com/transcom/mymove/pkg/route" ) // ShipmentUpdater is an autogenerated mock type for the ShipmentUpdater type @@ -16,9 +14,9 @@ type ShipmentUpdater struct { mock.Mock } -// UpdateShipment provides a mock function with given fields: appCtx, shipment, eTag, api, planner -func (_m *ShipmentUpdater) UpdateShipment(appCtx appcontext.AppContext, shipment *models.MTOShipment, eTag string, api string, planner route.Planner) (*models.MTOShipment, error) { - ret := _m.Called(appCtx, shipment, eTag, api, planner) +// UpdateShipment provides a mock function with given fields: appCtx, shipment, eTag, api +func (_m *ShipmentUpdater) UpdateShipment(appCtx appcontext.AppContext, shipment *models.MTOShipment, eTag string, api string) (*models.MTOShipment, error) { + ret := _m.Called(appCtx, shipment, eTag, api) if len(ret) == 0 { panic("no return value specified for UpdateShipment") @@ -26,19 +24,19 @@ func (_m *ShipmentUpdater) UpdateShipment(appCtx appcontext.AppContext, shipment var r0 *models.MTOShipment var r1 error - if rf, ok := ret.Get(0).(func(appcontext.AppContext, *models.MTOShipment, string, string, route.Planner) (*models.MTOShipment, error)); ok { - return rf(appCtx, shipment, eTag, api, planner) + if rf, ok := ret.Get(0).(func(appcontext.AppContext, *models.MTOShipment, string, string) (*models.MTOShipment, error)); ok { + return rf(appCtx, shipment, eTag, api) } - if rf, ok := ret.Get(0).(func(appcontext.AppContext, *models.MTOShipment, string, string, route.Planner) *models.MTOShipment); ok { - r0 = rf(appCtx, shipment, eTag, api, planner) + if rf, ok := ret.Get(0).(func(appcontext.AppContext, *models.MTOShipment, string, string) *models.MTOShipment); ok { + r0 = rf(appCtx, shipment, eTag, api) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*models.MTOShipment) } } - if rf, ok := ret.Get(1).(func(appcontext.AppContext, *models.MTOShipment, string, string, route.Planner) error); ok { - r1 = rf(appCtx, shipment, eTag, api, planner) + if rf, ok := ret.Get(1).(func(appcontext.AppContext, *models.MTOShipment, string, string) error); ok { + r1 = rf(appCtx, shipment, eTag, api) } else { r1 = ret.Error(1) } diff --git a/pkg/services/orchestrators/shipment/shipment_updater.go b/pkg/services/orchestrators/shipment/shipment_updater.go index d7ba3a7c4af..bf7fb5b67bd 100644 --- a/pkg/services/orchestrators/shipment/shipment_updater.go +++ b/pkg/services/orchestrators/shipment/shipment_updater.go @@ -5,7 +5,6 @@ import ( "github.com/transcom/mymove/pkg/appcontext" "github.com/transcom/mymove/pkg/models" - "github.com/transcom/mymove/pkg/route" "github.com/transcom/mymove/pkg/services" "github.com/transcom/mymove/pkg/unit" ) @@ -33,7 +32,7 @@ func NewShipmentUpdater(mtoShipmentUpdater services.MTOShipmentUpdater, ppmShipm } // UpdateShipment updates a shipment, taking into account different shipment types and their needs. -func (s *shipmentUpdater) UpdateShipment(appCtx appcontext.AppContext, shipment *models.MTOShipment, eTag string, api string, planner route.Planner) (*models.MTOShipment, error) { +func (s *shipmentUpdater) UpdateShipment(appCtx appcontext.AppContext, shipment *models.MTOShipment, eTag string, api string) (*models.MTOShipment, error) { if err := validateShipment(appCtx, *shipment, s.checks...); err != nil { return nil, err } @@ -156,11 +155,7 @@ func AddPricingEstimatesToMTOServiceItems(appCtx appcontext.AppContext, shipment serviceItemEstimatedPrice, err := shipmentUpdater.mtoServiceItemCreator.FindEstimatedPrice(appCtx, &serviceItem, *mtoShipment) if serviceItemEstimatedPrice != 0 && err == nil { - - // multiply price by 110% of estimated weight - priceResult := serviceItemEstimatedPrice.MultiplyFloat64(1.1) - - mtoShipmentCopy.MTOServiceItems[index].PricingEstimate = &priceResult + mtoShipmentCopy.MTOServiceItems[index].PricingEstimate = &serviceItemEstimatedPrice } if err != nil { return mtoShipmentCopy, err diff --git a/pkg/services/orchestrators/shipment/shipment_updater_test.go b/pkg/services/orchestrators/shipment/shipment_updater_test.go index bc42dc4ed5e..9f36fcd2650 100644 --- a/pkg/services/orchestrators/shipment/shipment_updater_test.go +++ b/pkg/services/orchestrators/shipment/shipment_updater_test.go @@ -197,7 +197,7 @@ func (suite *ShipmentSuite) TestUpdateShipment() { // Set invalid data, can't pass in blank to the generator above (it'll default to HHG if blank) so we're setting it afterward. shipment.ShipmentType = "" - updatedShipment, err := subtestData.shipmentUpdaterOrchestrator.UpdateShipment(appCtx, &shipment, etag.GenerateEtag(shipment.UpdatedAt), "test", nil) + updatedShipment, err := subtestData.shipmentUpdaterOrchestrator.UpdateShipment(appCtx, &shipment, etag.GenerateEtag(shipment.UpdatedAt), "test") suite.Nil(updatedShipment) @@ -245,7 +245,7 @@ func (suite *ShipmentSuite) TestUpdateShipment() { // Need to start a transaction so we can assert the call with the correct appCtx err := appCtx.NewTransaction(func(txAppCtx appcontext.AppContext) error { - mtoShipment, err := subtestData.shipmentUpdaterOrchestrator.UpdateShipment(txAppCtx, &shipment, eTag, "test", nil) + mtoShipment, err := subtestData.shipmentUpdaterOrchestrator.UpdateShipment(txAppCtx, &shipment, eTag, "test") suite.NoError(err) suite.NotNil(mtoShipment) @@ -308,7 +308,7 @@ func (suite *ShipmentSuite) TestUpdateShipment() { shipment.PPMShipment.AdvanceAmountReceived = models.CentPointer(unit.Cents(55000)) shipment.PPMShipment.HasReceivedAdvance = models.BoolPointer(true) - mtoShipment, err := subtestData.shipmentUpdaterOrchestrator.UpdateShipment(appCtx, &shipment, etag.GenerateEtag(shipment.UpdatedAt), "test", nil) + mtoShipment, err := subtestData.shipmentUpdaterOrchestrator.UpdateShipment(appCtx, &shipment, etag.GenerateEtag(shipment.UpdatedAt), "test") suite.NoError(err) suite.NotNil(mtoShipment) @@ -347,7 +347,7 @@ func (suite *ShipmentSuite) TestUpdateShipment() { shipment.BoatShipment.LengthInInches = models.IntPointer(20) shipment.BoatShipment.HasTrailer = models.BoolPointer(false) - mtoShipment, err := subtestData.shipmentUpdaterOrchestrator.UpdateShipment(appCtx, &shipment, etag.GenerateEtag(shipment.UpdatedAt), "test", nil) + mtoShipment, err := subtestData.shipmentUpdaterOrchestrator.UpdateShipment(appCtx, &shipment, etag.GenerateEtag(shipment.UpdatedAt), "test") suite.NoError(err) @@ -426,7 +426,7 @@ func (suite *ShipmentSuite) TestUpdateShipment() { }, nil) } - mtoShipment, err := subtestData.shipmentUpdaterOrchestrator.UpdateShipment(appCtx, &shipment, etag.GenerateEtag(shipment.UpdatedAt), "test", nil) + mtoShipment, err := subtestData.shipmentUpdaterOrchestrator.UpdateShipment(appCtx, &shipment, etag.GenerateEtag(shipment.UpdatedAt), "test") suite.Nil(mtoShipment) @@ -450,7 +450,7 @@ func (suite *ShipmentSuite) TestUpdateShipment() { eTag := etag.GenerateEtag(shipment.UpdatedAt) - mtoShipment, err := subtestData.shipmentUpdaterOrchestrator.UpdateShipment(appCtx, &shipment, eTag, "test", nil) + mtoShipment, err := subtestData.shipmentUpdaterOrchestrator.UpdateShipment(appCtx, &shipment, eTag, "test") suite.Nil(mtoShipment) diff --git a/pkg/services/shipment_orchestrator.go b/pkg/services/shipment_orchestrator.go index cef3a0c405a..69168e8f997 100644 --- a/pkg/services/shipment_orchestrator.go +++ b/pkg/services/shipment_orchestrator.go @@ -3,7 +3,6 @@ package services import ( "github.com/transcom/mymove/pkg/appcontext" "github.com/transcom/mymove/pkg/models" - "github.com/transcom/mymove/pkg/route" ) // ShipmentCreator creates a shipment, taking into account different shipment types and their needs. @@ -17,5 +16,5 @@ type ShipmentCreator interface { // //go:generate mockery --name ShipmentUpdater type ShipmentUpdater interface { - UpdateShipment(appCtx appcontext.AppContext, shipment *models.MTOShipment, eTag string, api string, planner route.Planner) (*models.MTOShipment, error) + UpdateShipment(appCtx appcontext.AppContext, shipment *models.MTOShipment, eTag string, api string) (*models.MTOShipment, error) } From 40a6626e6f1d39bd9b398d2319b2fd5ecd63db59 Mon Sep 17 00:00:00 2001 From: joeydoyecaci Date: Fri, 17 Jan 2025 05:57:58 +0000 Subject: [PATCH 16/23] Added unit test, fixed mock setups containing unused parameters --- pkg/handlers/ghcapi/mto_shipment_test.go | 1 - pkg/handlers/internalapi/mto_shipment_test.go | 1 - .../shipment/shipment_updater.go | 9 +- .../shipment/shipment_updater_test.go | 155 ++++++++++++++++++ 4 files changed, 163 insertions(+), 3 deletions(-) diff --git a/pkg/handlers/ghcapi/mto_shipment_test.go b/pkg/handlers/ghcapi/mto_shipment_test.go index a29e60c572c..9432dae0cad 100644 --- a/pkg/handlers/ghcapi/mto_shipment_test.go +++ b/pkg/handlers/ghcapi/mto_shipment_test.go @@ -4665,7 +4665,6 @@ func (suite *HandlerSuite) TestUpdateShipmentHandler() { mock.Anything, mock.Anything, mock.Anything, - nil, ).Return(nil, err) oldShipment := factory.BuildMTOShipment(suite.DB(), []factory.Customization{ diff --git a/pkg/handlers/internalapi/mto_shipment_test.go b/pkg/handlers/internalapi/mto_shipment_test.go index 3d971cc6a38..af56182d93b 100644 --- a/pkg/handlers/internalapi/mto_shipment_test.go +++ b/pkg/handlers/internalapi/mto_shipment_test.go @@ -1486,7 +1486,6 @@ func (suite *HandlerSuite) TestUpdateMTOShipmentHandler() { mock.AnythingOfType("*models.MTOShipment"), mock.AnythingOfType("string"), mock.AnythingOfType("string"), - nil, ).Return(nil, err) subtestData := getDefaultMTOShipmentAndParams(&mockUpdater) diff --git a/pkg/services/orchestrators/shipment/shipment_updater.go b/pkg/services/orchestrators/shipment/shipment_updater.go index bf7fb5b67bd..d624d33136f 100644 --- a/pkg/services/orchestrators/shipment/shipment_updater.go +++ b/pkg/services/orchestrators/shipment/shipment_updater.go @@ -150,10 +150,17 @@ func AddPricingEstimatesToMTOServiceItems(appCtx appcontext.AppContext, shipment } else { estimatedWeightToUse = *mtoShipmentCopy.PrimeEstimatedWeight } - estimatedWeightToUse = unit.Pound(estimatedWeightToUse.Float64() * 1.1) + originalWeight := estimatedWeightToUse + + // set weight to be modified mtoShipmentCopy.MTOServiceItems[index].EstimatedWeight = &estimatedWeightToUse + + //Calculate the price using 110% of recorded weight + estimatedWeightToUse = unit.Pound(estimatedWeightToUse.Float64() * 1.1) serviceItemEstimatedPrice, err := shipmentUpdater.mtoServiceItemCreator.FindEstimatedPrice(appCtx, &serviceItem, *mtoShipment) + // store actual captured weight + mtoShipmentCopy.MTOServiceItems[index].EstimatedWeight = &originalWeight if serviceItemEstimatedPrice != 0 && err == nil { mtoShipmentCopy.MTOServiceItems[index].PricingEstimate = &serviceItemEstimatedPrice } diff --git a/pkg/services/orchestrators/shipment/shipment_updater_test.go b/pkg/services/orchestrators/shipment/shipment_updater_test.go index 9f36fcd2650..2eaf1fb6cb4 100644 --- a/pkg/services/orchestrators/shipment/shipment_updater_test.go +++ b/pkg/services/orchestrators/shipment/shipment_updater_test.go @@ -2,6 +2,7 @@ package shipment import ( "fmt" + "time" "github.com/gofrs/uuid" "github.com/stretchr/testify/mock" @@ -18,6 +19,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" + "github.com/transcom/mymove/pkg/testdatagen" "github.com/transcom/mymove/pkg/unit" ) @@ -33,6 +35,7 @@ func (suite *ShipmentSuite) TestUpdateShipment() { type subtestDataObjects struct { mockMTOShipmentUpdater *mocks.MTOShipmentUpdater + mockMtoServiceItemCreator *mocks.MTOServiceItemCreator mockPPMShipmentUpdater *mocks.PPMShipmentUpdater mockBoatShipmentUpdater *mocks.BoatShipmentUpdater mockMobileHomeShipmentUpdater *mocks.MobileHomeShipmentUpdater @@ -50,6 +53,9 @@ func (suite *ShipmentSuite) TestUpdateShipment() { mockMTOShipmentUpdater := mocks.MTOShipmentUpdater{} subtestData.mockMTOShipmentUpdater = &mockMTOShipmentUpdater + mockMtoServiceItemCreator := mocks.MTOServiceItemCreator{} + subtestData.mockMtoServiceItemCreator = &mockMtoServiceItemCreator + mockPPMShipmentUpdater := mocks.PPMShipmentUpdater{} subtestData.mockPPMShipmentUpdater = &mockPPMShipmentUpdater @@ -186,6 +192,26 @@ func (suite *ShipmentSuite) TestUpdateShipment() { return subtestData } + makeServiceItemSubtestData := func() (subtestData subtestDataObjects) { + mockMTOShipmentUpdater := mocks.MTOShipmentUpdater{} + subtestData.mockMTOShipmentUpdater = &mockMTOShipmentUpdater + + mockMtoServiceItemCreator := mocks.MTOServiceItemCreator{} + subtestData.mockMtoServiceItemCreator = &mockMtoServiceItemCreator + + mockPPMShipmentUpdater := mocks.PPMShipmentUpdater{} + subtestData.mockPPMShipmentUpdater = &mockPPMShipmentUpdater + + mockBoatShipmentUpdater := mocks.BoatShipmentUpdater{} + subtestData.mockBoatShipmentUpdater = &mockBoatShipmentUpdater + + mockMobileHomeShipmentUpdater := mocks.MobileHomeShipmentUpdater{} + subtestData.mockMobileHomeShipmentUpdater = &mockMobileHomeShipmentUpdater + + subtestData.shipmentUpdaterOrchestrator = NewShipmentUpdater(subtestData.mockMTOShipmentUpdater, subtestData.mockPPMShipmentUpdater, subtestData.mockBoatShipmentUpdater, subtestData.mockMobileHomeShipmentUpdater, subtestData.mockMtoServiceItemCreator) + + return subtestData + } suite.Run("Returns an InvalidInputError if there is an error with the shipment info that was input", func() { appCtx := suite.AppContextForTest() @@ -474,4 +500,133 @@ func (suite *ShipmentSuite) TestUpdateShipment() { mock.AnythingOfType("uuid.UUID"), ) }) + + suite.Run("Updating weight will update the estimated price of service items", func() { + appCtx := suite.AppContextForTest() + + subtestData := makeServiceItemSubtestData() + + estimatedWeight := unit.Pound(2000) + pickupAddress := factory.BuildAddress(suite.DB(), nil, []factory.Trait{factory.GetTraitAddress2}) + deliveryAddress := factory.BuildAddress(suite.DB(), nil, []factory.Trait{factory.GetTraitAddress3}) + + shipment := factory.BuildMTOShipment(appCtx.DB(), []factory.Customization{ + { + Model: models.MTOShipment{ + ID: uuid.Must(uuid.FromString("a5e95c1d-97c3-4f79-8097-c12dd2557ac7")), + Status: models.MTOShipmentStatusApproved, + ShipmentType: models.MTOShipmentTypeHHG, + PrimeEstimatedWeight: &estimatedWeight, + }, + }, + { + Model: pickupAddress, + LinkOnly: true, + Type: &factory.Addresses.PickupAddress, + }, + { + Model: deliveryAddress, + LinkOnly: true, + Type: &factory.Addresses.DeliveryAddress, + }, + }, nil) + + reServiceCodeFSC := factory.FetchReServiceByCode(suite.DB(), models.ReServiceCodeFSC) + + startDate := time.Now().AddDate(-1, 0, 0) + endDate := startDate.AddDate(1, 1, 1) + reason := "lorem ipsum" + + testdatagen.FetchOrMakeReContract(suite.DB(), testdatagen.Assertions{}) + testdatagen.FetchOrMakeReContractYear(suite.DB(), + testdatagen.Assertions{ + ReContractYear: models.ReContractYear{ + Name: "Test Contract Year", + EscalationCompounded: 1.125, + StartDate: startDate, + EndDate: endDate, + }, + }) + + 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), + 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), + }, + }) + + actualPickupAddress := factory.BuildAddress(suite.DB(), nil, []factory.Trait{factory.GetTraitAddress2}) + requestedPickupDate := time.Date(2020, time.October, 24, 0, 0, 0, 0, time.UTC) + + serviceItemFSC := models.MTOServiceItem{ + MoveTaskOrder: shipment.MoveTaskOrder, + MoveTaskOrderID: shipment.MoveTaskOrderID, + MTOShipment: shipment, + MTOShipmentID: &shipment.ID, + ReService: reServiceCodeFSC, + Reason: &reason, + SITOriginHHGActualAddress: &actualPickupAddress, + Status: models.MTOServiceItemStatusSubmitted, + } + + shipment.MTOServiceItems = append(shipment.MTOServiceItems, serviceItemFSC) + suite.MustSave(&shipment) + + eTag := etag.GenerateEtag(shipment.UpdatedAt) + + subtestData.mockMtoServiceItemCreator.On("ZipTransitDistance", + mock.AnythingOfType("*appcontext.appContext"), + mock.Anything, + mock.Anything, + false, + false, + ).Return(800, nil) + + returnCents := unit.Cents(123) + + subtestData.mockMtoServiceItemCreator.On("FindEstimatedPrice", + mock.AnythingOfType("*appcontext.appContext"), + mock.Anything, + mock.Anything, + mock.Anything, + ).Return(returnCents, nil) + + subtestData.mockMTOShipmentUpdater. + On( + updateMTOShipmentMethodName, + mock.AnythingOfType("*appcontext.appContext"), + mock.AnythingOfType("*models.MTOShipment"), + mock.AnythingOfType("string"), + mock.AnythingOfType("string")). + Return( + &models.MTOShipment{ + ID: uuid.Must(uuid.FromString("a5e95c1d-97c3-4f79-8097-c12dd2557ac7")), + Status: models.MTOShipmentStatusApproved, + ShipmentType: models.MTOShipmentTypeHHG, + PrimeEstimatedWeight: &estimatedWeight, + RequestedPickupDate: &requestedPickupDate, + MTOServiceItems: models.MTOServiceItems{serviceItemFSC}, + PickupAddress: &pickupAddress, + DestinationAddress: &deliveryAddress, + }, nil) + + // Need to start a transaction so we can assert the call with the correct appCtx + err := appCtx.NewTransaction(func(txAppCtx appcontext.AppContext) error { + mtoShipment, err := subtestData.shipmentUpdaterOrchestrator.UpdateShipment(txAppCtx, &shipment, eTag, "test") + + suite.NoError(err) + suite.NotNil(mtoShipment) + + expectedPrice := unit.Cents(123) + expectedWeight := unit.Pound(2000) + suite.Equal(expectedWeight, *mtoShipment.MTOServiceItems[0].EstimatedWeight) + suite.Equal(expectedPrice, *mtoShipment.MTOServiceItems[0].PricingEstimate) + + return nil + }) + + suite.NoError(err) // just making golangci-lint happy + }) } From 0569c524cd5c5552213d60526f24a9da3087bc0f Mon Sep 17 00:00:00 2001 From: pambecker Date: Mon, 20 Jan 2025 16:04:49 +0000 Subject: [PATCH 17/23] merge conflicts --- Dockerfile | 2 +- Dockerfile.dp3 | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index f236355e92f..c0f1c0d6e1a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,7 +23,7 @@ COPY swagger/* /swagger/ COPY build /build COPY public/static/react-file-viewer /public/static/react-file-viewer -# Keep the tmp! +# Mount mutable tmp for app packages like pdfcpu VOLUME ["/tmp"] ENTRYPOINT ["/bin/milmove"] diff --git a/Dockerfile.dp3 b/Dockerfile.dp3 index fb5990cff53..d27ae71b209 100644 --- a/Dockerfile.dp3 +++ b/Dockerfile.dp3 @@ -1,8 +1,5 @@ FROM debian:stable AS build-env -## Give full perms to tmp for the server to have a read/write location -RUN mkdir -p /tmp && chmod 777 /tmp - # hadolint ignore=DL3007 FROM gcr.io/distroless/base-debian11@sha256:ac69aa622ea5dcbca0803ca877d47d069f51bd4282d5c96977e0390d7d256455 @@ -32,7 +29,7 @@ COPY swagger/* /swagger/ COPY build /build COPY public/static/react-file-viewer /public/static/react-file-viewer -# Keep the tmp! +# Mount mutable tmp for app packages like pdfcpu VOLUME ["/tmp"] ENTRYPOINT ["/bin/milmove"] From 4ce611d9be389b6bc6adc7e5e23cb50524ce3176 Mon Sep 17 00:00:00 2001 From: Daniel Jordan Date: Mon, 20 Jan 2025 15:04:14 +0000 Subject: [PATCH 18/23] updating comment --- ...0144247_update_pricing_proc_to_use_110_percent_weight.up.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrations/app/schema/20250120144247_update_pricing_proc_to_use_110_percent_weight.up.sql b/migrations/app/schema/20250120144247_update_pricing_proc_to_use_110_percent_weight.up.sql index aa7837ae551..f3e430bb5a4 100644 --- a/migrations/app/schema/20250120144247_update_pricing_proc_to_use_110_percent_weight.up.sql +++ b/migrations/app/schema/20250120144247_update_pricing_proc_to_use_110_percent_weight.up.sql @@ -1,4 +1,4 @@ --- updating to use the shipment.requested_pickup_date value to refine search to get more accurate prices +-- updating to multiply by 110% of prime estimated weight CREATE OR REPLACE PROCEDURE update_service_item_pricing( shipment_id UUID, mileage INT From b031b413515adfc693a34108d6e141756f1b58e7 Mon Sep 17 00:00:00 2001 From: Daniel Jordan Date: Mon, 20 Jan 2025 17:46:51 +0000 Subject: [PATCH 19/23] removing comments --- ...144247_update_pricing_proc_to_use_110_percent_weight.up.sql | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/migrations/app/schema/20250120144247_update_pricing_proc_to_use_110_percent_weight.up.sql b/migrations/app/schema/20250120144247_update_pricing_proc_to_use_110_percent_weight.up.sql index f3e430bb5a4..7a152be23e4 100644 --- a/migrations/app/schema/20250120144247_update_pricing_proc_to_use_110_percent_weight.up.sql +++ b/migrations/app/schema/20250120144247_update_pricing_proc_to_use_110_percent_weight.up.sql @@ -15,7 +15,7 @@ DECLARE service_code TEXT; o_zip_code TEXT; d_zip_code TEXT; - distance NUMERIC; -- This will be replaced by mileage + distance NUMERIC; estimated_fsc_multiplier NUMERIC; fuel_price NUMERIC; cents_above_baseline NUMERIC; @@ -106,7 +106,6 @@ BEGIN price_difference := calculate_price_difference(fuel_price); - -- calculate estimated price, return as cents IF estimated_fsc_multiplier IS NOT NULL AND distance IS NOT NULL THEN cents_above_baseline := distance * estimated_fsc_multiplier; RAISE NOTICE ''Distance: % * FSC Multipler: % = $% cents above baseline of $2.50'', distance, estimated_fsc_multiplier, cents_above_baseline; From a426b6653354402da8b8caf28f5282da641fb924 Mon Sep 17 00:00:00 2001 From: joeydoyecaci Date: Tue, 21 Jan 2025 11:30:04 -0500 Subject: [PATCH 20/23] Removed service item creator ntsr check --- 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 026998e3d11..c57caa7a65c 100644 --- a/pkg/services/mto_service_item/mto_service_item_creator.go +++ b/pkg/services/mto_service_item/mto_service_item_creator.go @@ -606,7 +606,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.MTOShipmentTypeHHGOutOfNTS { + if mtoShipment.PrimeEstimatedWeight != nil && mtoShipment.RequestedPickupDate != nil { serviceItemEstimatedPrice, err := o.FindEstimatedPrice(appCtx, serviceItem, mtoShipment) if serviceItemEstimatedPrice != 0 && err == nil { serviceItem.PricingEstimate = &serviceItemEstimatedPrice From 16fa17d3586ea1d1ca08c58bc8aa4a8cd1f2fc95 Mon Sep 17 00:00:00 2001 From: joeydoyecaci Date: Wed, 22 Jan 2025 16:14:36 -0500 Subject: [PATCH 21/23] Send 500 to the prime estimator --- pkg/services/orchestrators/shipment/shipment_updater.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/services/orchestrators/shipment/shipment_updater.go b/pkg/services/orchestrators/shipment/shipment_updater.go index d624d33136f..6dc0757cd2e 100644 --- a/pkg/services/orchestrators/shipment/shipment_updater.go +++ b/pkg/services/orchestrators/shipment/shipment_updater.go @@ -157,6 +157,12 @@ func AddPricingEstimatesToMTOServiceItems(appCtx appcontext.AppContext, shipment //Calculate the price using 110% of recorded weight estimatedWeightToUse = unit.Pound(estimatedWeightToUse.Float64() * 1.1) + + // if the weight is less than 500, it should be priced at minimum of 500 + if estimatedWeightToUse < 500 { + estimatedWeightToUse = 500 + } + serviceItemEstimatedPrice, err := shipmentUpdater.mtoServiceItemCreator.FindEstimatedPrice(appCtx, &serviceItem, *mtoShipment) // store actual captured weight From 3c2d562dc6d1436c5b0755f1c4568b4c48a87bb0 Mon Sep 17 00:00:00 2001 From: joeydoyecaci Date: Wed, 22 Jan 2025 18:27:07 -0500 Subject: [PATCH 22/23] Movved 500 lb limit into FindEstimatedPrice, clean up of PrimeEstimatedWeight setting --- .../mto_service_item/mto_service_item_creator.go | 9 ++++++--- pkg/services/orchestrators/shipment/shipment_updater.go | 9 +++------ 2 files changed, 9 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 c57caa7a65c..0851a845f6d 100644 --- a/pkg/services/mto_service_item/mto_service_item_creator.go +++ b/pkg/services/mto_service_item/mto_service_item_creator.go @@ -56,7 +56,10 @@ func (o *mtoServiceItemCreator) FindEstimatedPrice(appCtx appcontext.AppContext, requestedPickupDate := *mtoShipment.RequestedPickupDate currTime := time.Now() var distance int - primeEstimatedWeight := *mtoShipment.PrimeEstimatedWeight + + if *mtoShipment.PrimeEstimatedWeight < 500 && *mtoShipment.PrimeEstimatedWeight > 0 { + *mtoShipment.PrimeEstimatedWeight = 500 + } contractCode, err := FetchContractCode(appCtx, currTime) if err != nil { @@ -174,7 +177,7 @@ func (o *mtoServiceItemCreator) FindEstimatedPrice(appCtx appcontext.AppContext, } } - fscWeightBasedDistanceMultiplier, err := LookupFSCWeightBasedDistanceMultiplier(appCtx, primeEstimatedWeight) + fscWeightBasedDistanceMultiplier, err := LookupFSCWeightBasedDistanceMultiplier(appCtx, *mtoShipment.PrimeEstimatedWeight) if err != nil { return 0, err } @@ -186,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), *mtoShipment.PrimeEstimatedWeight, fscWeightBasedDistanceMultiplierFloat, eiaFuelPrice, isPPM) if err != nil { return 0, err } diff --git a/pkg/services/orchestrators/shipment/shipment_updater.go b/pkg/services/orchestrators/shipment/shipment_updater.go index 6dc0757cd2e..185e9235cd3 100644 --- a/pkg/services/orchestrators/shipment/shipment_updater.go +++ b/pkg/services/orchestrators/shipment/shipment_updater.go @@ -153,20 +153,17 @@ func AddPricingEstimatesToMTOServiceItems(appCtx appcontext.AppContext, shipment originalWeight := estimatedWeightToUse // set weight to be modified - mtoShipmentCopy.MTOServiceItems[index].EstimatedWeight = &estimatedWeightToUse + mtoShipmentCopy.PrimeEstimatedWeight = &estimatedWeightToUse //Calculate the price using 110% of recorded weight estimatedWeightToUse = unit.Pound(estimatedWeightToUse.Float64() * 1.1) - // if the weight is less than 500, it should be priced at minimum of 500 - if estimatedWeightToUse < 500 { - estimatedWeightToUse = 500 - } - serviceItemEstimatedPrice, err := shipmentUpdater.mtoServiceItemCreator.FindEstimatedPrice(appCtx, &serviceItem, *mtoShipment) // store actual captured weight mtoShipmentCopy.MTOServiceItems[index].EstimatedWeight = &originalWeight + mtoShipmentCopy.PrimeEstimatedWeight = &originalWeight + if serviceItemEstimatedPrice != 0 && err == nil { mtoShipmentCopy.MTOServiceItems[index].PricingEstimate = &serviceItemEstimatedPrice } From 5f182711b3ad86fd1d77163a6548bc0550ecfc8d Mon Sep 17 00:00:00 2001 From: joeydoyecaci Date: Thu, 23 Jan 2025 18:23:26 +0000 Subject: [PATCH 23/23] Added GetAdjustedWeight and moved 110% modifier --- .../mto_service_item_creator.go | 39 ++++++++---- .../mto_service_item_creator_test.go | 63 +++++++++++++++++++ .../shipment/shipment_updater.go | 11 +--- 3 files changed, 93 insertions(+), 20 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 0851a845f6d..9832fa733b0 100644 --- a/pkg/services/mto_service_item/mto_service_item_creator.go +++ b/pkg/services/mto_service_item/mto_service_item_creator.go @@ -57,9 +57,7 @@ func (o *mtoServiceItemCreator) FindEstimatedPrice(appCtx appcontext.AppContext, currTime := time.Now() var distance int - if *mtoShipment.PrimeEstimatedWeight < 500 && *mtoShipment.PrimeEstimatedWeight > 0 { - *mtoShipment.PrimeEstimatedWeight = 500 - } + adjustedWeight := GetAdjustedWeight(*mtoShipment.PrimeEstimatedWeight, mtoShipment.ShipmentType == models.MTOShipmentTypeUnaccompaniedBaggage) contractCode, err := FetchContractCode(appCtx, currTime) if err != nil { @@ -78,7 +76,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, *adjustedWeight, domesticServiceArea.ServiceArea, isPPM) if err != nil { return 0, err } @@ -91,7 +89,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, *adjustedWeight, servicesScheduleOrigin, isPPM) if err != nil { return 0, err } @@ -106,7 +104,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, *adjustedWeight, domesticServiceArea.ServiceArea, isPPM) if err != nil { return 0, err } @@ -119,7 +117,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, *adjustedWeight, serviceScheduleDestination, isPPM) if err != nil { return 0, err } @@ -137,7 +135,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), *adjustedWeight, domesticServiceArea.ServiceArea, isPPM) if err != nil { return 0, err } @@ -153,7 +151,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), *adjustedWeight, domesticServiceArea.ServiceArea) if err != nil { return 0, err } @@ -177,7 +175,7 @@ func (o *mtoServiceItemCreator) FindEstimatedPrice(appCtx appcontext.AppContext, } } - fscWeightBasedDistanceMultiplier, err := LookupFSCWeightBasedDistanceMultiplier(appCtx, *mtoShipment.PrimeEstimatedWeight) + fscWeightBasedDistanceMultiplier, err := LookupFSCWeightBasedDistanceMultiplier(appCtx, *adjustedWeight) if err != nil { return 0, err } @@ -189,7 +187,7 @@ func (o *mtoServiceItemCreator) FindEstimatedPrice(appCtx appcontext.AppContext, if err != nil { return 0, err } - price, _, err = o.fuelSurchargePricer.Price(appCtx, pickupDateForFSC, unit.Miles(distance), *mtoShipment.PrimeEstimatedWeight, fscWeightBasedDistanceMultiplierFloat, eiaFuelPrice, isPPM) + price, _, err = o.fuelSurchargePricer.Price(appCtx, pickupDateForFSC, unit.Miles(distance), *adjustedWeight, fscWeightBasedDistanceMultiplierFloat, eiaFuelPrice, isPPM) if err != nil { return 0, err } @@ -941,3 +939,22 @@ func (o *mtoServiceItemCreator) validateFirstDaySITServiceItem(appCtx appcontext return &extraServiceItems, nil } + +// Get Adjusted weight for pricing. Returns the weight at 110% or the minimum billable weight whichever is higher, unless it's 0 +func GetAdjustedWeight(incomingWeight unit.Pound, isUB bool) *unit.Pound { + // minimum weight billed by GHC is 500 lbs unless it's Unaccompanied Baggage (UB) + minimumBilledWeight := unit.Pound(500) + if isUB { + minimumBilledWeight = unit.Pound(300) + } + + // add 110% modifier to billable weight + newWeight := (int(incomingWeight.Float64() * 1.1)) + adjustedWeight := (*unit.Pound)(&newWeight) + + // if the adjusted weight is less than the minimum billable weight but is nonzero, set it to the minimum weight billed + if *adjustedWeight < minimumBilledWeight && *adjustedWeight > 0 { + *adjustedWeight = minimumBilledWeight + } + return adjustedWeight +} 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 d2a7709b9ff..9124119c722 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 @@ -1840,3 +1840,66 @@ func (suite *MTOServiceItemServiceSuite) TestCreateDestSITServiceItem() { suite.Contains(invalidInputError.ValidationErrors.Keys(), "reServiceCode") }) } +func (suite *MTOServiceItemServiceSuite) TestGetAdjustedWeight() { + suite.Run("If no weight is provided", func() { + var incomingWeight unit.Pound + adjustedWeight := GetAdjustedWeight(incomingWeight, false) + suite.Equal(unit.Pound(0), *adjustedWeight) + }) + suite.Run("If a weight of 0 is provided", func() { + incomingWeight := unit.Pound(0) + adjustedWeight := GetAdjustedWeight(incomingWeight, false) + suite.Equal(unit.Pound(0), *adjustedWeight) + }) + suite.Run("If weight of 100 is provided", func() { + incomingWeight := unit.Pound(100) + adjustedWeight := GetAdjustedWeight(incomingWeight, false) + suite.Equal(unit.Pound(500), *adjustedWeight) + }) + suite.Run("If weight of 454 is provided", func() { + incomingWeight := unit.Pound(454) + adjustedWeight := GetAdjustedWeight(incomingWeight, false) + suite.Equal(unit.Pound(500), *adjustedWeight) + }) + suite.Run("If weight of 456 is provided", func() { + incomingWeight := unit.Pound(456) + adjustedWeight := GetAdjustedWeight(incomingWeight, false) + suite.Equal(unit.Pound(501), *adjustedWeight) + }) + suite.Run("If weight of 1000 is provided", func() { + incomingWeight := unit.Pound(1000) + adjustedWeight := GetAdjustedWeight(incomingWeight, false) + suite.Equal(unit.Pound(1100), *adjustedWeight) + }) + + suite.Run("If no weight is provided UB", func() { + var incomingWeight unit.Pound + adjustedWeight := GetAdjustedWeight(incomingWeight, true) + suite.Equal(unit.Pound(0), *adjustedWeight) + }) + suite.Run("If a weight of 0 is provided UB", func() { + incomingWeight := unit.Pound(0) + adjustedWeight := GetAdjustedWeight(incomingWeight, true) + suite.Equal(unit.Pound(0), *adjustedWeight) + }) + suite.Run("If weight of 100 is provided UB", func() { + incomingWeight := unit.Pound(100) + adjustedWeight := GetAdjustedWeight(incomingWeight, true) + suite.Equal(unit.Pound(300), *adjustedWeight) + }) + suite.Run("If weight of 272 is provided UB", func() { + incomingWeight := unit.Pound(272) + adjustedWeight := GetAdjustedWeight(incomingWeight, true) + suite.Equal(unit.Pound(300), *adjustedWeight) + }) + suite.Run("If weight of 274 is provided UB", func() { + incomingWeight := unit.Pound(274) + adjustedWeight := GetAdjustedWeight(incomingWeight, true) + suite.Equal(unit.Pound(301), *adjustedWeight) + }) + suite.Run("If weight of 1000 is provided UB", func() { + incomingWeight := unit.Pound(1000) + adjustedWeight := GetAdjustedWeight(incomingWeight, true) + suite.Equal(unit.Pound(1100), *adjustedWeight) + }) +} diff --git a/pkg/services/orchestrators/shipment/shipment_updater.go b/pkg/services/orchestrators/shipment/shipment_updater.go index 185e9235cd3..d8d82af8e90 100644 --- a/pkg/services/orchestrators/shipment/shipment_updater.go +++ b/pkg/services/orchestrators/shipment/shipment_updater.go @@ -150,19 +150,12 @@ func AddPricingEstimatesToMTOServiceItems(appCtx appcontext.AppContext, shipment } else { estimatedWeightToUse = *mtoShipmentCopy.PrimeEstimatedWeight } - originalWeight := estimatedWeightToUse - - // set weight to be modified - mtoShipmentCopy.PrimeEstimatedWeight = &estimatedWeightToUse - - //Calculate the price using 110% of recorded weight - estimatedWeightToUse = unit.Pound(estimatedWeightToUse.Float64() * 1.1) serviceItemEstimatedPrice, err := shipmentUpdater.mtoServiceItemCreator.FindEstimatedPrice(appCtx, &serviceItem, *mtoShipment) // store actual captured weight - mtoShipmentCopy.MTOServiceItems[index].EstimatedWeight = &originalWeight - mtoShipmentCopy.PrimeEstimatedWeight = &originalWeight + mtoShipmentCopy.MTOServiceItems[index].EstimatedWeight = &estimatedWeightToUse + mtoShipmentCopy.PrimeEstimatedWeight = &estimatedWeightToUse if serviceItemEstimatedPrice != 0 && err == nil { mtoShipmentCopy.MTOServiceItems[index].PricingEstimate = &serviceItemEstimatedPrice