Skip to content

Commit

Permalink
Merge pull request #14346 from transcom/B-21359-INT
Browse files Browse the repository at this point in the history
B 21359 int - Backend: Assigned User Cleanup
  • Loading branch information
JonSpight authored Dec 30, 2024
2 parents b85e777 + 1e1340b commit fc0eafd
Show file tree
Hide file tree
Showing 13 changed files with 688 additions and 23 deletions.
42 changes: 34 additions & 8 deletions pkg/factory/move_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,6 @@ func BuildMove(db *pop.Connection, customs []Customization, traits []Trait) mode
closeoutOffice = BuildTransportationOffice(db, tempCloseoutOfficeCustoms, nil)
}

var counselingOffice models.TransportationOffice
tempCounselingOfficeCustoms := customs
counselingOfficeResult := findValidCustomization(customs, TransportationOffices.CounselingOffice)
if counselingOfficeResult != nil {
tempCounselingOfficeCustoms = convertCustomizationInList(tempCounselingOfficeCustoms, TransportationOffices.CounselingOffice, TransportationOffice)
counselingOffice = BuildTransportationOffice(db, tempCounselingOfficeCustoms, nil)
}

var scAssignedUser models.OfficeUser
tempSCAssignedUserCustoms := customs
scAssignedUserResult := findValidCustomization(customs, OfficeUsers.SCAssignedUser)
Expand All @@ -51,6 +43,30 @@ func BuildMove(db *pop.Connection, customs []Customization, traits []Trait) mode
scAssignedUser = BuildOfficeUser(db, tempSCAssignedUserCustoms, nil)
}

var tooAssignedUser models.OfficeUser
tempTOOAssignedUserCustoms := customs
tooAssignedUserResult := findValidCustomization(customs, OfficeUsers.TOOAssignedUser)
if tooAssignedUserResult != nil {
tempTOOAssignedUserCustoms = convertCustomizationInList(tempTOOAssignedUserCustoms, OfficeUsers.TOOAssignedUser, OfficeUser)
tooAssignedUser = BuildOfficeUser(db, tempTOOAssignedUserCustoms, nil)
}

var tioAssignedUser models.OfficeUser
tempTIOAssignedUserCustoms := customs
tioAssignedUserResult := findValidCustomization(customs, OfficeUsers.TIOAssignedUser)
if tioAssignedUserResult != nil {
tempTIOAssignedUserCustoms = convertCustomizationInList(tempTIOAssignedUserCustoms, OfficeUsers.TIOAssignedUser, OfficeUser)
tioAssignedUser = BuildOfficeUser(db, tempTIOAssignedUserCustoms, nil)
}

var counselingOffice models.TransportationOffice
tempCounselingOfficeCustoms := customs
counselingOfficeResult := findValidCustomization(customs, TransportationOffices.CounselingOffice)
if counselingOfficeResult != nil {
tempCounselingOfficeCustoms = convertCustomizationInList(tempCounselingOfficeCustoms, TransportationOffices.CounselingOffice, TransportationOffice)
counselingOffice = BuildTransportationOffice(db, tempCounselingOfficeCustoms, nil)
}

var defaultReferenceID string
var err error
if db != nil {
Expand Down Expand Up @@ -89,6 +105,16 @@ func BuildMove(db *pop.Connection, customs []Customization, traits []Trait) mode
move.CloseoutOfficeID = &closeoutOffice.ID
}

if tooAssignedUserResult != nil {
move.TOOAssignedUser = &tooAssignedUser
move.TOOAssignedID = &tooAssignedUser.ID
}

if tioAssignedUserResult != nil {
move.TIOAssignedUser = &tioAssignedUser
move.TIOAssignedID = &tioAssignedUser.ID
}

