Skip to content

Commit

Permalink
Merge pull request #13650 from transcom/INT-B-20618-Office-Edit-Mobil…
Browse files Browse the repository at this point in the history
…e-Home

INT-B-20618 Office users edit/create/delete mobile home shipments
  • Loading branch information
brooklyn-welsh authored Sep 26, 2024
2 parents 951e7f1 + 360e3cf commit e6bccd7
Show file tree
Hide file tree
Showing 16 changed files with 1,015 additions and 66 deletions.
8 changes: 4 additions & 4 deletions pkg/factory/boat_shipment_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type boatBuildType byte
const (
boatBuildStandard boatBuildType = iota
boatBuildStandardTowAway
boatBuildStandardHualAway
boatBuildStandardHaulAway
)

// buildBoatShipmentWithBuildType does the actual work
Expand Down Expand Up @@ -56,7 +56,7 @@ func buildBoatShipmentWithBuildType(db *pop.Connection, customs []Customization,
shipment.ShipmentType = models.MTOShipmentTypeBoatTowAway
}

if buildType == boatBuildStandardHualAway {
if buildType == boatBuildStandardHaulAway {
shipment.ShipmentType = models.MTOShipmentTypeBoatHaulAway
}

Expand All @@ -80,7 +80,7 @@ func buildBoatShipmentWithBuildType(db *pop.Connection, customs []Customization,
boatShipment.IsRoadworthy = models.BoolPointer(true)
}

if buildType == boatBuildStandardHualAway {
if buildType == boatBuildStandardHaulAway {
boatShipment.Type = models.BoatShipmentTypeHaulAway
boatShipment.HasTrailer = models.BoolPointer(false)
boatShipment.IsRoadworthy = models.BoolPointer(false)
Expand All @@ -106,7 +106,7 @@ func BuildBoatShipmentTowAway(db *pop.Connection, customs []Customization, trait
return buildBoatShipmentWithBuildType(db, customs, traits, boatBuildStandardTowAway)
}
func BuildBoatShipmentHaulAway(db *pop.Connection, customs []Customization, traits []Trait) models.BoatShipment {
return buildBoatShipmentWithBuildType(db, customs, traits, boatBuildStandardHualAway)
return buildBoatShipmentWithBuildType(db, customs, traits, boatBuildStandardHaulAway)
}

// ------------------------
Expand Down
26 changes: 15 additions & 11 deletions pkg/services/move/move_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,29 +214,33 @@ func (router moveRouter) sendToServiceCounselor(appCtx appcontext.AppContext, mo
move.MTOShipments[i].Status = models.MTOShipmentStatusSubmitted

if verrs, err := appCtx.DB().ValidateAndUpdate(&move.MTOShipments[i]); verrs.HasAny() || err != nil {
msg := "failure saving shipment when routing move submission"
msg := "failure saving parent MTO shipment object for boat/mobile home shipment when routing move submission"
appCtx.Logger().Error(msg, zap.Error(err))
return apperror.NewInvalidInputError(move.MTOShipments[i].ID, err, verrs, msg)
}
}
// update status for mobile home shipment
if move.MTOShipments[i].ShipmentType == models.MTOShipmentTypeMobileHome {
move.MTOShipments[i].Status = models.MTOShipmentStatusSubmitted

if verrs, err := appCtx.DB().ValidateAndUpdate(&move.MTOShipments[i]); verrs.HasAny() || err != nil {
msg := "failure saving shipment when routing move submission"
appCtx.Logger().Error(msg, zap.Error(err))
return apperror.NewInvalidInputError(move.MTOShipments[i].ID, err, verrs, msg)
if move.MTOShipments[i].BoatShipment != nil {
if verrs, err := appCtx.DB().ValidateAndUpdate(move.MTOShipments[i].BoatShipment); verrs.HasAny() || err != nil {
msg := "failure saving boat shipment when routing move submission"
appCtx.Logger().Error(msg, zap.Error(err))
return apperror.NewInvalidInputError(move.MTOShipments[i].ID, err, verrs, msg)
}
}

if move.MTOShipments[i].MobileHome != nil {
if verrs, err := appCtx.DB().ValidateAndUpdate(move.MTOShipments[i].MobileHome); verrs.HasAny() || err != nil {
msg := "failure saving mobile home shipment when routing move submission"
appCtx.Logger().Error(msg, zap.Error(err))
return apperror.NewInvalidInputError(move.MTOShipments[i].ID, err, verrs, msg)
}
}
}
}

if verrs, err := appCtx.DB().ValidateAndSave(move); verrs.HasAny() || err != nil {
msg := "failure saving move when routing move submission"
appCtx.Logger().Error(msg, zap.Error(err))
return apperror.NewInvalidInputError(move.ID, err, verrs, msg)
}

return nil
}

Expand Down
235 changes: 235 additions & 0 deletions pkg/services/move/move_router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,23 @@ func (suite *MoveServiceSuite) TestMoveSubmission() {
},
},
}, nil)

