Skip to content

Commit

Permalink
adds assigned_fulfillment_order (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
sx328 authored Sep 7, 2023
1 parent fb0d550 commit acc26c9
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 7 deletions.
76 changes: 76 additions & 0 deletions assigned_fulfillment_order.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package goshopify

import "fmt"

const (
assignedFulfillmentOrderBasePath = "assigned_fulfillment_orders"
)

// AssignedFulfillmentService is an interface for interfacing with the assigned fulfillment orders
// of the Shopify API.
// https://shopify.dev/docs/api/admin-rest/2023-07/resources/assignedfulfillmentorder
type AssignedFulfillmentOrderService interface {
Get(interface{}) ([]AssignedFulfillmentOrder, error)
}

type AssignedFulfillmentOrder struct {
Id int64 `json:"id,omitempty"`
AssignedLocationId int64 `json:"assigned_location_id,omitempty"`
Destination AssignedFulfillmentOrderDestination `json:"destination,omitempty"`
LineItems []AssignedFulfillmentOrderLineItem `json:"line_items,omitempty"`
OrderId int64 `json:"order_id,omitempty"`
RequestStatus string `json:"request_status,omitempty"`
ShopId int64 `json:"shop_id,omitempty"`
Status string `json:"status,omitempty"`
}

// AssignedFulfillmentOrderDestination represents a destination for a AssignedFulfillmentOrder
type AssignedFulfillmentOrderDestination struct {
Id int64 `json:"id,omitempty"`
Address1 string `json:"address1,omitempty"`
Address2 string `json:"address2,omitempty"`
City string `json:"city,omitempty"`
Company string `json:"company,omitempty"`
Country string `json:"country,omitempty"`
Email string `json:"email,omitempty"`
FirstName string `json:"first_name,omitempty"`
LastName string `json:"last_name,omitempty"`
Phone string `json:"phone,omitempty"`
Province string `json:"province,omitempty"`
Zip string `json:"zip,omitempty"`
}

// AssignedFulfillmentOrderLineItem represents a line item for a AssignedFulfillmentOrder
type AssignedFulfillmentOrderLineItem struct {
Id int64 `json:"id,omitempty"`
ShopId int64 `json:"shop_id,omitempty"`
FulfillmentOrderId int64 `json:"fulfillment_order_id,omitempty"`
LineItemId int64 `json:"line_item_id,omitempty"`
InventoryItemId int64 `json:"inventory_item_id,omitempty"`
Quantity int64 `json:"quantity,omitempty"`
FulfillableQuantity int64 `json:"fulfillable_quantity,omitempty"`
}

// AssignedFulfillmentOrderResource represents the result from the assigned_fulfillment_order.json endpoint
type AssignedFulfillmentOrdersResource struct {
AssignedFulfillmentOrders []AssignedFulfillmentOrder `json:"fulfillment_orders,omitempty"`
}

type AssignedFulfillmentOrderOptions struct {
AssignmentStatus string `url:"assignment_status,omitempty"`
LocationIds string `url:"location_ids,omitempty"`
}

// AssignedFulfillmentOrderServiceOp handles communication with the AssignedFulfillmentOrderService
// related methods of the Shopify API
type AssignedFulfillmentOrderServiceOp struct {
client *Client
}

// Gets a list of all the fulfillment orders that are assigned to an app at the shop level
func (s *AssignedFulfillmentOrderServiceOp) Get(options interface{}) ([]AssignedFulfillmentOrder, error) {
path := fmt.Sprintf("%s.json", assignedFulfillmentOrderBasePath)
resource := new(AssignedFulfillmentOrdersResource)
err := s.client.Get(path, resource, options)
return resource.AssignedFulfillmentOrders, err
}
63 changes: 63 additions & 0 deletions assigned_fulfillment_order_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package goshopify

import (
"fmt"
"reflect"
"testing"

"github.com/jarcoal/httpmock"
)

func AssignedFulfillmentOrderTests(t *testing.T, assignedFulfillmentOrder AssignedFulfillmentOrder) {
// Check that ID is assigned to the returned fulfillment
expectedInt := int64(255858046) // in assigned_fulfillment_orders.json fixture
if assignedFulfillmentOrder.Id != expectedInt {
t.Errorf("AssignedFulfillmentOrder.ID returned %+v, expected %+v", assignedFulfillmentOrder.Id, expectedInt)
}
}

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

httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/assigned_fulfillment_orders.json", client.pathPrefix),
httpmock.NewStringResponder(200, `{"fulfillment_orders": [{"id":1},{"id":2}]}`))