if counselingOfficeResult != nil {
move.CounselingOffice = &counselingOffice
move.CounselingOfficeID = &counselingOffice.ID
Expand Down
53 changes: 53 additions & 0 deletions pkg/factory/move_factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,59 @@ func (suite *FactorySuite) TestBuildMove() {
suite.NotEmpty(move.MTOShipments)
suite.Equal(models.MTOShipmentStatusSubmitted, move.MTOShipments[0].Status)
})
suite.Run("Successful creation of a move with an assigned SC", func() {
officeUser := BuildOfficeUserWithRoles(suite.DB(), nil, []roles.RoleType{roles.RoleTypeServicesCounselor})

move := BuildMoveWithShipment(suite.DB(), []Customization{
{
Model: models.Move{
Status: models.MoveStatusAPPROVED,
},
},
{
Model: officeUser,
LinkOnly: true,
Type: &OfficeUsers.SCAssignedUser,
},
}, nil)
suite.Equal(officeUser.ID, *move.SCAssignedID)
})

suite.Run("Successful creation of a move with an assigned TOO", func() {
officeUser := BuildOfficeUserWithRoles(suite.DB(), nil, []roles.RoleType{roles.RoleTypeTOO})

move := BuildMoveWithShipment(suite.DB(), []Customization{
{
Model: models.Move{
Status: models.MoveStatusAPPROVED,
},
},
{
Model: officeUser,
LinkOnly: true,
Type: &OfficeUsers.TOOAssignedUser,
},
}, nil)
suite.Equal(officeUser.ID, *move.TOOAssignedID)
})

suite.Run("Successful creation of a move with an assigned TIO", func() {
officeUser := BuildOfficeUserWithRoles(suite.DB(), nil, []roles.RoleType{roles.RoleTypeTIO})

move := BuildMoveWithShipment(suite.DB(), []Customization{
{
Model: models.Move{
Status: models.MoveStatusAPPROVED,
},
},
{
Model: officeUser,
LinkOnly: true,
Type: &OfficeUsers.TIOAssignedUser,
},
}, nil)
suite.Equal(officeUser.ID, *move.TIOAssignedID)
})

