Skip to content

Commit

Permalink
added counselor update authorized weight allowance and added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cameroncaci committed Jan 29, 2024
1 parent bb7a2c6 commit f65b2d8
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 2 deletions.
15 changes: 15 additions & 0 deletions pkg/factory/order_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,18 @@ func BuildOrder(db *pop.Connection, customs []Customization, traits []Trait) mod
func BuildOrderWithoutDefaults(db *pop.Connection, customs []Customization, traits []Trait) models.Order {
return buildOrderWithBuildType(db, customs, traits, orderBuildWithoutDefaults)
}

// ------------------------
// TRAITS
// ------------------------

// GetTraitHasDependents returns a customization to enable dependents on an order
func GetTraitHasDependents() []Customization {
return []Customization{
{
Model: models.Order{
HasDependents: true,
},
},
}
}
10 changes: 10 additions & 0 deletions pkg/services/order/order_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,16 @@ func allowanceFromCounselingPayload(existingOrder models.Order, payload ghcmessa
order.Grade = &grade
}

// Calculate new DBWeightAuthorized based on the new grade
weightAllotment := models.GetWeightAllotment(*order.Grade)
weight := weightAllotment.TotalWeightSelf
// Payload does not have this information, retrieve dependents from the existing order
if existingOrder.HasDependents && *payload.DependentsAuthorized {
// Only utilize dependent weight authorized if dependents are both present and authorized
weight = weightAllotment.TotalWeightSelfPlusDependents
}
order.Entitlement.DBAuthorizedWeight = &weight

if payload.OrganizationalClothingAndIndividualEquipment != nil {
order.Entitlement.OrganizationalClothingAndIndividualEquipment = *payload.OrganizationalClothingAndIndividualEquipment
}
Expand Down
93 changes: 91 additions & 2 deletions pkg/services/order/order_updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ func (suite *OrderServiceSuite) TestUpdateAllowanceAsTOO() {
suite.IsType(apperror.PreconditionFailedError{}, err)
})

