Skip to content

Commit

Permalink
Merge pull request #11909 from transcom/B-18491-update-endpoint-updat…
Browse files Browse the repository at this point in the history
…eMTOServiceItem-MAIN

B 18491 update endpoint for updateMTOServiceItem MAIN
  • Loading branch information
deandreJones authored Feb 12, 2024
2 parents 3e2a37e + 6955598 commit 6df3d24
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 29 deletions.
4 changes: 2 additions & 2 deletions pkg/gen/primeapi/embedded_spec.go

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

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

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

9 changes: 5 additions & 4 deletions pkg/services/mto_service_item/mto_service_item_validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,15 +377,16 @@ func (v *updateMTOServiceItemData) checkSITDestinationFinalAddress(_ appcontext.
return nil // the SITDestinationFinalAddress is being created, so we're fine here
}

if v.oldServiceItem.ReService.Code != models.ReServiceCodeDDDSIT {
return apperror.NewConflictError(v.updatedServiceItem.ID,
fmt.Sprintf("- SIT Destination Final Address may only be manually created for %s service items.", models.ReServiceCodeDDDSIT))
reServiceCodesDestination := []models.ReServiceCode{models.ReServiceCodeDDDSIT, models.ReServiceCodeDDASIT, models.ReServiceCodeDDFSIT, models.ReServiceCodeDDSFSC}
if slices.Contains(reServiceCodesDestination, v.oldServiceItem.ReService.Code) {
v.verrs.Add("SITDestinationFinalAddress", "Update the shipment destination address to update the service item's SIT final destination address.")
return nil
}

if *v.oldServiceItem.SITDestinationFinalAddressID != uuid.Nil &&
v.updatedServiceItem.SITDestinationFinalAddress != nil &&
v.updatedServiceItem.SITDestinationFinalAddress.ID != *v.oldServiceItem.SITDestinationFinalAddressID {
v.verrs.Add("SITDestinationFinalAddress", "cannot be updated")
v.verrs.Add("SITDestinationFinalAddress", "Update the shipment destination address to update the service item's SIT final destination address.")
}

return nil
Expand Down
84 changes: 77 additions & 7 deletions pkg/services/mto_service_item/mto_service_item_validators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,15 +613,15 @@ func (suite *MTOServiceItemServiceSuite) TestUpdateMTOServiceItemData() {
}
})