boatShipment := factory.BuildBoatShipmentHaulAway(suite.DB(), []factory.Customization{
{
Model: models.BoatShipment{},
},
}, nil)

mobileHomeShipment := factory.BuildMobileHomeShipment(suite.DB(), []factory.Customization{
{
Model: models.MobileHome{},
},
}, nil)

move.MTOShipments = models.MTOShipments{shipment}
move.MTOShipments[0].PPMShipment = &ppmShipment
move.MTOShipments[0].BoatShipment = &boatShipment
move.MTOShipments[0].MobileHome = &mobileHomeShipment

newSignedCertification := factory.BuildSignedCertification(nil, []factory.Customization{
{
Expand Down Expand Up @@ -397,6 +412,204 @@ func (suite *MoveServiceSuite) TestMoveSubmission() {
suite.Equal(models.MTOShipmentStatusSubmitted, move.MTOShipments[0].Status, "expected Submitted")
suite.Equal(models.PPMShipmentStatusSubmitted, move.MTOShipments[0].PPMShipment.Status, "expected Submitted")
})

suite.Run("returns an error when a Mobile Home Shipment is not formatted correctly", func() {
// Under test: MoveRouter.Submit
// Set up: Submit a move without a mobile home shipment that has a field that will not pass validation
// Expected outcome: Error on DB().ValidateAndUpdate
move := factory.BuildMove(suite.DB(), []factory.Customization{
{
Model: models.DutyLocation{
ProvidesServicesCounseling: true,
},
Type: &factory.DutyLocations.OriginDutyLocation,
},
}, nil)
hhgShipment := factory.BuildMTOShipmentMinimal(suite.DB(), []factory.Customization{
{
Model: models.MTOShipment{
Status: models.MTOShipmentStatusDraft,
ShipmentType: models.MTOShipmentTypeMobileHome,
},
},
{
Model: move,
LinkOnly: true,
},
}, nil)

year := -10000
mobileHomeShipment := factory.BuildMobileHomeShipment(suite.DB(), []factory.Customization{
{
Model: models.MobileHome{},
},
}, nil)
mobileHomeShipment.Year = &year
move.MTOShipments = models.MTOShipments{hhgShipment}
move.MTOShipments[0].MobileHome = &mobileHomeShipment
newSignedCertification := factory.BuildSignedCertification(nil, []factory.Customization{
{
Model: move,
LinkOnly: true,
},
}, nil)
err := moveRouter.Submit(suite.AppContextForTest(), &move, &newSignedCertification)

suite.Error(err)
suite.Contains(err.Error(), "failure saving mobile home shipment when routing move submission")
suite.Equal(models.MoveStatusNeedsServiceCounseling, move.Status, "expected move to still be in NEEDS_SERVICE_COUNSELING status when routing has failed")
})

suite.Run("returns an error when a Mobile Home Shipment is not formatted correctly", func() {
// Under test: MoveRouter.Submit
// Set up: Submit a move without a mobile home shipment that has a field that will not pass validation
// Expected outcome: Error on DB().ValidateAndUpdate
move := factory.BuildMove(suite.DB(), []factory.Customization{
{
Model: models.DutyLocation{
ProvidesServicesCounseling: true,
},
Type: &factory.DutyLocations.OriginDutyLocation,
},
}, nil)
hhgShipment := factory.BuildMTOShipmentMinimal(suite.DB(), []factory.Customization{
{
Model: models.MTOShipment{
Status: models.MTOShipmentStatusDraft,
ShipmentType: models.MTOShipmentTypeBoatHaulAway,
},
},
{
Model: move,
LinkOnly: true,
},
}, nil)

year := -10000
boatShipment := factory.BuildBoatShipment(suite.DB(), []factory.Customization{
{
Model: models.BoatShipment{},
},
}, nil)
boatShipment.Year = &year
move.MTOShipments = models.MTOShipments{hhgShipment}
move.MTOShipments[0].BoatShipment = &boatShipment
newSignedCertification := factory.BuildSignedCertification(nil, []factory.Customization{
{
Model: move,
LinkOnly: true,
},
}, nil)
err := moveRouter.Submit(suite.AppContextForTest(), &move, &newSignedCertification)

suite.Error(err)
suite.Contains(err.Error(), "failure saving boat shipment when routing move submission")
suite.Equal(models.MoveStatusNeedsServiceCounseling, move.Status, "expected move to still be in NEEDS_SERVICE_COUNSELING status when routing has failed")
})

suite.Run("returns validation errors when a the parent MTO Shipment object for a Mobile Home Shipment is not formatted correctly", func() {
// Under test: MoveRouter.Submit
// Set up: Submit a move without a mobile home shipment that has a field that will not pass validation
// Expected outcome: Error on DB().ValidateAndUpdate

sitDaysAllowance := -1 // Invalid value that should cause a validation error on MTOShipment

expError := "failure saving parent MTO shipment object for boat/mobile home shipment when routing move submission"

move := factory.BuildMove(suite.DB(), []factory.Customization{
{
Model: models.DutyLocation{
ProvidesServicesCounseling: true,
},
Type: &factory.DutyLocations.OriginDutyLocation,
},
}, nil)
hhgShipment := factory.BuildMTOShipmentMinimal(suite.DB(), []factory.Customization{
{
Model: models.MTOShipment{
Status: models.MTOShipmentStatusDraft,
ShipmentType: models.MTOShipmentTypeMobileHome,
},
},
{
Model: move,
LinkOnly: true,
},
}, nil)

hhgShipment.SITDaysAllowance = &sitDaysAllowance

mobileHomeShipment := factory.BuildMobileHomeShipment(suite.DB(), []factory.Customization{
{
Model: models.MobileHome{},
},
}, nil)
move.MTOShipments = models.MTOShipments{hhgShipment}
move.MTOShipments[0].MobileHome = &mobileHomeShipment
newSignedCertification := factory.BuildSignedCertification(nil, []factory.Customization{
{
Model: move,
LinkOnly: true,
},
}, nil)
err := moveRouter.Submit(suite.AppContextForTest(), &move, &newSignedCertification)

suite.Error(err)
suite.Contains(err.Error(), expError)
suite.Equal(models.MoveStatusNeedsServiceCounseling, move.Status, "expected move to still be in NEEDS_SERVICE_COUNSELING status when routing has failed")
})

suite.Run("returns validation errors when a the parent MTO Shipment object for a Boat Shipment is not formatted correctly", func() {
// Under test: MoveRouter.Submit
// Set up: Submit a move without a mobile home shipment that has a field that will not pass validation
// Expected outcome: Error on DB().ValidateAndUpdate

sitDaysAllowance := -1 // Invalid value that should cause a validation error on MTOShipment

expError := "failure saving parent MTO shipment object for boat/mobile home shipment when routing move submission"

move := factory.BuildMove(suite.DB(), []factory.Customization{
{
Model: models.DutyLocation{
ProvidesServicesCounseling: true,
},
Type: &factory.DutyLocations.OriginDutyLocation,
},
}, nil)
hhgShipment := factory.BuildMTOShipmentMinimal(suite.DB(), []factory.Customization{
{
Model: models.MTOShipment{
Status: models.MTOShipmentStatusDraft,
ShipmentType: models.MTOShipmentTypeBoatHaulAway,
},
},
{
Model: move,
LinkOnly: true,
},
}, nil)

hhgShipment.SITDaysAllowance = &sitDaysAllowance

boatShipment := factory.BuildBoatShipment(suite.DB(), []factory.Customization{
{
Model: models.BoatShipment{},
},
}, nil)
move.MTOShipments = models.MTOShipments{hhgShipment}
move.MTOShipments[0].BoatShipment = &boatShipment
newSignedCertification := factory.BuildSignedCertification(nil, []factory.Customization{
{
Model: move,
LinkOnly: true,
},
}, nil)
err := moveRouter.Submit(suite.AppContextForTest(), &move, &newSignedCertification)

suite.Error(err)
suite.Contains(err.Error(), expError)
suite.Equal(models.MoveStatusNeedsServiceCounseling, move.Status, "expected move to still be in NEEDS_SERVICE_COUNSELING status when routing has failed")
})
}

func (suite *MoveServiceSuite) TestMoveCancellation() {
Expand Down Expand Up @@ -745,6 +958,28 @@ func (suite *MoveServiceSuite) TestCompleteServiceCounseling() {
suite.IsType(apperror.ConflictError{}, err)
suite.Contains(err.Error(), "NTS-release shipment must include facility info")
})

suite.Run("Boat Shipment - status changed to 'SERVICE_COUNSELING_COMPLETED'", func() {
move := factory.BuildStubbedMoveWithStatus(models.MoveStatusNeedsServiceCounseling)
boatShipment := factory.BuildBoatShipment(nil, nil, nil)
move.MTOShipments = models.MTOShipments{boatShipment.Shipment}

err := moveRouter.CompleteServiceCounseling(suite.AppContextForTest(), &move)

suite.NoError(err)
suite.Equal(models.MoveStatusServiceCounselingCompleted, move.Status)
})

suite.Run("Mobile Home Shipment - status changed to 'SERVICE_COUNSELING_COMPLETED'", func() {
move := factory.BuildStubbedMoveWithStatus(models.MoveStatusNeedsServiceCounseling)
mobileHomeShipment := factory.BuildMobileHomeShipment(nil, nil, nil)
move.MTOShipments = models.MTOShipments{mobileHomeShipment.Shipment}

err := moveRouter.CompleteServiceCounseling(suite.AppContextForTest(), &move)

suite.NoError(err)
suite.Equal(models.MoveStatusServiceCounselingCompleted, move.Status)
})
}

func (suite *MoveServiceSuite) createServiceItem() (models.MTOServiceItem, models.Move) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,6 @@ func (suite *ShipmentSummaryWorksheetServiceSuite) TestMemberPaidRemainingPPMEnt
mockPPMCloseoutFetcher := &mocks.PPMCloseoutFetcher{}
sswPPMComputer := NewSSWPPMComputer(mockPPMCloseoutFetcher)
sswPage2, _ := sswPPMComputer.FormatValuesShipmentSummaryWorksheetFormPage2(ssd, true)

suite.Equal("$4.00", sswPage2.PPMRemainingEntitlement)
}

Expand Down
Loading

0 comments on commit e6bccd7

Please sign in to comment.