suite.Run("Successful creation of customized move with shipment", func() {
// Under test: BuildMoveWithShipment
Expand Down
8 changes: 6 additions & 2 deletions pkg/factory/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,15 @@ var TransportationOffices = transportationOfficeGroup{
}

type officeUserGroup struct {
SCAssignedUser CustomType
SCAssignedUser CustomType
TIOAssignedUser CustomType
TOOAssignedUser CustomType
}

var OfficeUsers = officeUserGroup{
SCAssignedUser: "SCAssignedUser",
SCAssignedUser: "SCAssignedUser",
TIOAssignedUser: "TIOAssignedUser",
TOOAssignedUser: "TOOAssignedUser",
}

// uploadGroup is a grouping of all the upload related fields
Expand Down
163 changes: 161 additions & 2 deletions pkg/handlers/ghcapi/internal/payloads/model_to_payload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,98 @@ import (
"github.com/transcom/mymove/pkg/models"
"github.com/transcom/mymove/pkg/models/roles"
"github.com/transcom/mymove/pkg/storage/test"
"github.com/transcom/mymove/pkg/unit"
)

func TestOrder(_ *testing.T) {
order := &models.Order{}
Order(order)
}

func (suite *PayloadsSuite) TestOrderWithMove() {
move := factory.BuildMove(suite.DB(), nil, nil)
moves := models.Moves{}
moves = append(moves, move)
order := factory.BuildOrder(nil, []factory.Customization{
{
Model: models.Order{
ID: uuid.Must(uuid.NewV4()),
HasDependents: *models.BoolPointer(true),
Moves: moves,
},
},
}, nil)
Order(&order)
}

func (suite *PayloadsSuite) TestBoatShipment() {
boat := factory.BuildBoatShipment(suite.DB(), nil, nil)
boatShipment := BoatShipment(nil, &boat)
suite.NotNil(boatShipment)

}

func (suite *PayloadsSuite) TestMobileHomeShipment() {
mobileHome := factory.BuildMobileHomeShipment(suite.DB(), nil, nil)
mobileHomeShipment := MobileHomeShipment(nil, &mobileHome)
suite.NotNil(mobileHomeShipment)
}

func (suite *PayloadsSuite) TestMovingExpense() {
contractExpense := models.MovingExpenseReceiptTypeContractedExpense
weightStored := 2000
sitLocation := models.SITLocationTypeDestination
sitReimburseableAmount := 500

movingExpense := models.MovingExpense{
PPMShipmentID: uuid.Must(uuid.NewV4()),
DocumentID: uuid.Must(uuid.NewV4()),
MovingExpenseType: &contractExpense,
Reason: models.StringPointer("no good"),
SITStartDate: models.TimePointer(time.Now()),
SITEndDate: models.TimePointer(time.Now()),
WeightStored: (*unit.Pound)(&weightStored),
SITLocation: &sitLocation,
SITReimburseableAmount: (*unit.Cents)(&sitReimburseableAmount),
}
movingExpenseValues := MovingExpense(nil, &movingExpense)
suite.NotNil(movingExpenseValues)
}

func (suite *PayloadsSuite) TestMovingExpenses() {
contractExpense := models.MovingExpenseReceiptTypeContractedExpense
weightStored := 2000
sitLocation := models.SITLocationTypeDestination
sitReimburseableAmount := 500
movingExpenses := models.MovingExpenses{}

movingExpense := models.MovingExpense{
PPMShipmentID: uuid.Must(uuid.NewV4()),
DocumentID: uuid.Must(uuid.NewV4()),
MovingExpenseType: &contractExpense,
Reason: models.StringPointer("no good"),
SITStartDate: models.TimePointer(time.Now()),
SITEndDate: models.TimePointer(time.Now()),
WeightStored: (*unit.Pound)(&weightStored),
SITLocation: &sitLocation,
SITReimburseableAmount: (*unit.Cents)(&sitReimburseableAmount),
}
movingExpenseTwo := models.MovingExpense{
PPMShipmentID: uuid.Must(uuid.NewV4()),
DocumentID: uuid.Must(uuid.NewV4()),
MovingExpenseType: &contractExpense,
Reason: models.StringPointer("no good"),
SITStartDate: models.TimePointer(time.Now()),
SITEndDate: models.TimePointer(time.Now()),
WeightStored: (*unit.Pound)(&weightStored),
SITLocation: &sitLocation,
SITReimburseableAmount: (*unit.Cents)(&sitReimburseableAmount),
}
movingExpenses = append(movingExpenses, movingExpense, movingExpenseTwo)
movingExpensesValue := MovingExpenses(nil, movingExpenses)
suite.NotNil(movingExpensesValue)
}

// TestMove makes sure zero values/optional fields are handled
func TestMove(t *testing.T) {
_, err := Move(&models.Move{}, &test.FakeS3Storage{})
Expand Down Expand Up @@ -661,6 +746,81 @@ func (suite *PayloadsSuite) TestCreateCustomer() {
})
}

func (suite *PayloadsSuite) TestMoveTaskOrder() {
move := factory.BuildMove(suite.DB(), nil, nil)
moveTaskOrder := MoveTaskOrder(&move)
suite.NotNil(moveTaskOrder)
}

func (suite *PayloadsSuite) TestTransportationOffice() {
office := factory.BuildTransportationOffice(suite.DB(), []factory.Customization{
{
Model: models.TransportationOffice{
ID: uuid.Must(uuid.NewV4()),
},
}}, nil)
transportationOffice := TransportationOffice(&office)
suite.NotNil(transportationOffice)
}
func (suite *PayloadsSuite) TestTransportationOffices() {
office := factory.BuildTransportationOffice(suite.DB(), []factory.Customization{
{
Model: models.TransportationOffice{
ID: uuid.Must(uuid.NewV4()),
},
}}, nil)
officeTwo := factory.BuildTransportationOffice(suite.DB(), []factory.Customization{
{
Model: models.TransportationOffice{
ID: uuid.Must(uuid.NewV4()),
},
}}, nil)
transportationOfficeList := models.TransportationOffices{}
transportationOfficeList = append(transportationOfficeList, office, officeTwo)
value := TransportationOffices(transportationOfficeList)
suite.NotNil(value)
}
func (suite *PayloadsSuite) TestListMove() {

marines := models.AffiliationMARINES
listMove := ListMove(nil)

suite.Nil(listMove)
moveUSMC := factory.BuildMove(suite.DB(), []factory.Customization{
{
Model: models.ServiceMember{
Affiliation: &marines,
},
},
}, nil)

listMove = ListMove(&moveUSMC)
suite.NotNil(listMove)
}

func (suite *PayloadsSuite) TestListMoves() {
list := models.Moves{}

marines := models.AffiliationMARINES
spaceForce := models.AffiliationSPACEFORCE
moveUSMC := factory.BuildMove(suite.DB(), []factory.Customization{
{
Model: models.ServiceMember{
Affiliation: &marines,
},
},
}, nil)
moveSF := factory.BuildMove(suite.DB(), []factory.Customization{
{
Model: models.ServiceMember{
Affiliation: &spaceForce,
},
},
}, nil)
list = append(list, moveUSMC, moveSF)
value := ListMoves(&list)
suite.NotNil(value)
}
func (suite *PayloadsSuite) TestSearchMoves() {
appCtx := suite.AppContextForTest()

Expand All @@ -672,9 +832,8 @@ func (suite *PayloadsSuite) TestSearchMoves() {
},
},
}, nil)

