forked from getconversio/go-shopify
-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds
assigned_fulfillment_order
(#233)
- Loading branch information
Showing
4 changed files
with
148 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
// } | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters