Skip to content

Commit

Permalink
Add options to list customer orders (bold-commerce#21)
Browse files Browse the repository at this point in the history
* Makes a breaking change to a method just recently added. Missing from the Shopify API documentation was the fact that this endpoint appears to take the same arguments as GET /admin/orders.json.
  • Loading branch information
dbertouille authored and rickywiens committed Sep 28, 2018
1 parent 12eded9 commit 05c6702
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
6 changes: 3 additions & 3 deletions customer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type CustomerService interface {
Create(Customer) (*Customer, error)
Update(Customer) (*Customer, error)
Delete(int) error
ListOrders(int) ([]Order, error)
ListOrders(int, interface{}) ([]Order, error)

// MetafieldsService used for Customer resource to communicate with Metafields resource
MetafieldsService
Expand Down Expand Up @@ -168,9 +168,9 @@ func (s *CustomerServiceOp) DeleteMetafield(customerID int, metafieldID int) err
}

// ListOrders retrieves all orders from a customer
func (s *CustomerServiceOp) ListOrders(customerID int) ([]Order, error) {
func (s *CustomerServiceOp) ListOrders(customerID int, options interface{}) ([]Order, error) {
path := fmt.Sprintf("%s/%d/orders.json", customersBasePath, customerID)
resource := new(OrdersResource)
err := s.client.Get(path, resource, nil)
err := s.client.Get(path, resource, options)
return resource.Orders, err
}
18 changes: 17 additions & 1 deletion customer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,25 @@ func TestCustomerListOrders(t *testing.T) {
httpmock.RegisterResponder(
"GET",
"https://fooshop.myshopify.com/admin/customers/1/orders.json",
httpmock.NewStringResponder(200, "{\"orders\":[]}"),
)
httpmock.RegisterResponder(
"GET",
"https://fooshop.myshopify.com/admin/customers/1/orders.json?status=any",
httpmock.NewBytesResponder(200, loadFixture("orders.json")),
)
orders, err := client.Customer.ListOrders(1)

orders, err := client.Customer.ListOrders(1, nil)
if err != nil {
t.Errorf("Customer.ListOrders returned error: %v", err)
}

// Check that orders were parsed
if len(orders) != 0 {
t.Errorf("Customer.ListOrders got %v orders, expected: 1", len(orders))
}

orders, err = client.Customer.ListOrders(1, OrderListOptions{Status: "any"})
if err != nil {
t.Errorf("Customer.ListOrders returned error: %v", err)
}
Expand Down

0 comments on commit 05c6702

Please sign in to comment.