Skip to content

Commit

Permalink
updating validation message, adding validation to address update as w…
Browse files Browse the repository at this point in the history
…ell, tests
  • Loading branch information
danieljordan-caci committed Oct 14, 2024
1 parent 602e960 commit 3dbd8ef
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/services/address/address_creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (f *addressCreator) CreateAddress(appCtx appcontext.AppContext, address *mo

// until international moves are supported, we will default the country for created addresses to "US"
if address.Country != nil && address.Country.Country != "US" {
return nil, fmt.Errorf("- the country %s is not supported at this time", address.Country.Country)
return nil, fmt.Errorf("- the country %s is not supported at this time - only US is allowed", address.Country.Country)
}

if address.Country != nil && address.Country.Country != "" {
Expand Down
2 changes: 1 addition & 1 deletion pkg/services/address/address_creator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (suite *AddressSuite) TestAddressCreator() {

suite.Error(err)
suite.Nil(address)
suite.Equal("- the country GB is not supported at this time", err.Error())
suite.Equal("- the country GB is not supported at this time - only US is allowed", err.Error())
})

suite.Run("Successfully creates an address with empty strings for optional fields", func() {
Expand Down
6 changes: 6 additions & 0 deletions pkg/services/address/address_updater.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package address

import (
"fmt"

"github.com/transcom/mymove/pkg/appcontext"
"github.com/transcom/mymove/pkg/apperror"
"github.com/transcom/mymove/pkg/etag"
Expand Down Expand Up @@ -47,6 +49,10 @@ func (f *addressUpdater) UpdateAddress(appCtx appcontext.AppContext, address *mo
return nil, err
}

// until international moves are supported, we will default the country for created addresses to "US"
if mergedAddress.Country != nil && mergedAddress.Country.Country != "US" {
return nil, fmt.Errorf("- the country %s is not supported at this time - only US is allowed", mergedAddress.Country.Country)
}
// first we will check to see if the country values have changed at all
// until international moves are supported, we will default the country for created addresses to "US"
if mergedAddress.Country != nil && mergedAddress.Country.Country != "" && mergedAddress.Country != originalAddress.Country {
Expand Down
38 changes: 38 additions & 0 deletions pkg/services/address/address_updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,42 @@ func (suite *AddressSuite) TestAddressUpdater() {
expectedError := fmt.Sprintf("Data received from requester is bad: %s: invalid ID used for address", apperror.BadDataCode)
suite.Equal(expectedError, err.Error())
})

suite.Run("Able to update when providing US country value in updated address", func() {
originalAddress := createOriginalAddress()
addressUpdater := NewAddressUpdater()

desiredAddress := &models.Address{
ID: originalAddress.ID,
StreetAddress1: streetAddress1,
City: city,
State: state,
PostalCode: postalCode,
Country: &models.Country{Country: "US"},
}
updatedAddress, err := addressUpdater.UpdateAddress(suite.AppContextForTest(), desiredAddress, etag.GenerateEtag(originalAddress.UpdatedAt))

suite.NoError(err)
suite.NotNil(updatedAddress)
suite.Equal(updatedAddress.Country.Country, "US")
})

suite.Run("Receives an error when trying to update to an international address", func() {
originalAddress := createOriginalAddress()
addressUpdater := NewAddressUpdater()

desiredAddress := &models.Address{
ID: originalAddress.ID,
StreetAddress1: streetAddress1,
City: city,
State: state,
PostalCode: postalCode,
Country: &models.Country{Country: "GB"},
}
updatedAddress, err := addressUpdater.UpdateAddress(suite.AppContextForTest(), desiredAddress, etag.GenerateEtag(originalAddress.UpdatedAt))

suite.Error(err)
suite.Nil(updatedAddress)
suite.Equal("- the country GB is not supported at this time - only US is allowed", err.Error())
})
}

0 comments on commit 3dbd8ef

Please sign in to comment.