Skip to content

Commit

Permalink
Merge branch 'integrationTesting' into B-22227-INT
Browse files Browse the repository at this point in the history
  • Loading branch information
r-mettler authored Feb 13, 2025
2 parents d75839d + 6529c15 commit 088dba6
Show file tree
Hide file tree
Showing 10 changed files with 627 additions and 172 deletions.
4 changes: 2 additions & 2 deletions pkg/handlers/primeapi/mto_service_item_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1097,8 +1097,8 @@ func (suite *HandlerSuite) TestCreateMTOServiceItemOriginSITHandlerWithDOFSITWit
},
}, nil)
factory.FetchReServiceByCode(suite.DB(), models.ReServiceCodeDOFSIT)
sitEntryDate := time.Date(2024, time.February, 28, 0, 0, 0, 0, time.UTC)
sitDepartureDate := time.Date(2024, time.February, 27, 0, 0, 0, 0, time.UTC)
sitEntryDate := time.Date(2024, time.February, 27, 0, 0, 0, 0, time.UTC)
sitDepartureDate := time.Date(2024, time.February, 28, 0, 0, 0, 0, time.UTC)
sitPostalCode := "00000"

// Original customer pickup address
Expand Down
6 changes: 6 additions & 0 deletions pkg/services/mto_service_item/mto_service_item_creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,12 @@ func (o *mtoServiceItemCreator) validateFirstDaySITServiceItem(appCtx appcontext
return nil, err
}

//SIT Entry Date must be before SIT Departure Date
err = o.checkSITEntryDateBeforeDepartureDate(serviceItem)
if err != nil {
return nil, err
}

verrs := validate.NewErrors()

// check if the address IDs are nil
Expand Down
150 changes: 150 additions & 0 deletions pkg/services/mto_service_item/mto_service_item_creator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1354,6 +1354,99 @@ func (suite *MTOServiceItemServiceSuite) TestCreateOriginSITServiceItem() {
suite.IsType(apperror.ConflictError{}, err)
})

suite.Run("Do not create DOFSIT if departure date is after entry date", func() {
shipment := setupTestData()
originAddress := factory.BuildAddress(suite.DB(), nil, nil)
reServiceDOFSIT := factory.FetchReServiceByCode(suite.DB(), models.ReServiceCodeDOFSIT)
serviceItemDOFSIT := factory.BuildMTOServiceItem(nil, []factory.Customization{
{
Model: models.MTOServiceItem{
SITEntryDate: models.TimePointer(time.Now().AddDate(0, 0, 1)),
SITDepartureDate: models.TimePointer(time.Now()),
},
},
{
Model: reServiceDOFSIT,
LinkOnly: true,
},
{
Model: shipment,
LinkOnly: true,
},
{
Model: originAddress,
LinkOnly: true,
Type: &factory.Addresses.SITOriginHHGOriginalAddress,
},
}, nil)
builder := query.NewQueryBuilder()
moveRouter := moverouter.NewMoveRouter()
planner := &mocks.Planner{}
planner.On("ZipTransitDistance",
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())
_, _, err := creator.CreateMTOServiceItem(suite.AppContextForTest(), &serviceItemDOFSIT)
suite.Error(err)
expectedError := fmt.Sprintf(
"the SIT Departure Date (%s) must be after the SIT Entry Date (%s)",
serviceItemDOFSIT.SITDepartureDate.Format("2006-01-02"),
serviceItemDOFSIT.SITEntryDate.Format("2006-01-02"),
)
suite.Contains(err.Error(), expectedError)
})

suite.Run("Do not create DOFSIT if departure date is the same as entry date", func() {
today := models.TimePointer(time.Now())
shipment := setupTestData()
originAddress := factory.BuildAddress(suite.DB(), nil, nil)
reServiceDOFSIT := factory.FetchReServiceByCode(suite.DB(), models.ReServiceCodeDOFSIT)
serviceItemDOFSIT := factory.BuildMTOServiceItem(nil, []factory.Customization{
{
Model: models.MTOServiceItem{
SITEntryDate: today,
SITDepartureDate: today,
},
},
{
Model: reServiceDOFSIT,
LinkOnly: true,
},
{
Model: shipment,
LinkOnly: true,
},
{
Model: originAddress,
LinkOnly: true,
Type: &factory.Addresses.SITOriginHHGOriginalAddress,
},
}, nil)
builder := query.NewQueryBuilder()
moveRouter := moverouter.NewMoveRouter()
planner := &mocks.Planner{}
planner.On("ZipTransitDistance",
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())
_, _, err := creator.CreateMTOServiceItem(suite.AppContextForTest(), &serviceItemDOFSIT)
suite.Error(err)
expectedError := fmt.Sprintf(
"the SIT Departure Date (%s) must be after the SIT Entry Date (%s)",
serviceItemDOFSIT.SITDepartureDate.Format("2006-01-02"),
serviceItemDOFSIT.SITEntryDate.Format("2006-01-02"),
)
suite.Contains(err.Error(), expectedError)
})