moves := models.Moves{moveUSMC}
suite.Run("Success - Returns a ghcmessages Upload payload from Upload Struct", func() {
suite.Run("Success - Returns a ghcmessages Upload payload from Upload Struct Marine move with no shipments", func() {
payload := SearchMoves(appCtx, moves)

suite.IsType(payload, &ghcmessages.SearchMoves{})
Expand Down
25 changes: 16 additions & 9 deletions pkg/handlers/ghcapi/payment_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,17 +228,25 @@ func (suite *HandlerSuite) TestGetPaymentRequestsForMoveHandler() {

func (suite *HandlerSuite) TestUpdatePaymentRequestStatusHandler() {
paymentRequestID, _ := uuid.FromString("00000000-0000-0000-0000-000000000001")
officeUserUUID, _ := uuid.NewV4()

setupTestData := func() models.OfficeUser {
officeUser := factory.BuildOfficeUser(nil, []factory.Customization{
{Model: models.OfficeUser{
ID: officeUserUUID,
}},

transportationOffice := factory.BuildTransportationOffice(suite.DB(), []factory.Customization{
{
Model: models.TransportationOffice{
ProvidesCloseout: true,
},
},
}, nil)
officeUser.User.Roles = append(officeUser.User.Roles, roles.Role{
RoleType: roles.RoleTypeTIO,
})

officeUser := factory.BuildOfficeUserWithRoles(suite.DB(), []factory.Customization{
{
Model: transportationOffice,
LinkOnly: true,
Type: &factory.TransportationOffices.CloseoutOffice,
},
}, []roles.RoleType{roles.RoleTypeTIO})

return officeUser
}
paymentRequest := models.PaymentRequest{
Expand All @@ -250,7 +258,6 @@ func (suite *HandlerSuite) TestUpdatePaymentRequestStatusHandler() {
}

statusUpdater := paymentrequest.NewPaymentRequestStatusUpdater(query.NewQueryBuilder())

suite.Run("successful status update of payment request", func() {
officeUser := setupTestData()
pendingPaymentRequest := factory.BuildPaymentRequest(suite.DB(), nil, nil)
Expand Down
Loading

0 comments on commit fc0eafd

Please sign in to comment.