Skip to content

Commit

Permalink
Merge branch 'main' of github.com:transcom/mymove into MAIN-B-22056_s…
Browse files Browse the repository at this point in the history
…ns_sqs_deps_w_endpoint
  • Loading branch information
ryan-mchugh committed Jan 29, 2025
2 parents 55767df + 0b4d856 commit bd4f373
Show file tree
Hide file tree
Showing 18 changed files with 574 additions and 31 deletions.
1 change: 1 addition & 0 deletions migrations/app/migrations_manifest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,7 @@
20250110001339_update_nts_release_enum_name.up.sql
20250110153428_add_shipment_address_updates_to_move_history.up.sql
20250110214012_homesafeconnect_cert.up.sql
20250113152050_rename_ubp.up.sql
20250113201232_update_estimated_pricing_procs_add_is_peak_func.up.sql
20250116200912_disable_homesafe_stg_cert.up.sql
20250120144247_update_pricing_proc_to_use_110_percent_weight.up.sql
1 change: 1 addition & 0 deletions migrations/app/schema/20250113152050_rename_ubp.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
update re_services set name = 'International UB price' where code = 'UBP';
10 changes: 10 additions & 0 deletions pkg/gen/ghcapi/embedded_spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pkg/gen/ghcmessages/m_t_o_service_item.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions pkg/handlers/ghcapi/internal/payloads/model_to_payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -1861,6 +1861,15 @@ func MTOServiceItemModel(s *models.MTOServiceItem, storer storage.FileStorer) *g
serviceRequestDocs[i] = payload
}
}
var sort *string
if s.ReService.ReServiceItems != nil {
for _, reServiceItem := range *s.ReService.ReServiceItems {
if s.MTOShipment.MarketCode == reServiceItem.MarketCode && s.MTOShipment.ShipmentType == reServiceItem.ShipmentType {
sort = reServiceItem.Sort
break
}
}
}
payload := &ghcmessages.MTOServiceItem{
ID: handlers.FmtUUID(s.ID),
MoveTaskOrderID: handlers.FmtUUID(s.MoveTaskOrderID),
Expand All @@ -1876,6 +1885,7 @@ func MTOServiceItemModel(s *models.MTOServiceItem, storer storage.FileStorer) *g
SitDepartureDate: handlers.FmtDateTimePtr(s.SITDepartureDate),
SitCustomerContacted: handlers.FmtDatePtr(s.SITCustomerContacted),
SitRequestedDelivery: handlers.FmtDatePtr(s.SITRequestedDelivery),
Sort: sort,
Status: ghcmessages.MTOServiceItemStatus(s.Status),
Description: handlers.FmtStringPtr(s.Description),
Dimensions: MTOServiceItemDimensions(s.Dimensions),
Expand Down
45 changes: 45 additions & 0 deletions pkg/handlers/ghcapi/internal/payloads/model_to_payload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1218,6 +1218,51 @@ func (suite *PayloadsSuite) TestMTOServiceItemModel() {
suite.NotNil(result, "Expected result to not be nil for valid MTOServiceItem")
suite.Equal(handlers.FmtString(models.MarketOconus.FullString()), result.Market, "Expected Market to be OCONUS")
})

suite.Run("sets Sort from correct serviceItem", func() {
reServiceID := uuid.Must(uuid.NewV4())

reServiceItems := make(models.ReServiceItems, 3)
mockReService := models.ReService{
ID: reServiceID,
Code: models.ReServiceCodeUBP,
Name: "Test ReService",
ReServiceItems: &reServiceItems,
}

mockMTOShipment := models.MTOShipment{
ShipmentType: models.MTOShipmentTypeUnaccompaniedBaggage,
MarketCode: models.MarketCodeInternational,
}

reServiceItems[0] = models.ReServiceItem{
ReService: mockReService,
ShipmentType: models.MTOShipmentTypeHHG,
MarketCode: models.MarketCodeInternational,
Sort: models.StringPointer("0"),
}
reServiceItems[1] = models.ReServiceItem{
ReService: mockReService,
ShipmentType: models.MTOShipmentTypeUnaccompaniedBaggage,
MarketCode: models.MarketCodeInternational,
Sort: models.StringPointer("1"),
}
reServiceItems[2] = models.ReServiceItem{
ReService: mockReService,
ShipmentType: models.MTOShipmentTypeUnaccompaniedBaggage,
MarketCode: models.MarketCodeDomestic,
Sort: models.StringPointer("2"),
}

mockMtoServiceItem := models.MTOServiceItem{
ReService: mockReService,
MTOShipment: mockMTOShipment,
}

result := MTOServiceItemModel(&mockMtoServiceItem, suite.storer)
suite.NotNil(result, "Expected result to not be nil for valid MTOServiceItem")
suite.Equal("1", *result.Sort, "Expected to get the Sort value by matching the correct ReServiceItem using ShipmentType and MarketCode.")
})
}

func (suite *PayloadsSuite) TestMTOShipment() {
Expand Down
2 changes: 2 additions & 0 deletions pkg/handlers/ghcapi/mto_service_items.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ func (h ListMTOServiceItemsHandler) Handle(params mtoserviceitemop.ListMTOServic
query.NewQueryAssociation("SITDestinationFinalAddress"),
query.NewQueryAssociation("SITOriginHHGOriginalAddress"),
query.NewQueryAssociation("SITOriginHHGActualAddress"),
query.NewQueryAssociation("ReService.ReServiceItems"),
query.NewQueryAssociation("MTOShipment"),
})

var serviceItems models.MTOServiceItems
Expand Down
131 changes: 112 additions & 19 deletions pkg/handlers/ghcapi/mto_service_items_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,33 +39,21 @@ 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) {
mto := factory.BuildMove(suite.DB(), nil, nil)
mtoID = mto.ID
reService := factory.FetchReService(suite.DB(), []factory.Customization{
{
Model: models.ReService{
ID: reServiceID,
Code: "TEST10000",
},
},
}, nil)
mtoShipment := factory.BuildMTOShipment(suite.DB(), []factory.Customization{
{
Model: models.MTOShipment{ID: mtoShipmentID},
},
}, nil)
mtoShipment := factory.BuildMTOShipment(suite.DB(), nil, nil)
requestUser := factory.BuildUser(nil, nil, nil)
serviceItem := factory.BuildMTOServiceItem(suite.DB(), []factory.Customization{
{
Model: models.MTOServiceItem{
ID: serviceItemID,
},
Model: models.MTOServiceItem{},
},
{
Model: mto,
Expand Down Expand Up @@ -132,11 +120,70 @@ func (suite *HandlerSuite) TestListMTOServiceItemHandler() {

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

return requestUser, serviceItems
return requestUser, serviceItems, mto.ID
}

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

poeFsc := 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.ReServiceCodePOEFSC,
},
},
}, nil)

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)

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 @@ -203,8 +250,54 @@ 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),
}

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 @@ -252,7 +345,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
3 changes: 2 additions & 1 deletion pkg/models/re_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const (
ReServiceCodeNSTH ReServiceCode = "NSTH"
// ReServiceCodeNSTUB Nonstandard UB
ReServiceCodeNSTUB ReServiceCode = "NSTUB"
// ReServiceCodeUBP International UB
// ReServiceCodeUBP International UB price
ReServiceCodeUBP ReServiceCode = "UBP"
// ReServiceCodeISLH Shipping & Linehaul
ReServiceCodeISLH ReServiceCode = "ISLH"
Expand Down Expand Up @@ -147,6 +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"`
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
Loading

0 comments on commit bd4f373

Please sign in to comment.