suite.Run("checkSITDestinationFinalAddress - adding SITDestinationFinalAddress", func() {
suite.Run("checkSITDestinationFinalAddress - adding SITDestinationFinalAddress for origin SIT service item", func() {
oldServiceItemPrime := factory.BuildMTOServiceItem(suite.DB(), []factory.Customization{
{
Model: factory.BuildAvailableToPrimeMove(suite.DB(), nil, nil),
LinkOnly: true,
},
{
Model: models.ReService{
Code: models.ReServiceCodeDDDSIT,
Code: models.ReServiceCodeDOPSIT,
},
},
}, nil)
Expand All @@ -642,7 +642,7 @@ func (suite *MTOServiceItemServiceSuite) TestUpdateMTOServiceItemData() {
suite.NoError(err)
})

suite.Run("checkSITDestinationFinalAddress - invalid input failure: SITDestinationFinalAddress", func() {
suite.Run("checkSITDestinationFinalAddress - invalid input failure: updating SITDestinationFinalAddress for DDASIT", func() {
oldServiceItemPrime := factory.BuildMTOServiceItem(suite.DB(), []factory.Customization{
{
Model: factory.BuildAvailableToPrimeMove(suite.DB(), nil, nil),
Expand Down Expand Up @@ -672,12 +672,12 @@ func (suite *MTOServiceItemServiceSuite) TestUpdateMTOServiceItemData() {
}
err := serviceItemData.checkSITDestinationFinalAddress(suite.AppContextForTest())

suite.Error(err)
conflictError := apperror.ConflictError{}
suite.IsType(conflictError, err)
suite.NoError(err)
suite.True(serviceItemData.verrs.HasAny())
suite.Contains(serviceItemData.verrs.Keys(), "SITDestinationFinalAddress")
})

suite.Run("checkSITDestinationFinalAddress - invalid input failure: SITDestinationFinalAddress", func() {
suite.Run("checkSITDestinationFinalAddress - invalid input failure: updating SITDestinationFinalAddress for DDDSIT ", func() {
oldServiceItemPrime := factory.BuildMTOServiceItem(suite.DB(), []factory.Customization{
{
Model: factory.BuildAvailableToPrimeMove(suite.DB(), nil, nil),
Expand Down Expand Up @@ -712,6 +712,76 @@ func (suite *MTOServiceItemServiceSuite) TestUpdateMTOServiceItemData() {
suite.Contains(serviceItemData.verrs.Keys(), "SITDestinationFinalAddress")
})

suite.Run("checkSITDestinationFinalAddress - invalid input failure: updating SITDestinationFinalAddress for DDFSIT ", func() {
oldServiceItemPrime := factory.BuildMTOServiceItem(suite.DB(), []factory.Customization{
{
Model: factory.BuildAvailableToPrimeMove(suite.DB(), nil, nil),
LinkOnly: true,
},
{
Model: models.Address{},
Type: &factory.Addresses.SITDestinationFinalAddress,
},
{
Model: models.ReService{
Code: models.ReServiceCodeDDFSIT,
},
},
}, nil)
newServiceItemPrime := oldServiceItemPrime

// Try to update SITDestinationFinalAddress
newAddress := factory.BuildAddress(suite.DB(), nil, []factory.Trait{factory.GetTraitAddress3})
newServiceItemPrime.SITDestinationFinalAddress = &newAddress

serviceItemData := updateMTOServiceItemData{
updatedServiceItem: newServiceItemPrime,
oldServiceItem: oldServiceItemPrime,
verrs: validate.NewErrors(),
availabilityChecker: checker,
}
err := serviceItemData.checkSITDestinationFinalAddress(suite.AppContextForTest())

suite.NoError(err)
suite.True(serviceItemData.verrs.HasAny())
suite.Contains(serviceItemData.verrs.Keys(), "SITDestinationFinalAddress")
})

suite.Run("checkSITDestinationFinalAddress - invalid input failure: updating SITDestinationFinalAddress for DDSFSC ", func() {
oldServiceItemPrime := factory.BuildMTOServiceItem(suite.DB(), []factory.Customization{
{
Model: factory.BuildAvailableToPrimeMove(suite.DB(), nil, nil),
LinkOnly: true,
},
{
Model: models.Address{},
Type: &factory.Addresses.SITDestinationFinalAddress,
},
{
Model: models.ReService{
Code: models.ReServiceCodeDDSFSC,
},
},
}, nil)
newServiceItemPrime := oldServiceItemPrime

// Try to update SITDestinationFinalAddress
newAddress := factory.BuildAddress(suite.DB(), nil, []factory.Trait{factory.GetTraitAddress3})
newServiceItemPrime.SITDestinationFinalAddress = &newAddress

serviceItemData := updateMTOServiceItemData{
updatedServiceItem: newServiceItemPrime,
oldServiceItem: oldServiceItemPrime,
verrs: validate.NewErrors(),
availabilityChecker: checker,
}
err := serviceItemData.checkSITDestinationFinalAddress(suite.AppContextForTest())

suite.NoError(err)
suite.True(serviceItemData.verrs.HasAny())
suite.Contains(serviceItemData.verrs.Keys(), "SITDestinationFinalAddress")
})

suite.Run("checkSITDestinationOriginalAddress - invalid input failure: adding SITDestinationOriginalAddress", func() {
oldServiceItemPrime := factory.BuildMTOServiceItem(suite.DB(), []factory.Customization{
{
Expand Down
7 changes: 4 additions & 3 deletions swagger-def/prime.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -995,10 +995,11 @@ paths:
This endpoint supports different body definitions. In the modelType field below, select the modelType corresponding
to the service item you wish to update and the documentation will update with the new definition.
* Addresses: You can add a new SIT Destination final address using this endpoint (and must use this endpoint to do so), but you cannot update an existing one.
Please use [createSITAddressUpdateRequest](#operation/createSITAddressUpdateRequest) instead.
* Addresses: To update a destination service item's SIT destination final address, update the shipment destination address.
For approved shipments, please use [updateShipmentDestinationAddress](#mtoShipment/updateShipmentDestinationAddress).
For shipments not yet approved, please use [updateMTOShipmentAddress](#mtoShipment/updateMTOShipmentAddress).
To create a service item, please use [createMTOServiceItem](#operation/createMTOServiceItem)) endpoint.
To create a service item, please use [createMTOServiceItem](#mtoServiceItem/createMTOServiceItem)) endpoint.
operationId: updateMTOServiceItem
tags:
- mtoServiceItem
Expand Down
15 changes: 8 additions & 7 deletions swagger/prime.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1188,17 +1188,18 @@ paths:
field below, select the modelType corresponding
to the service item you wish to update and the documentation will update with the new definition.
* Addresses: You can add a new SIT Destination final address using this
endpoint (and must use this endpoint to do so), but you cannot update an
existing one.
* Addresses: To update a destination service item's SIT destination
final address, update the shipment destination address.
Please use
[createSITAddressUpdateRequest](#operation/createSITAddressUpdateRequest)
instead.
For approved shipments, please use
[updateShipmentDestinationAddress](#mtoShipment/updateShipmentDestinationAddress).
For shipments not yet approved, please use
[updateMTOShipmentAddress](#mtoShipment/updateMTOShipmentAddress).
To create a service item, please use
[createMTOServiceItem](#operation/createMTOServiceItem)) endpoint.
[createMTOServiceItem](#mtoServiceItem/createMTOServiceItem)) endpoint.
operationId: updateMTOServiceItem
tags:
- mtoServiceItem
Expand Down

0 comments on commit 6df3d24

Please sign in to comment.