Skip to content

Commit

Permalink
Update V2 for PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
karmakaze committed Dec 2, 2019
1 parent c72bff7 commit 738e870
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 39 deletions.
18 changes: 1 addition & 17 deletions lib/shopify_api/resources/assigned_fulfillment_order.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
module ShopifyAPI
class AssignedFulfillmentOrder < Base
CANCELLATION_REQUESTED = 'cancellation_requested'
FULFILLMENT_REQUESTED = 'fulfillment_requested'
FULFILLMENT_ACCEPTED = 'fulfillment_accepted'

ALL_ASSIGNED_STATUSES = [
CANCELLATION_REQUESTED = 'cancellation_requested',
FULFILLMENT_REQUESTED = 'fulfillment_requested',
FULFILLMENT_ACCEPTED = 'fulfillment_accepted'
].freeze

def self.all(options = {})
params = options[:params] || options['params'] || {}
assigned_status = params[:assigned_status] || params['assigned_status']
if assigned_status && !ALL_ASSIGNED_STATUSES.include?(assigned_status)
raise ValidationException, "Invalid 'assigned_status': #{assigned_status}"
end

assigned_fulfillment_orders = super(options)
assigned_fulfillment_orders.map { |afo| FulfillmentOrder.new(afo.as_json) }
assigned_fulfillment_orders.map { |afo| FulfillmentOrder.new(afo.attributes) }
end
end
end
4 changes: 2 additions & 2 deletions lib/shopify_api/resources/fulfillment_order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ def self.all(options = {})
end

def fulfillments(options = {})
fo_fulfillments = get(:fulfillments, options)
fo_fulfillments.map { |fof| FulfillmentOrderFulfillment.new(fof.as_json) }
fulfillments = get(:fulfillments, options)
fulfillments.map { |fulfillment| FulfillmentV2.new(fulfillment.as_json) }
end
end
end
4 changes: 0 additions & 4 deletions lib/shopify_api/resources/fulfillment_order_fulfillment.rb

This file was deleted.

4 changes: 4 additions & 0 deletions lib/shopify_api/resources/fulfillment_v2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module ShopifyAPI
class FulfillmentV2 < Base
end
end
4 changes: 2 additions & 2 deletions lib/shopify_api/resources/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def capture(amount = "", currency: nil)
end

def fulfillment_orders(options = {})
order_fulfillment_orders = get(:fulfillment_orders, options)
order_fulfillment_orders.map { |ofo| FulfillmentOrder.new(ofo.as_json) }
fulfillment_orders = get(:fulfillment_orders, options)
fulfillment_orders.map { |fulfillment_order| FulfillmentOrder.new(fulfillment_order.as_json) }
end

class ClientDetails < Base
Expand Down
18 changes: 5 additions & 13 deletions test/assigned_fulfillment_order_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,13 @@
class AssignedFulFillmentOrderTest < Test::Unit::TestCase
context "AssignedFulfillmentOrder" do
context "#all" do
should "raise ValidationException if assigned_status is invalid" do
assert_raises ShopifyAPI::ValidationException do
assigned_fulfillment_orders = ShopifyAPI::AssignedFulfillmentOrder.all(
params: { assigned_status: 'bogus_status' }
)
end
end

should "list assigned fulfillment orders by assigned_status" do
fo_fixture = load_fixture('assigned_fulfillment_orders')
fulfillment_order_fixture = load_fixture('assigned_fulfillment_orders')
fake 'assigned_fulfillment_orders.json?assigned_status=cancellation_requested', method: :get,
body: fo_fixture, extension: false
body: fulfillment_order_fixture, extension: false

assigned_fulfillment_orders = ShopifyAPI::AssignedFulfillmentOrder.all(
params: { assigned_status: ShopifyAPI::AssignedFulfillmentOrder::CANCELLATION_REQUESTED }
params: { assigned_status: 'cancellation_requested' }
)

assert_equal 2, assigned_fulfillment_orders.count
Expand All @@ -29,10 +21,10 @@ class AssignedFulFillmentOrderTest < Test::Unit::TestCase
end

should "be able to list assigned fulfillment orders by location_ids" do
fo_fixture = load_fixture('assigned_fulfillment_orders')
fulfillment_order_fixture = load_fixture('assigned_fulfillment_orders')
assigned_location_id = 905684977
fake "assigned_fulfillment_orders.json?location_ids%5B%5D=#{assigned_location_id}", method: :get,
body: fo_fixture, extension: false
body: fulfillment_order_fixture, extension: false

assigned_fulfillment_orders = ShopifyAPI::AssignedFulfillmentOrder.all(
params: { location_ids: [assigned_location_id] }
Expand Down
2 changes: 1 addition & 1 deletion test/fulfillment_order_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def setup

assert_equal 1, fulfillments.count
fulfillment = fulfillments.first
assert_equal 'ShopifyAPI::FulfillmentOrderFulfillment', fulfillment.class.name
assert_equal 'ShopifyAPI::FulfillmentV2', fulfillment.class.name
assert_equal 450789469, fulfillment.order_id
end
end
Expand Down

0 comments on commit 738e870

Please sign in to comment.