suite.Run("Updates the allowance when all fields are valid", func() {
suite.Run("Updates the allowance when all fields are valid and no dependents", func() {
moveRouter := move.NewMoveRouter()
orderUpdater := NewOrderUpdater(moveRouter)
order := factory.BuildServiceCounselingCompletedMove(suite.DB(), nil, nil).Orders
Expand Down Expand Up @@ -572,6 +572,49 @@ func (suite *OrderServiceSuite) TestUpdateAllowanceAsTOO() {
suite.Equal(*payload.ProGearWeightSpouse, int64(updatedOrder.Entitlement.ProGearWeightSpouse))
suite.Equal(*payload.RequiredMedicalEquipmentWeight, int64(updatedOrder.Entitlement.RequiredMedicalEquipmentWeight))
suite.Equal(*payload.OrganizationalClothingAndIndividualEquipment, updatedOrder.Entitlement.OrganizationalClothingAndIndividualEquipment)
suite.Equal(*updatedOrder.Entitlement.DBAuthorizedWeight, 16000)
})

suite.Run("Updates the allowance when all fields are valid with dependents", func() {
moveRouter := move.NewMoveRouter()
orderUpdater := NewOrderUpdater(moveRouter)
// Build with dependents trait
order := factory.BuildServiceCounselingCompletedMove(suite.DB(), nil, []factory.Trait{
factory.GetTraitHasDependents,
}).Orders

grade := ghcmessages.GradeO5
affiliation := ghcmessages.AffiliationAIRFORCE
ocie := false
proGearWeight := models.Int64Pointer(100)
proGearWeightSpouse := models.Int64Pointer(10)
rmeWeight := models.Int64Pointer(10000)
eTag := etag.GenerateEtag(order.UpdatedAt)

payload := ghcmessages.UpdateAllowancePayload{
Agency: &affiliation,
DependentsAuthorized: models.BoolPointer(true),
Grade: &grade,
OrganizationalClothingAndIndividualEquipment: &ocie,
ProGearWeight: proGearWeight,
ProGearWeightSpouse: proGearWeightSpouse,
RequiredMedicalEquipmentWeight: rmeWeight,
}

updatedOrder, _, err := orderUpdater.UpdateAllowanceAsTOO(suite.AppContextForTest(), order.ID, payload, eTag)
suite.NoError(err)

var orderInDB models.Order
err = suite.DB().Find(&orderInDB, order.ID)

suite.NoError(err)
suite.Equal(order.ID.String(), updatedOrder.ID.String())
suite.Equal(payload.DependentsAuthorized, updatedOrder.Entitlement.DependentsAuthorized)
suite.Equal(*payload.ProGearWeight, int64(updatedOrder.Entitlement.ProGearWeight))
suite.Equal(*payload.ProGearWeightSpouse, int64(updatedOrder.Entitlement.ProGearWeightSpouse))
suite.Equal(*payload.RequiredMedicalEquipmentWeight, int64(updatedOrder.Entitlement.RequiredMedicalEquipmentWeight))
suite.Equal(*payload.OrganizationalClothingAndIndividualEquipment, updatedOrder.Entitlement.OrganizationalClothingAndIndividualEquipment)
suite.Equal(*updatedOrder.Entitlement.DBAuthorizedWeight, 17500)
})
}

Expand Down Expand Up @@ -604,7 +647,7 @@ func (suite *OrderServiceSuite) TestUpdateAllowanceAsCounselor() {
suite.IsType(apperror.PreconditionFailedError{}, err)
})

suite.Run("Updates the allowance when all fields are valid", func() {
suite.Run("Updates the allowance when all fields are valid with dependents authorized but not present", func() {
moveRouter := move.NewMoveRouter()
orderUpdater := NewOrderUpdater(moveRouter)
order := factory.BuildNeedsServiceCounselingMove(suite.DB(), nil, nil).Orders
Expand Down Expand Up @@ -644,6 +687,52 @@ func (suite *OrderServiceSuite) TestUpdateAllowanceAsCounselor() {
suite.Equal(*payload.RequiredMedicalEquipmentWeight, int64(updatedOrder.Entitlement.RequiredMedicalEquipmentWeight))
suite.Equal(*payload.OrganizationalClothingAndIndividualEquipment, updatedOrder.Entitlement.OrganizationalClothingAndIndividualEquipment)
suite.EqualValues(payload.Agency, fetchedSM.Affiliation)
suite.Equal(*updatedOrder.Entitlement.DBAuthorizedWeight, 16000)
})

suite.Run("Updates the allowance when all fields are valid with dependents present and authorized", func() {
moveRouter := move.NewMoveRouter()
orderUpdater := NewOrderUpdater(moveRouter)
order := factory.BuildNeedsServiceCounselingMove(suite.DB(), nil, []factory.Trait{
factory.GetTraitHasDependents,
}).Orders

grade := ghcmessages.GradeO5
affiliation := ghcmessages.AffiliationAIRFORCE
ocie := false
proGearWeight := models.Int64Pointer(100)
proGearWeightSpouse := models.Int64Pointer(10)
rmeWeight := models.Int64Pointer(10000)
eTag := etag.GenerateEtag(order.UpdatedAt)

payload := ghcmessages.CounselingUpdateAllowancePayload{
Agency: &affiliation,
DependentsAuthorized: models.BoolPointer(true),
Grade: &grade,
OrganizationalClothingAndIndividualEquipment: &ocie,
ProGearWeight: proGearWeight,
ProGearWeightSpouse: proGearWeightSpouse,
RequiredMedicalEquipmentWeight: rmeWeight,
}

updatedOrder, _, err := orderUpdater.UpdateAllowanceAsCounselor(suite.AppContextForTest(), order.ID, payload, eTag)
suite.NoError(err)

var orderInDB models.Order
err = suite.DB().Find(&orderInDB, order.ID)

fetchedSM := models.ServiceMember{}
_ = suite.DB().Find(&fetchedSM, order.ServiceMember.ID)

suite.NoError(err)
suite.Equal(order.ID.String(), updatedOrder.ID.String())
suite.Equal(payload.DependentsAuthorized, updatedOrder.Entitlement.DependentsAuthorized)
suite.Equal(*payload.ProGearWeight, int64(updatedOrder.Entitlement.ProGearWeight))
suite.Equal(*payload.ProGearWeightSpouse, int64(updatedOrder.Entitlement.ProGearWeightSpouse))
suite.Equal(*payload.RequiredMedicalEquipmentWeight, int64(updatedOrder.Entitlement.RequiredMedicalEquipmentWeight))
suite.Equal(*payload.OrganizationalClothingAndIndividualEquipment, updatedOrder.Entitlement.OrganizationalClothingAndIndividualEquipment)
suite.EqualValues(payload.Agency, fetchedSM.Affiliation)
suite.Equal(*updatedOrder.Entitlement.DBAuthorizedWeight, 17500)
})

suite.Run("Updates the allowance when move needs service counseling and order fields are missing", func() {
Expand Down

0 comments on commit f65b2d8

Please sign in to comment.