assignedFulfillmentOrderService := &AssignedFulfillmentOrderServiceOp{client: client}

assignedFulfillmentOrders, err := assignedFulfillmentOrderService.Get(nil)
if err != nil {
t.Errorf("AssignedFulfillmentOrder.List returned error: %v", err)
}

expected := []AssignedFulfillmentOrder{{Id: 1}, {Id: 2}}
if !reflect.DeepEqual(assignedFulfillmentOrders, expected) {
t.Errorf("AssignedFulfillmentOrder.List returned %+v, expected %+v", assignedFulfillmentOrders, expected)
}
}

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

// fixture := loadFixture("fulfillment_order.json")
// httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/fulfillment_orders/255858046.json", client.pathPrefix),
// httpmock.NewBytesResponder(200, fixture))

// fulfillmentOrderService := &FulfillmentOrderServiceOp{client: client}

// fulfillment, err := fulfillmentOrderService.Get(255858046, nil)
// if err != nil {
// t.Errorf("FulfillmentOrder.Get returned error: %v", err)
// }

// expected := FulfillmentOrderResource{}
// err = json.Unmarshal(fixture, &expected)
// if err != nil {
// t.Errorf("json.Unmarshall returned error : %v", err)
// }

// if !reflect.DeepEqual(fulfillment, expected.FulfillmentOrder) {
// t.Errorf("FulfillmentOrder.Get returned %+v, expected %+v", fulfillment, expected)
// }
// }
14 changes: 7 additions & 7 deletions fulfillment_order.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ type FulfillmentOrderHoldReason string

const (
HoldReasonAwaitingPayment FulfillmentOrderHoldReason = "awaiting_payment"
HoldReasonHighRiskOfFraud = "high_risk_of_fraud"
HoldReasonIncorrectAddress = "incorrect_address"
HoldReasonOutOfStock = "inventory_out_of_stock"
HoldReasonOther = "other"
HoldReasonHighRiskOfFraud FulfillmentOrderHoldReason = "high_risk_of_fraud"
HoldReasonIncorrectAddress FulfillmentOrderHoldReason = "incorrect_address"
HoldReasonOutOfStock FulfillmentOrderHoldReason = "inventory_out_of_stock"
HoldReasonOther FulfillmentOrderHoldReason = "other"
)

// FulfillmentOrderServiceOp handles communication with the fulfillment order
Expand Down Expand Up @@ -141,12 +141,12 @@ type FulfillmentOrder struct {
UpdatedAt *time.Time `json:"updated_at,omitempty"`
}

// FulfillmentOrdersResource represents the result from the fulfilment_orders.json endpoint
// FulfillmentOrdersResource represents the result from the fulfillment_orders.json endpoint
type FulfillmentOrdersResource struct {
FulfillmentOrders []FulfillmentOrder `json:"fulfillment_orders"`
}

// FulfillmentOrderResource represents the result from the fulfilment_orders/<id>.json endpoint
// FulfillmentOrderResource represents the result from the fulfillment_orders/<id>.json endpoint
type FulfillmentOrderResource struct {
FulfillmentOrder *FulfillmentOrder `json:"fulfillment_order"`
}
Expand All @@ -157,7 +157,7 @@ type FulfillmentOrderMoveResource struct {
MovedFulfillmentOrder FulfillmentOrder `json:"moved_fulfillment_order"`
}

// FulfillmentOrderPathPrefix returns the prefix for a fulfillmentorder path
// FulfillmentOrderPathPrefix returns the prefix for a fulfillmentOrder path
func FulfillmentOrderPathPrefix(resource string, resourceID int64) string {
return fmt.Sprintf("%s/%d", resource, resourceID)
}
Expand Down
2 changes: 2 additions & 0 deletions goshopify.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ type Client struct {
GiftCard GiftCardService
FulfillmentOrder FulfillmentOrderService
GraphQL GraphQLService
AssignedFulfillmentOrder AssignedFulfillmentOrderService
}

// A general response error that follows a similar layout to Shopify's response
Expand Down Expand Up @@ -308,6 +309,7 @@ func NewClient(app App, shopName, token string, opts ...Option) *Client {
c.GiftCard = &GiftCardServiceOp{client: c}
c.FulfillmentOrder = &FulfillmentOrderServiceOp{client: c}
c.GraphQL = &GraphQLServiceOp{client: c}
c.AssignedFulfillmentOrder = &AssignedFulfillmentOrderServiceOp{client: c}

// apply any options
for _, opt := range opts {
Expand Down

0 comments on commit acc26c9

Please sign in to comment.