Skip to content

Commit

Permalink
Merge pull request #2 from dietdoctor/new-user-id
Browse files Browse the repository at this point in the history
update user can change user id
  • Loading branch information
lindroth authored May 31, 2019
2 parents 71ea1b6 + f31ccec commit fdbf52c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions customer_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ func (g *CustomerGateway) Create(ctx context.Context, c *CustomerRequest) (*Cust

// Update updates any field that is set in the passed customer object.
// The ID field is mandatory.
func (g *CustomerGateway) Update(ctx context.Context, c *CustomerRequest) (*Customer, error) {
resp, err := g.execute(ctx, "PUT", "customers/"+c.ID, c)
func (g *CustomerGateway) Update(ctx context.Context, customerID string, c *CustomerRequest) (*Customer, error) {
resp, err := g.execute(ctx, "PUT", "customers/"+customerID, c)
if err != nil {
return nil, err
}
Expand Down
17 changes: 10 additions & 7 deletions customer_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,11 @@ func TestCustomer(t *testing.T) {
// Update
unique := testhelpers.RandomString()
newFirstName := "John" + unique
c2, err := testGateway.Customer().Update(ctx, &CustomerRequest{
ID: customer.Id,

newID := testhelpers.RandomString()

c2, err := testGateway.Customer().Update(ctx, customer.Id, &CustomerRequest{
ID: newID,
FirstName: newFirstName,
})

Expand All @@ -88,14 +91,14 @@ func TestCustomer(t *testing.T) {
}

// Find
c3, err := testGateway.Customer().Find(ctx, customer.Id)
c3, err := testGateway.Customer().Find(ctx, newID)

t.Log(c3)

if err != nil {
t.Fatal(err)
}
if c3.Id != customer.Id {
if c3.Id != newID {
t.Fatal("ids do not match")
}

Expand All @@ -110,18 +113,18 @@ func TestCustomer(t *testing.T) {
if len(searchResult.Customers) == 0 {
t.Fatal("could not search for a customer")
}
if id := searchResult.Customers[0].Id; id != customer.Id {
if id := searchResult.Customers[0].Id; id != newID {
t.Fatalf("id from search does not match: got %s, wanted %s", id, customer.Id)
}

// Delete
err = testGateway.Customer().Delete(ctx, customer.Id)
err = testGateway.Customer().Delete(ctx, newID)
if err != nil {
t.Fatal(err)
}

// Test customer 404
c4, err := testGateway.Customer().Find(ctx, customer.Id)
c4, err := testGateway.Customer().Find(ctx, newID)
if err == nil {
t.Fatal("should return 404")
}
Expand Down

0 comments on commit fdbf52c

Please sign in to comment.