suite.Run("Do not create standalone DOPSIT service item", func() {
// TESTCASE SCENARIO
// Under test: CreateMTOServiceItem function
Expand Down Expand Up @@ -1779,6 +1872,63 @@ func (suite *MTOServiceItemServiceSuite) TestCreateDestSITServiceItem() {
suite.Contains(err.Error(), expectedError)
})

suite.Run("Do not create DDFSIT if departure date is after entry date", func() {
shipment, creator, reServiceDDFSIT := setupTestData()
serviceItemDDFSIT := factory.BuildMTOServiceItem(nil, []factory.Customization{
{
Model: models.MTOServiceItem{
SITEntryDate: models.TimePointer(time.Now().AddDate(0, 0, 1)),
SITDepartureDate: models.TimePointer(time.Now()),
},
},
{
Model: reServiceDDFSIT,
LinkOnly: true,
},
{
Model: shipment,
LinkOnly: true,
},
}, nil)
_, _, err := creator.CreateMTOServiceItem(suite.AppContextForTest(), &serviceItemDDFSIT)
suite.Error(err)
expectedError := fmt.Sprintf(
"the SIT Departure Date (%s) must be after the SIT Entry Date (%s)",
serviceItemDDFSIT.SITDepartureDate.Format("2006-01-02"),
serviceItemDDFSIT.SITEntryDate.Format("2006-01-02"),
)
suite.Contains(err.Error(), expectedError)
})

suite.Run("Do not create DDFSIT if departure date is the same as entry date", func() {
today := models.TimePointer(time.Now())
shipment, creator, reServiceDDFSIT := setupTestData()
serviceItemDDFSIT := factory.BuildMTOServiceItem(nil, []factory.Customization{
{
Model: models.MTOServiceItem{
SITEntryDate: today,
SITDepartureDate: today,
},
},
{
Model: reServiceDDFSIT,
LinkOnly: true,
},
{
Model: shipment,
LinkOnly: true,
},
}, nil)
_, _, err := creator.CreateMTOServiceItem(suite.AppContextForTest(), &serviceItemDDFSIT)
suite.Error(err)
expectedError := fmt.Sprintf(
"the SIT Departure Date (%s) must be after the SIT Entry Date (%s)",
serviceItemDDFSIT.SITDepartureDate.Format("2006-01-02"),
serviceItemDDFSIT.SITEntryDate.Format("2006-01-02"),
)
suite.Contains(err.Error(), expectedError)
})

// Successful creation of DDASIT service item
suite.Run("Success - DDASIT creation approved", func() {
shipment, creator, reServiceDDFSIT := setupTestData()
Expand Down
13 changes: 13 additions & 0 deletions pkg/services/mto_service_item/mto_service_item_validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -838,3 +838,16 @@ func (o *mtoServiceItemCreator) checkSITEntryDateAndFADD(serviceItem *models.MTO

return nil
}

func (o *mtoServiceItemCreator) checkSITEntryDateBeforeDepartureDate(serviceItem *models.MTOServiceItem) error {
if serviceItem.SITEntryDate == nil || serviceItem.SITDepartureDate == nil {
return nil
}

//Departure Date has to be after the Entry Date
if !serviceItem.SITDepartureDate.After(*serviceItem.SITEntryDate) {
return apperror.NewUnprocessableEntityError(fmt.Sprintf("the SIT Departure Date (%s) must be after the SIT Entry Date (%s)",
serviceItem.SITDepartureDate.Format("2006-01-02"), serviceItem.SITEntryDate.Format("2006-01-02")))
}
return nil
}
Loading

0 comments on commit 088dba6

Please sign in to comment.