Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APP-7522: Adding handling the address for billing config #4758

Merged
merged 2 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions cli/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ func (c *viamClient) updateBillingServiceAction(cCtx *cli.Context, orgID, addres
printf(cCtx.App.Writer, "City: %s", address.GetCity())
printf(cCtx.App.Writer, "State: %s", address.GetState())
printf(cCtx.App.Writer, "Postal Code: %s", address.GetZipcode())
printf(cCtx.App.Writer, "Country: USA")
printf(cCtx.App.Writer, "Country: %s", address.GetCountry())
return nil
}

Expand Down Expand Up @@ -375,7 +375,10 @@ func (c *viamClient) getBillingConfig(cCtx *cli.Context, orgID string) error {
printf(cCtx.App.Writer, "City: %s", resp.BillingAddress.GetCity())
printf(cCtx.App.Writer, "State: %s", resp.BillingAddress.GetState())
printf(cCtx.App.Writer, "Postal Code: %s", resp.BillingAddress.GetZipcode())
printf(cCtx.App.Writer, "Country: %s", "USA")
if resp.BillingAddress.GetCountry() != "" {
printf(cCtx.App.Writer, "Country: %s", resp.BillingAddress.GetCountry())
}

return nil
}

Expand Down
7 changes: 4 additions & 3 deletions cli/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ func TestGetBillingConfigAction(t *testing.T) {
City: "San Francisco",
State: "CA",
Zipcode: "94105",
Country: "United States",
},
LogoUrl: "https://logo.com",
BillingDashboardUrl: "https://app.viam.dev/my-dashboard",
Expand All @@ -289,7 +290,7 @@ func TestGetBillingConfigAction(t *testing.T) {
test.That(t, out.messages[8], test.ShouldContainSubstring, "San Francisco")
test.That(t, out.messages[9], test.ShouldContainSubstring, "CA")
test.That(t, out.messages[10], test.ShouldContainSubstring, "94105")
test.That(t, out.messages[11], test.ShouldContainSubstring, "USA")
test.That(t, out.messages[11], test.ShouldContainSubstring, "United States")
}

func TestOrganizationSetLogoAction(t *testing.T) {
Expand Down Expand Up @@ -435,7 +436,7 @@ func TestUpdateBillingServiceAction(t *testing.T) {
}

cCtx, ac, out, errOut := setup(asc, nil, nil, nil, "token")
address := "123 Main St, Suite 100, San Francisco, CA, 94105"
address := "123 Main St, Suite 100, San Francisco, CA, 94105, United States"
test.That(t, ac.updateBillingServiceAction(cCtx, "test-org", address), test.ShouldBeNil)
test.That(t, len(errOut.messages), test.ShouldEqual, 0)
test.That(t, len(out.messages), test.ShouldEqual, 8)
Expand All @@ -446,7 +447,7 @@ func TestUpdateBillingServiceAction(t *testing.T) {
test.That(t, out.messages[4], test.ShouldContainSubstring, "San Francisco")
test.That(t, out.messages[5], test.ShouldContainSubstring, "CA")
test.That(t, out.messages[6], test.ShouldContainSubstring, "94105")
test.That(t, out.messages[7], test.ShouldContainSubstring, "USA")
test.That(t, out.messages[7], test.ShouldContainSubstring, "United States")
}

func TestOrganizationEnableBillingServiceAction(t *testing.T) {
Expand Down
8 changes: 5 additions & 3 deletions cli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,17 @@ func parseBillingAddress(address string) (*apppb.BillingAddress, error) {
}

splitAddress := strings.Split(address, ",")
if len(splitAddress) != 4 && len(splitAddress) != 5 {
return nil, errors.Errorf("address: %s does not follow the format: line1, line2 (optional), city, state, zipcode", address)
if len(splitAddress) != 5 && len(splitAddress) != 6 {
return nil, errors.Errorf("address: %s does not follow the format: line1, line2 (optional), city, state, zipcode, country", address)
}

if len(splitAddress) == 4 {
if len(splitAddress) == 5 {
return &apppb.BillingAddress{
AddressLine_1: strings.Trim(splitAddress[0], " "),
City: strings.Trim(splitAddress[1], " "),
State: strings.Trim(splitAddress[2], " "),
Zipcode: strings.Trim(splitAddress[3], " "),
Country: strings.Trim(splitAddress[4], " "),
}, nil
}

Expand All @@ -92,6 +93,7 @@ func parseBillingAddress(address string) (*apppb.BillingAddress, error) {
City: strings.Trim(splitAddress[2], " "),
State: strings.Trim(splitAddress[3], " "),
Zipcode: strings.Trim(splitAddress[4], " "),
Country: strings.Trim(splitAddress[5], " "),
}, nil
}

Expand Down
6 changes: 4 additions & 2 deletions cli/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,24 @@ func TestParseBillingAddress(t *testing.T) {
expectedErr error
}{
{
input: "123 Main St, Apt 1, San Francisco, CA, 94105",
input: "123 Main St, Apt 1, San Francisco, CA, 94105, United States",
expectedAddress: &apppb.BillingAddress{
AddressLine_1: "123 Main St",
AddressLine_2: &addressLine2,
City: "San Francisco",
State: "CA",
Zipcode: "94105",
Country: "United States",
},
},
{
input: "123 Main St, San Francisco, CA, 94105",
input: "123 Main St, San Francisco, CA, 94105, United States",
expectedAddress: &apppb.BillingAddress{
AddressLine_1: "123 Main St",
City: "San Francisco",
State: "CA",
Zipcode: "94105",
Country: "United States",
},
},
{
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ require (
go.uber.org/atomic v1.11.0
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.27.0
go.viam.com/api v0.1.387
go.viam.com/api v0.1.388
go.viam.com/test v1.2.4
go.viam.com/utils v0.1.128
goji.io v2.0.2+incompatible
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1513,8 +1513,8 @@ go.uber.org/zap v1.18.1/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI=
go.uber.org/zap v1.23.0/go.mod h1:D+nX8jyLsMHMYrln8A0rJjFt/T/9/bGgIhAqxv5URuY=
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
go.viam.com/api v0.1.387 h1:nxWF+dO+z2mwTpTkcs8mr8L0ic4ZwcqOAumBtHnvqsc=
go.viam.com/api v0.1.387/go.mod h1:g5eipXHNm0rQmW7DWya6avKcmzoypLmxnMlAaIsE5Ls=
go.viam.com/api v0.1.388 h1:6UW1+5DY1zIupzJnms9oGEKG8xHgu0T1hc6Zx5UhAeQ=
go.viam.com/api v0.1.388/go.mod h1:g5eipXHNm0rQmW7DWya6avKcmzoypLmxnMlAaIsE5Ls=
go.viam.com/test v1.2.4 h1:JYgZhsuGAQ8sL9jWkziAXN9VJJiKbjoi9BsO33TW3ug=
go.viam.com/test v1.2.4/go.mod h1:zI2xzosHdqXAJ/kFqcN+OIF78kQuTV2nIhGZ8EzvaJI=
go.viam.com/utils v0.1.128 h1:ScO0pWiwoYzsILcJudL4axCAGhNPmzszJeMoHhdx23s=
Expand Down
Loading