Skip to content

Commit

Permalink
Merge branch 'B-21569' into B-21569-INT
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengleason-caci committed Jan 22, 2025
2 parents 1025de9 + f7d0ccd commit 9b83c1c
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 17 deletions.
9 changes: 7 additions & 2 deletions pkg/handlers/ghcapi/internal/payloads/model_to_payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -1880,8 +1880,13 @@ func MTOServiceItemModel(s *models.MTOServiceItem, storer storage.FileStorer) *g
}
}
var sort *string = nil
if s.ReService.ReServiceItem != nil {
sort = s.ReService.ReServiceItem.Sort
if s.ReService.ReServiceItems != nil {
for _, reServiceItem := range *s.ReService.ReServiceItems {
if (s.MTOShipment.MarketCode == "" || s.MTOShipment.MarketCode == reServiceItem.MarketCode) && (s.MTOShipment.ShipmentType == "" || s.MTOShipment.ShipmentType == reServiceItem.ShipmentType) {
sort = reServiceItem.Sort
break
}
}
}
payload := &ghcmessages.MTOServiceItem{
ID: handlers.FmtUUID(s.ID),
Expand Down
6 changes: 5 additions & 1 deletion pkg/handlers/ghcapi/mto_service_items.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,11 @@ func (h ListMTOServiceItemsHandler) Handle(params mtoserviceitemop.ListMTOServic
query.NewQueryAssociation("SITDestinationFinalAddress"),
query.NewQueryAssociation("SITOriginHHGOriginalAddress"),
query.NewQueryAssociation("SITOriginHHGActualAddress"),
query.NewQueryAssociation("ReService.ReServiceItem.Sort"),
query.NewQueryAssociation("ReService.ReServiceItems.Sort"),
query.NewQueryAssociation("ReService.ReServiceItems.MarketCode"),
query.NewQueryAssociation("ReService.ReServiceItems.ShipmentType"),
query.NewQueryAssociation("MTOShipment.MarketCode"),
query.NewQueryAssociation("MTOShipment.ShipmentType"),
})

var serviceItems models.MTOServiceItems
Expand Down
103 changes: 90 additions & 13 deletions pkg/handlers/ghcapi/mto_service_items_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,12 @@ import (
)

func (suite *HandlerSuite) TestListMTOServiceItemHandler() {
reServiceID, _ := uuid.NewV4()
serviceItemID, _ := uuid.NewV4()
mtoShipmentID, _ := uuid.NewV4()
var mtoID uuid.UUID

setupTestData := func() (models.User, models.MTOServiceItems) {
setupTestData := func() (models.User, models.MTOServiceItems, uuid.UUID) {
reServiceID, _ := uuid.NewV4()
serviceItemID, _ := uuid.NewV4()
mtoShipmentID, _ := uuid.NewV4()
mto := factory.BuildMove(suite.DB(), nil, nil)
mtoID = mto.ID
reService := factory.FetchReService(suite.DB(), []factory.Customization{
{
Model: models.ReService{
Expand Down Expand Up @@ -130,6 +128,25 @@ func (suite *HandlerSuite) TestListMTOServiceItemHandler() {
},
}, nil)

serviceItems := models.MTOServiceItems{serviceItem, originSit, destinationSit}

return requestUser, serviceItems, mto.ID
}

setupIUBTestData := func() (models.User, models.MTOServiceItems, uuid.UUID) {
mtoShipmentID, _ := uuid.NewV4()
mto := factory.BuildMove(suite.DB(), nil, nil)
mtoShipment := factory.BuildMTOShipment(suite.DB(), []factory.Customization{
{
Model: models.MTOShipment{
ID: mtoShipmentID,
ShipmentType: models.MTOShipmentTypeUnaccompaniedBaggage,
MarketCode: models.MarketCodeInternational,
},
},
}, nil)
requestUser := factory.BuildUser(nil, nil, nil)

poeFsc := factory.BuildMTOServiceItem(suite.DB(), []factory.Customization{
{
Model: models.MTOServiceItem{
Expand All @@ -151,13 +168,34 @@ func (suite *HandlerSuite) TestListMTOServiceItemHandler() {
},
}, nil)

serviceItems := models.MTOServiceItems{serviceItem, originSit, destinationSit, poeFsc}
ubp := factory.BuildMTOServiceItem(suite.DB(), []factory.Customization{
{
Model: models.MTOServiceItem{
Status: models.MTOServiceItemStatusApproved,
},
},
{
Model: mto,
LinkOnly: true,
},
{
Model: mtoShipment,
LinkOnly: true,
},
{
Model: models.ReService{
Code: models.ReServiceCodeUBP,
},
},
}, nil)

return requestUser, serviceItems
serviceItems := models.MTOServiceItems{poeFsc, ubp}

return requestUser, serviceItems, mto.ID
}

suite.Run("Successful list fetch - Integration Test", func() {
requestUser, serviceItems := setupTestData()
requestUser, serviceItems, mtoID := setupTestData()
req := httptest.NewRequest("GET", fmt.Sprintf("/move_task_orders/%s/mto_service_items", mtoID.String()), nil)
req = suite.AuthenticateUserRequest(req, requestUser)

Expand Down Expand Up @@ -200,7 +238,7 @@ func (suite *HandlerSuite) TestListMTOServiceItemHandler() {
suite.NoError(okResponse.Payload.Validate(strfmt.Default))
fmt.Println(okResponse.Payload)

suite.Len(okResponse.Payload, 4)
suite.Len(okResponse.Payload, 3)
for _, serviceItem := range serviceItems {
for _, payload := range okResponse.Payload {
// Validate that the Customer Contacts were included in the payload
Expand All @@ -222,17 +260,56 @@ func (suite *HandlerSuite) TestListMTOServiceItemHandler() {
}
}
}
})

suite.Run("Successful sorted serviceItems for UB", func() {
requestUser, serviceItems, mtoID := setupIUBTestData()
req := httptest.NewRequest("GET", fmt.Sprintf("/move_task_orders/%s/mto_service_items", mtoID.String()), nil)
req = suite.AuthenticateUserRequest(req, requestUser)

params := mtoserviceitemop.ListMTOServiceItemsParams{
HTTPRequest: req,
MoveTaskOrderID: *handlers.FmtUUID(serviceItems[0].MoveTaskOrderID),
}

// Validate that sort field is populated for service items which have it (ie. POEFSC)
queryBuilder := query.NewQueryBuilder()
listFetcher := fetch.NewListFetcher(queryBuilder)
fetcher := fetch.NewFetcher(queryBuilder)
counselingPricer := ghcrateengine.NewCounselingServicesPricer()
moveManagementPricer := ghcrateengine.NewManagementServicesPricer()
handler := ListMTOServiceItemsHandler{
suite.createS3HandlerConfig(),
listFetcher,
fetcher,
counselingPricer,
moveManagementPricer,
}

// Validate incoming payload: no body to validate

response := handler.Handle(params)
suite.IsType(&mtoserviceitemop.ListMTOServiceItemsOK{}, response)
okResponse := response.(*mtoserviceitemop.ListMTOServiceItemsOK)

// Validate outgoing payload
suite.NoError(okResponse.Payload.Validate(strfmt.Default))
fmt.Println(okResponse.Payload)

suite.Len(okResponse.Payload, 2)
// Validate that sort field is populated for service items which have it.
// These test values can be updated to match any DB changes.
for _, payload := range okResponse.Payload {
if payload.ReServiceCode != nil && *payload.ReServiceCode == models.ReServiceCodePOEFSC.String() {
suite.Equal("2", *payload.Sort)
}
if payload.ReServiceCode != nil && *payload.ReServiceCode == models.ReServiceCodeUBP.String() {
suite.Equal("1", *payload.Sort)
}
}
})

suite.Run("Failure list fetch - Internal Server Error", func() {
requestUser, serviceItems := setupTestData()
requestUser, serviceItems, mtoID := setupTestData()
req := httptest.NewRequest("GET", fmt.Sprintf("/move_task_orders/%s/mto_service_items", mtoID.String()), nil)
req = suite.AuthenticateUserRequest(req, requestUser)

Expand Down Expand Up @@ -280,7 +357,7 @@ func (suite *HandlerSuite) TestListMTOServiceItemHandler() {
})

suite.Run("Failure list fetch - 404 Not Found - Move Task Order ID", func() {
requestUser, serviceItems := setupTestData()
requestUser, serviceItems, mtoID := setupTestData()
req := httptest.NewRequest("GET", fmt.Sprintf("/move_task_orders/%s/mto_service_items", mtoID.String()), nil)
req = suite.AuthenticateUserRequest(req, requestUser)

Expand Down
2 changes: 1 addition & 1 deletion pkg/models/re_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ type ReService struct {
Priority int `db:"priority" rw:"r"`
Name string `json:"name" db:"name" rw:"r"`
ServiceLocation *ServiceLocationType `db:"service_location" rw:"r"`
ReServiceItem *ReServiceItem `has_one:"re_service_item" fk_id:"service_id"`
ReServiceItems *ReServiceItems `has_many:"re_service_items" fk_id:"service_id"`
CreatedAt time.Time `json:"created_at" db:"created_at" rw:"r"`
UpdatedAt time.Time `json:"updated_at" db:"updated_at" rw:"r"`
}
Expand Down

0 comments on commit 9b83c1c

Please sign in to comment.