Skip to content
This repository has been archived by the owner on Aug 26, 2022. It is now read-only.

Commit

Permalink
Remove ownerType validation, as it is not required in requests
Browse files Browse the repository at this point in the history
  • Loading branch information
darwinz committed Nov 11, 2020
1 parent 4578d0d commit 8c6cc02
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 41 deletions.
2 changes: 1 addition & 1 deletion pkg/customers/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func createAddress(logger log.Logger, ownerType client.OwnerType, repo CustomerR
for _, addr := range addresses {
addrs = append(addrs, address{
Type: addr.Type,
OwnerType: addr.OwnerType,
OwnerType: ownerType,
Address1: addr.Address1,
Address2: addr.Address2,
City: addr.City,
Expand Down
2 changes: 1 addition & 1 deletion pkg/customers/customer_representatives.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ func (req customerRepresentativeRequest) asRepresentative(storage *ssnStorage) (
representative.Phones = append(representative.Phones, client.Phone{
Number: req.Phones[i].Number,
Type: req.Phones[i].Type,
OwnerType: req.Phones[i].OwnerType,
OwnerType: client.OWNERTYPE_REPRESENTATIVE,
})
}
for i := range req.Addresses {
Expand Down
10 changes: 0 additions & 10 deletions pkg/customers/customer_representatives_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ func TestCustomers__customerRepresentativeRequest(t *testing.T) {
req.Phones = append(req.Phones, phone{
Number: "123.456.7890",
Type: "mobile",
OwnerType: "customer",
})
if err := req.validate(); err != nil {
t.Errorf("unexpected error: %v", err)
Expand All @@ -158,7 +157,6 @@ func TestCustomers__customerRepresentativeRequest(t *testing.T) {
PostalCode: "90210",
Country: "US",
Type: "primary",
OwnerType: client.OWNERTYPE_REPRESENTATIVE,
})
if err := req.validate(); err != nil {
t.Errorf("unexpected error: %v", err)
Expand Down Expand Up @@ -273,7 +271,6 @@ func TestCustomers__updateRepresentative(t *testing.T) {
{
Number: "123.456.7890",
Type: "mobile",
OwnerType: "representative",
},
},
Addresses: []address{
Expand All @@ -284,7 +281,6 @@ func TestCustomers__updateRepresentative(t *testing.T) {
PostalCode: "90210",
Country: "US",
Type: "primary",
OwnerType: "representative",
},
},
}
Expand Down Expand Up @@ -349,7 +345,6 @@ func TestCustomers__updateRepresentative(t *testing.T) {
PostalCode: "90210",
Country: "US",
Type: "primary",
OwnerType: "representative",
},
{
Address1: "444 4th st",
Expand All @@ -358,7 +353,6 @@ func TestCustomers__updateRepresentative(t *testing.T) {
PostalCode: "90210",
Country: "US",
Type: "primary",
OwnerType: "representative",
},
}
payload, err = json.Marshal(&updateReq)
Expand Down Expand Up @@ -412,7 +406,6 @@ func TestCustomerRepository__updateRepresentative(t *testing.T) {
PostalCode: "90210",
Country: "US",
Type: "primary",
OwnerType: "customer",
},
},
}
Expand All @@ -429,15 +422,13 @@ func TestCustomerRepository__updateRepresentative(t *testing.T) {
{
Number: "555.555.5555",
Type: "mobile",
OwnerType: "customer",
},
},
Addresses: []address{
{
Address1: "555 5th st",
City: "real city",
Type: "primary",
OwnerType: "customer",
},
},
}
Expand Down Expand Up @@ -496,7 +487,6 @@ func TestCustomersRepository__addRepresentativeAddress(t *testing.T) {
PostalCode: "90210",
Country: "US",
Type: "primary",
OwnerType: "representative",
},
); err != nil {
t.Fatal(err)
Expand Down
12 changes: 0 additions & 12 deletions pkg/customers/customers.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,6 @@ func (p *phone) validate() error {
return fmt.Errorf("unknown type: %s", p.Type)
}

switch p.OwnerType {
case client.OWNERTYPE_CUSTOMER, client.OWNERTYPE_REPRESENTATIVE:
default:
return fmt.Errorf("unknown owner type: %s", p.OwnerType)
}

return nil
}

Expand All @@ -185,12 +179,6 @@ func (add *address) validate() error {
return fmt.Errorf("unknown type: %s", add.Type)
}

switch add.OwnerType {
case client.OWNERTYPE_CUSTOMER, client.OWNERTYPE_REPRESENTATIVE:
default:
return fmt.Errorf("unknown owner type: %s", add.OwnerType)
}

if !usstates.Valid(add.State) {
return fmt.Errorf("create customer: invalid state=%s", add.State)
}
Expand Down
20 changes: 3 additions & 17 deletions pkg/customers/customers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,6 @@ func TestCustomers__customerRequest(t *testing.T) {
req.Phones = append(req.Phones, phone{
Number: "123.456.7890",
Type: "mobile",
OwnerType: "customer",
})
if err := req.validate(); err != nil {
t.Errorf("unexpected error: %v", err)
Expand Down Expand Up @@ -351,7 +350,7 @@ func TestCustomers__customerRequest(t *testing.T) {
}

func TestCustomers__addressValidate(t *testing.T) {
add := address{Type: "primary", OwnerType: "customer"}
add := address{Type: "primary"}

add.State = "IA"
if err := add.validate(); err != nil {
Expand All @@ -366,8 +365,8 @@ func TestCustomers__addressValidate(t *testing.T) {

func TestCustomers__CreateCustomer(t *testing.T) {
w := httptest.NewRecorder()
phone := `{"number": "555.555.5555", "type": "mobile", "ownerType": "customer"}`
address := `{"type": "primary", "ownerType": "customer", "address1": "123 1st St", "city": "Denver", "state": "CO", "postalCode": "12345", "country": "USA"}`
phone := `{"number": "555.555.5555", "type": "mobile"}`
address := `{"type": "primary", "address1": "123 1st St", "city": "Denver", "state": "CO", "postalCode": "12345", "country": "USA"}`
body := fmt.Sprintf(`{"firstName": "jane", "lastName": "doe", "email": "jane@example.com", "birthDate": "1991-04-01", "ssn": "123456789", "type": "individual", "phones": [%s], "addresses": [%s]}`, phone, address)
req := httptest.NewRequest("POST", "/customers", strings.NewReader(body))
req.Header.Set("x-organization", "test")
Expand Down Expand Up @@ -444,7 +443,6 @@ func TestCustomers__updateCustomer(t *testing.T) {
{
Number: "123.456.7890",
Type: "mobile",
OwnerType: "customer",
},
},
Addresses: []address{
Expand All @@ -455,7 +453,6 @@ func TestCustomers__updateCustomer(t *testing.T) {
PostalCode: "90210",
Country: "US",
Type: "primary",
OwnerType: "customer",
},
},
}
Expand All @@ -479,7 +476,6 @@ func TestCustomers__updateCustomer(t *testing.T) {
{
Number: "555.555.5555",
Type: "mobile",
OwnerType: "customer",
},
}
updateReq.Addresses = []address{
Expand All @@ -490,7 +486,6 @@ func TestCustomers__updateCustomer(t *testing.T) {
PostalCode: "90210",
Country: "US",
Type: "primary",
OwnerType: "customer",
},
}
payload, err := json.Marshal(&updateReq)
Expand Down Expand Up @@ -526,7 +521,6 @@ func TestCustomers__updateCustomer(t *testing.T) {
PostalCode: "90210",
Country: "US",
Type: "primary",
OwnerType: "customer",
},
{
Address1: "444 4th st",
Expand All @@ -535,7 +529,6 @@ func TestCustomers__updateCustomer(t *testing.T) {
PostalCode: "90210",
Country: "US",
Type: "primary",
OwnerType: "customer",
},
}
payload, err = json.Marshal(&updateReq)
Expand Down Expand Up @@ -581,7 +574,6 @@ func TestCustomers__repository(t *testing.T) {
{
Number: "123.456.7890",
Type: "mobile",
OwnerType: "customer",
},
},
Addresses: []address{
Expand Down Expand Up @@ -686,7 +678,6 @@ func TestCustomerRepository__updateCustomer(t *testing.T) {
{
Number: "123.456.7890",
Type: "mobile",
OwnerType: "customer",
},
},
Addresses: []address{
Expand All @@ -712,15 +703,13 @@ func TestCustomerRepository__updateCustomer(t *testing.T) {
{
Number: "555.555.5555",
Type: "mobile",
OwnerType: "customer",
},
},
Addresses: []address{
{
Address1: "555 5th st",
City: "real city",
Type: "primary",
OwnerType: "customer",
},
},
}
Expand Down Expand Up @@ -789,7 +778,6 @@ func TestCustomersRepository__addAddress(t *testing.T) {
PostalCode: "90210",
Country: "US",
Type: "primary",
OwnerType: "customer",
},
); err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -1056,7 +1044,6 @@ func mockCustomerRequest() customerRequest {
p := phone{}
p.Number = "123-456-7892"
p.Type = "mobile"
p.OwnerType = "customer"
c.Phones = append(c.Phones, p)

a := address{}
Expand All @@ -1066,7 +1053,6 @@ func mockCustomerRequest() customerRequest {
a.Country = "USA"
a.PostalCode = "19456"
a.State = "MA"
a.OwnerType = "customer"
c.Addresses = append(c.Addresses, a)
return c
}
Expand Down

0 comments on commit 8c6cc02

Please sign in to comment.