Skip to content

Commit

Permalink
Add order update endpoint (#41)
Browse files Browse the repository at this point in the history
It allows to update notes, customer, address and so on
  • Loading branch information
yulintan authored and rickywiens committed Dec 20, 2018
1 parent 1ee02fc commit 422649a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
10 changes: 10 additions & 0 deletions order.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type OrderService interface {
Count(interface{}) (int, error)
Get(int, interface{}) (*Order, error)
Create(Order) (*Order, error)
Update(Order) (*Order, error)

// MetafieldsService used for Order resource to communicate with Metafields resource
MetafieldsService
Expand Down Expand Up @@ -314,6 +315,15 @@ func (s *OrderServiceOp) Create(order Order) (*Order, error) {
return resource.Order, err
}

// Update order
func (s *OrderServiceOp) Update(order Order) (*Order, error) {
path := fmt.Sprintf("%s/%d.json", ordersBasePath, order.ID)
wrappedData := OrderResource{Order: &order}
resource := new(OrderResource)
err := s.client.Put(path, wrappedData, resource)
return resource.Order, err
}

// List metafields for an order
func (s *OrderServiceOp) ListMetafields(orderID int, options interface{}) ([]Metafield, error) {
metafieldService := &MetafieldServiceOp{client: s.client, resource: ordersResourceName, resourceID: orderID}
Expand Down
24 changes: 24 additions & 0 deletions order_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,30 @@ func TestOrderCreate(t *testing.T) {
}
}

func TestOrderUpdate(t *testing.T) {
setup()
defer teardown()

httpmock.RegisterResponder("PUT", "https://fooshop.myshopify.com/admin/orders/1.json",
httpmock.NewStringResponder(201, `{"order":{"id": 1}}`))

order := Order{
ID: 1,
FinancialStatus: "paid",
FulfillmentStatus: "fulfilled",
}

o, err := client.Order.Update(order)
if err != nil {
t.Errorf("Order.Update returned error: %v", err)
}

expected := Order{ID: 1}
if o.ID != expected.ID {
t.Errorf("Order.Update returned id %d, expected %d", o.ID, expected.ID)
}
}

func TestOrderListMetafields(t *testing.T) {
setup()
defer teardown()
Expand Down

0 comments on commit 422649a

Please sign in to comment.