From f65b2d8f3bdda6c2db239c688e045347078349a7 Mon Sep 17 00:00:00 2001 From: cameroncaci Date: Mon, 29 Jan 2024 15:45:34 +0000 Subject: [PATCH] added counselor update authorized weight allowance and added tests --- pkg/factory/order_factory.go | 15 ++++ pkg/services/order/order_updater.go | 10 +++ pkg/services/order/order_updater_test.go | 93 +++++++++++++++++++++++- 3 files changed, 116 insertions(+), 2 deletions(-) diff --git a/pkg/factory/order_factory.go b/pkg/factory/order_factory.go index 903c0c58dc4..8aa411954d4 100644 --- a/pkg/factory/order_factory.go +++ b/pkg/factory/order_factory.go @@ -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, + }, + }, + } +} diff --git a/pkg/services/order/order_updater.go b/pkg/services/order/order_updater.go index 14a823a0e63..7041cb9eee4 100644 --- a/pkg/services/order/order_updater.go +++ b/pkg/services/order/order_updater.go @@ -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 } diff --git a/pkg/services/order/order_updater_test.go b/pkg/services/order/order_updater_test.go index eff9a8302ca..8cf2a862d8d 100644 --- a/pkg/services/order/order_updater_test.go +++ b/pkg/services/order/order_updater_test.go @@ -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 @@ -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) }) } @@ -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 @@ -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() {