|
@@ -8,10 +8,12 @@ class FulFillmentOrderTest < Test::Unit::TestCase
|
|
|
super
|
|
|
@url_prefix = url_prefix_for_activated_session_for('2020-01')
|
|
|
|
|
|
- fake('fulfillment_orders',
|
|
|
+ fake(
|
|
|
+ 'fulfillment_orders',
|
|
|
url: "#{@url_prefix}/fulfillment_orders/519788021.json",
|
|
|
method: :get,
|
|
|
- body: load_fixture('fulfillment_order'))
|
|
|
+ body: load_fixture('fulfillment_order')
|
|
|
+ )
|
|
|
end
|
|
|
|
|
|
context "FulfillmentOrder" do
|
|
@@ -34,11 +36,12 @@ class FulFillmentOrderTest < Test::Unit::TestCase
|
|
|
should "raise NotImplementedError when api_version is older than 2020-01" do
|
|
|
@url_prefix = url_prefix_for_activated_session_for('2019-10')
|
|
|
|
|
|
- fake 'fulfillment_orders',
|
|
|
+ fake(
|
|
|
+ 'fulfillment_orders',
|
|
|
url: "#{@url_prefix}/fulfillment_orders/519788021.json",
|
|
|
method: :get,
|
|
|
body: load_fixture('fulfillment_order')
|
|
|
-
|
|
|
+ )
|
|
|
exception = assert_raises(NotImplementedError) do
|
|
|
ShopifyAPI::FulfillmentOrder.find(519788021)
|
|
|
end
|
|
@@ -47,7 +50,7 @@ class FulFillmentOrderTest < Test::Unit::TestCase
|
|
|
exception.message
|
|
|
)
|
|
|
|
|
|
- assert_raises NotImplementedError do
|
|
|
+ assert_raises(NotImplementedError) do
|
|
|
ShopifyAPI::FulfillmentOrder.all(params: { order_id: 450789469 })
|
|
|
end
|
|
|
end
|
|
@@ -56,32 +59,32 @@ class FulFillmentOrderTest < Test::Unit::TestCase
|
|
|
context "#find" do
|
|
|
should "be able to find fulfillment order" do
|
|
|
fulfillment_order = ShopifyAPI::FulfillmentOrder.find(519788021)
|
|
|
- assert fulfillment_order.is_a?(ShopifyAPI::FulfillmentOrder)
|
|
|
- assert_equal 519788021, fulfillment_order.id
|
|
|
- assert_equal 450789469, fulfillment_order.order_id
|
|
|
+ assert(fulfillment_order.is_a?(ShopifyAPI::FulfillmentOrder))
|
|
|
+ assert_equal(519788021, fulfillment_order.id)
|
|
|
+ assert_equal(450789469, fulfillment_order.order_id)
|
|
|
end
|
|
|
end
|
|
|
|
|
|
context "#all" do
|
|
|
should "be able to list fulfillment orders for an order" do
|
|
|
- fake 'orders',
|
|
|
+ fake('orders',
|
|
|
url: "#{@url_prefix}/orders/450789469/fulfillment_orders.json",
|
|
|
method: :get,
|
|
|
body: load_fixture('fulfillment_orders')
|
|
|
-
|
|
|
+ )
|
|
|
fulfillment_orders = ShopifyAPI::FulfillmentOrder.all(
|
|
|
params: { order_id: 450789469 }
|
|
|
)
|
|
|
|
|
|
- assert_equal [519788021, 519788022], fulfillment_orders.map(&:id).sort
|
|
|
+ assert_equal([519788021, 519788022], fulfillment_orders.map(&:id).sort)
|
|
|
fulfillment_orders.each do |fulfillment_order|
|
|
|
- assert fulfillment_order.is_a?(ShopifyAPI::FulfillmentOrder)
|
|
|
- assert_equal 450789469, fulfillment_order.order_id
|
|
|
+ assert(fulfillment_order.is_a?(ShopifyAPI::FulfillmentOrder))
|
|
|
+ assert_equal(450789469, fulfillment_order.order_id)
|
|
|
end
|
|
|
end
|
|
|
|
|
|
should "require order_id" do
|
|
|
- assert_raises ShopifyAPI::ValidationException do
|
|
|
+ assert_raises(ShopifyAPI::ValidationException) do
|
|
|
ShopifyAPI::FulfillmentOrder.all
|
|
|
end
|
|
|
end
|
|
@@ -90,37 +93,39 @@ class FulFillmentOrderTest < Test::Unit::TestCase
|
|
|
context "#fulfillments" do
|
|
|
should "be able to list fulfillments for a fulfillment order" do
|
|
|
fulfillment_order = ShopifyAPI::FulfillmentOrder.find(519788021)
|
|
|
- fake 'fulfillment_orders',
|
|
|
+ fake(
|
|
|
+ 'fulfillment_orders',
|
|
|
url: "#{@url_prefix}/fulfillment_orders/#{fulfillment_order.id}/fulfillments.json",
|
|
|
method: :get,
|
|
|
body: load_fixture('fulfillments')
|
|
|
-
|
|
|
+ )
|
|
|
fulfillments = fulfillment_order.fulfillments
|
|
|
|
|
|
- assert_equal 1, fulfillments.count
|
|
|
+ assert_equal(1, fulfillments.count)
|
|
|
fulfillment = fulfillments.first
|
|
|
- assert fulfillment.is_a?(ShopifyAPI::Fulfillment)
|
|
|
- assert_equal 450789469, fulfillment.order_id
|
|
|
+ assert(fulfillment.is_a?(ShopifyAPI::Fulfillment))
|
|
|
+ assert_equal(450789469, fulfillment.order_id)
|
|
|
end
|
|
|
end
|
|
|
|
|
|
context "#locations_for_move" do
|
|
|
should "be able to list locations for a fulfillment order" do
|
|
|
fulfillment_order = ShopifyAPI::FulfillmentOrder.find(519788021)
|
|
|
- fake 'fulfillment_orders',
|
|
|
+ fake(
|
|
|
+ 'fulfillment_orders',
|
|
|
url: "#{@url_prefix}/fulfillment_orders/#{fulfillment_order.id}/locations_for_move.json",
|
|
|
method: :get,
|
|
|
body: load_fixture('fulfillment_order_locations_for_move')
|
|
|
-
|
|
|
+ )
|
|
|
locations_for_move = fulfillment_order.locations_for_move
|
|
|
|
|
|
- assert_equal 2, locations_for_move.count
|
|
|
+ assert_equal(2, locations_for_move.count)
|
|
|
location_for_move = locations_for_move.first
|
|
|
- assert location_for_move.is_a?(ShopifyAPI::FulfillmentOrderLocationsForMove)
|
|
|
+ assert(location_for_move.is_a?(ShopifyAPI::FulfillmentOrderLocationsForMove))
|
|
|
|
|
|
location = location_for_move.location
|
|
|
- assert location.is_a?(ShopifyAPI::Location)
|
|
|
- assert_equal 1059367776,location.id
|
|
|
+ assert(location.is_a?(ShopifyAPI::Location))
|
|
|
+ assert_equal(1059367776,location.id)
|
|
|
end
|
|
|
end
|
|
|
|
|
@@ -140,37 +145,38 @@ class FulFillmentOrderTest < Test::Unit::TestCase
|
|
|
moved_fulfillment_order: fake_moved_fulfillment_order,
|
|
|
remaining_fulfillment_order: nil,
|
|
|
}
|
|
|
- fake 'fulfillment_orders',
|
|
|
+ fake(
|
|
|
+ 'fulfillment_orders',
|
|
|
url: "#{@url_prefix}/fulfillment_orders/519788021/move.json",
|
|
|
method: :post,
|
|
|
request_body: ActiveSupport::JSON.encode(request_body),
|
|
|
body: ActiveSupport::JSON.encode(body)
|
|
|
-
|
|
|
+ )
|
|
|
response_fulfillment_orders = fulfillment_order.move(new_location_id: new_location_id)
|
|
|
|
|
|
- assert_equal 'closed', fulfillment_order.status
|
|
|
+ assert_equal('closed', fulfillment_order.status)
|
|
|
|
|
|
- assert_equal 3, response_fulfillment_orders.count
|
|
|
+ assert_equal(3, response_fulfillment_orders.count)
|
|
|
original_fulfillment_order = response_fulfillment_orders['original_fulfillment_order']
|
|
|
refute_nil original_fulfillment_order
|
|
|
- assert original_fulfillment_order.is_a?(ShopifyAPI::FulfillmentOrder)
|
|
|
- assert_equal 'closed', original_fulfillment_order.status
|
|
|
+ assert(original_fulfillment_order.is_a?(ShopifyAPI::FulfillmentOrder))
|
|
|
+ assert_equal('closed', original_fulfillment_order.status)
|
|
|
|
|
|
moved_fulfillment_order = response_fulfillment_orders['moved_fulfillment_order']
|
|
|
refute_nil moved_fulfillment_order
|
|
|
- assert moved_fulfillment_order.is_a?(ShopifyAPI::FulfillmentOrder)
|
|
|
- assert_equal 'open', moved_fulfillment_order.status
|
|
|
- assert_equal new_location_id, moved_fulfillment_order.assigned_location_id
|
|
|
+ assert(moved_fulfillment_order.is_a?(ShopifyAPI::FulfillmentOrder))
|
|
|
+ assert_equal('open', moved_fulfillment_order.status)
|
|
|
+ assert_equal(new_location_id, moved_fulfillment_order.assigned_location_id)
|
|
|
|
|
|
remaining_fulfillment_order = response_fulfillment_orders['remaining_fulfillment_order']
|
|
|
- assert_nil remaining_fulfillment_order
|
|
|
+ assert_nil(remaining_fulfillment_order)
|
|
|
end
|
|
|
end
|
|
|
|
|
|
context "#cancel" do
|
|
|
should "cancel a fulfillment order" do
|
|
|
fulfillment_order = ShopifyAPI::FulfillmentOrder.find(519788021)
|
|
|
- assert_equal 'open', fulfillment_order.status
|
|
|
+ assert_equal('open', fulfillment_order.status)
|
|
|
|
|
|
cancelled = ActiveSupport::JSON.decode(load_fixture('fulfillment_order'))
|
|
|
cancelled['status'] = 'cancelled'
|
|
@@ -178,19 +184,20 @@ class FulFillmentOrderTest < Test::Unit::TestCase
|
|
|
fulfillment_order: cancelled,
|
|
|
replacement_fulfillment_order: fulfillment_order,
|
|
|
}
|
|
|
- fake 'fulfillment_orders',
|
|
|
+ fake(
|
|
|
+ 'fulfillment_orders',
|
|
|
url: "#{@url_prefix}/fulfillment_orders/519788021/cancel.json",
|
|
|
method: :post,
|
|
|
body: ActiveSupport::JSON.encode(body)
|
|
|
-
|
|
|
+ )
|
|
|
response_fulfillment_orders = fulfillment_order.cancel
|
|
|
|
|
|
- assert_equal 'cancelled', fulfillment_order.status
|
|
|
- assert_equal 2, response_fulfillment_orders.count
|
|
|
+ assert_equal('cancelled', fulfillment_order.status)
|
|
|
+ assert_equal(2, response_fulfillment_orders.count)
|
|
|
fulfillment_order = response_fulfillment_orders['fulfillment_order']
|
|
|
- assert_equal 'cancelled', fulfillment_order.status
|
|
|
+ assert_equal('cancelled', fulfillment_order.status)
|
|
|
replacement_fulfillment_order = response_fulfillment_orders['replacement_fulfillment_order']
|
|
|
- assert_equal 'open', replacement_fulfillment_order.status
|
|
|
+ assert_equal('open', replacement_fulfillment_order.status)
|
|
|
end
|
|
|
end
|
|
|
|
|
@@ -206,14 +213,15 @@ class FulFillmentOrderTest < Test::Unit::TestCase
|
|
|
message: "Test close message."
|
|
|
}
|
|
|
}
|
|
|
- fake 'fulfillment_orders',
|
|
|
+ fake(
|
|
|
+ 'fulfillment_orders',
|
|
|
url: "#{@url_prefix}/fulfillment_orders/519788021/close.json",
|
|
|
method: :post,
|
|
|
request_body: ActiveSupport::JSON.encode(request_body),
|
|
|
body: ActiveSupport::JSON.encode(closed)
|
|
|
-
|
|
|
- assert fulfillment_order.close(message: "Test close message.")
|
|
|
- assert_equal 'incomplete', fulfillment_order.status
|
|
|
+ )
|
|
|
+ assert(fulfillment_order.close(message: "Test close message."))
|
|
|
+ assert_equal('incomplete', fulfillment_order.status)
|
|
|
end
|
|
|
end
|
|
|
|
|
@@ -242,12 +250,13 @@ class FulFillmentOrderTest < Test::Unit::TestCase
|
|
|
message: 'Fulfill this FO, please.'
|
|
|
}
|
|
|
}
|
|
|
- fake 'fulfillment_orders',
|
|
|
+ fake(
|
|
|
+ 'fulfillment_orders',
|
|
|
url: "#{@url_prefix}/fulfillment_orders/519788021/fulfillment_request.json",
|
|
|
method: :post,
|
|
|
request_body: ActiveSupport::JSON.encode(request_body),
|
|
|
body: ActiveSupport::JSON.encode(body)
|
|
|
-
|
|
|
+ )
|
|
|
fulfillment_order = ShopifyAPI::FulfillmentOrder.find(519788021)
|
|
|
params = {
|
|
|
fulfillment_order_line_items: [{ id: 1, quantity: 1 }],
|
|
@@ -255,22 +264,22 @@ class FulFillmentOrderTest < Test::Unit::TestCase
|
|
|
}
|
|
|
response_fulfillment_orders = fulfillment_order.request_fulfillment(params)
|
|
|
|
|
|
- assert_equal 'closed', fulfillment_order.status
|
|
|
- assert_equal 3, response_fulfillment_orders.size
|
|
|
+ assert_equal('closed', fulfillment_order.status)
|
|
|
+ assert_equal(3, response_fulfillment_orders.size)
|
|
|
|
|
|
original_fulfillment_order = response_fulfillment_orders['original_fulfillment_order']
|
|
|
- assert_equal 519788021, original_fulfillment_order.id
|
|
|
- assert_equal 'closed', original_fulfillment_order.status
|
|
|
+ assert_equal(519788021, original_fulfillment_order.id)
|
|
|
+ assert_equal('closed', original_fulfillment_order.status)
|
|
|
|
|
|
submitted_fulfillment_order = response_fulfillment_orders['submitted_fulfillment_order']
|
|
|
- assert_equal 2, submitted_fulfillment_order.id
|
|
|
- assert_equal 'open', submitted_fulfillment_order.status
|
|
|
- assert_equal 'submitted', submitted_fulfillment_order.request_status
|
|
|
+ assert_equal(2, submitted_fulfillment_order.id)
|
|
|
+ assert_equal('open', submitted_fulfillment_order.status)
|
|
|
+ assert_equal('submitted', submitted_fulfillment_order.request_status)
|
|
|
|
|
|
unsubmitted_fulfillment_order = response_fulfillment_orders['unsubmitted_fulfillment_order']
|
|
|
- assert_equal 3, unsubmitted_fulfillment_order.id
|
|
|
- assert_equal 'open', unsubmitted_fulfillment_order.status
|
|
|
- assert_equal 'unsubmitted', unsubmitted_fulfillment_order.request_status
|
|
|
+ assert_equal(3, unsubmitted_fulfillment_order.id)
|
|
|
+ assert_equal('open', unsubmitted_fulfillment_order.status)
|
|
|
+ assert_equal('unsubmitted', unsubmitted_fulfillment_order.request_status)
|
|
|
end
|
|
|
|
|
|
should "make a fulfillment request for a fulfillment order excluding unsubmitted" do
|
|
@@ -293,12 +302,13 @@ class FulFillmentOrderTest < Test::Unit::TestCase
|
|
|
message: 'Fulfill this FO, please.'
|
|
|
}
|
|
|
}
|
|
|
- fake 'fulfillment_orders',
|
|
|
+ fake(
|
|
|
+ 'fulfillment_orders',
|
|
|
url: "#{@url_prefix}/fulfillment_orders/519788021/fulfillment_request.json",
|
|
|
method: :post,
|
|
|
request_body: ActiveSupport::JSON.encode(request_body),
|
|
|
body: ActiveSupport::JSON.encode(body)
|
|
|
-
|
|
|
+ )
|
|
|
fulfillment_order = ShopifyAPI::FulfillmentOrder.find(519788021)
|
|
|
params = {
|
|
|
fulfillment_order_line_items: [{ id: 1, quantity: 1 }],
|
|
@@ -306,19 +316,19 @@ class FulFillmentOrderTest < Test::Unit::TestCase
|
|
|
}
|
|
|
response_fulfillment_orders = fulfillment_order.request_fulfillment(params)
|
|
|
|
|
|
- assert_equal 'closed', fulfillment_order.status
|
|
|
- assert_equal 3, response_fulfillment_orders.size
|
|
|
+ assert_equal('closed', fulfillment_order.status)
|
|
|
+ assert_equal(3, response_fulfillment_orders.size)
|
|
|
|
|
|
original_fulfillment_order = response_fulfillment_orders['original_fulfillment_order']
|
|
|
- assert_equal 519788021, original_fulfillment_order.id
|
|
|
- assert_equal 'closed', original_fulfillment_order.status
|
|
|
+ assert_equal(519788021, original_fulfillment_order.id)
|
|
|
+ assert_equal('closed', original_fulfillment_order.status)
|
|
|
|
|
|
submitted_fulfillment_order = response_fulfillment_orders['submitted_fulfillment_order']
|
|
|
- assert_equal 2, submitted_fulfillment_order.id
|
|
|
- assert_equal 'open', submitted_fulfillment_order.status
|
|
|
- assert_equal 'submitted', submitted_fulfillment_order.request_status
|
|
|
+ assert_equal(2, submitted_fulfillment_order.id)
|
|
|
+ assert_equal('open', submitted_fulfillment_order.status)
|
|
|
+ assert_equal('submitted', submitted_fulfillment_order.request_status)
|
|
|
|
|
|
- assert_nil response_fulfillment_orders['unsubmitted_fulfillment_order']
|
|
|
+ assert_nil(response_fulfillment_orders['unsubmitted_fulfillment_order'])
|
|
|
end
|
|
|
end
|
|
|
|
|
@@ -335,17 +345,18 @@ class FulFillmentOrderTest < Test::Unit::TestCase
|
|
|
fake_response = {
|
|
|
fulfillment_order: fulfillment_order.attributes.merge(status: 'in_progress', request_status: 'accepted')
|
|
|
}
|
|
|
- fake 'fulfillment_orders',
|
|
|
+ fake(
|
|
|
+ 'fulfillment_orders',
|
|
|
url: "#{@url_prefix}/fulfillment_orders/519788021/fulfillment_request/accept.json",
|
|
|
method: :post,
|
|
|
request_body: ActiveSupport::JSON.encode(request_body),
|
|
|
body: ActiveSupport::JSON.encode(fake_response)
|
|
|
-
|
|
|
+ )
|
|
|
accepted = fulfillment_order.accept_fulfillment_request(message: message)
|
|
|
|
|
|
- assert_equal true, accepted
|
|
|
- assert_equal 'in_progress', fulfillment_order.status
|
|
|
- assert_equal 'accepted', fulfillment_order.request_status
|
|
|
+ assert_equal(true, accepted)
|
|
|
+ assert_equal('in_progress', fulfillment_order.status)
|
|
|
+ assert_equal('accepted', fulfillment_order.request_status)
|
|
|
end
|
|
|
end
|
|
|
|
|
@@ -362,17 +373,18 @@ class FulFillmentOrderTest < Test::Unit::TestCase
|
|
|
fake_response = {
|
|
|
fulfillment_order: fulfillment_order.attributes.merge(status: 'open', request_status: 'rejected')
|
|
|
}
|
|
|
- fake 'fulfillment_orders',
|
|
|
+ fake(
|
|
|
+ 'fulfillment_orders',
|
|
|
url: "#{@url_prefix}/fulfillment_orders/519788021/fulfillment_request/reject.json",
|
|
|
method: :post,
|
|
|
request_body: ActiveSupport::JSON.encode(request_body),
|
|
|
body: ActiveSupport::JSON.encode(fake_response)
|
|
|
-
|
|
|
+ )
|
|
|
rejected = fulfillment_order.reject_fulfillment_request(message: message)
|
|
|
|
|
|
- assert_equal true, rejected
|
|
|
- assert_equal 'open', fulfillment_order.status
|
|
|
- assert_equal 'rejected', fulfillment_order.request_status
|
|
|
+ assert_equal(true, rejected)
|
|
|
+ assert_equal('open', fulfillment_order.status)
|
|
|
+ assert_equal('rejected', fulfillment_order.request_status)
|
|
|
end
|
|
|
end
|
|
|
|
|
@@ -389,17 +401,18 @@ class FulFillmentOrderTest < Test::Unit::TestCase
|
|
|
cancelling = ActiveSupport::JSON.decode(load_fixture('fulfillment_order'))
|
|
|
cancelling['status'] = 'in_progress'
|
|
|
cancelling['request_status'] = 'cancellation_requested'
|
|
|
- fake 'fulfillment_orders',
|
|
|
+ fake(
|
|
|
+ 'fulfillment_orders',
|
|
|
url: "#{@url_prefix}/fulfillment_orders/519788021/cancellation_request.json",
|
|
|
method: :post,
|
|
|
request_body: ActiveSupport::JSON.encode(request_body),
|
|
|
body: ActiveSupport::JSON.encode({ fulfillment_order: cancelling })
|
|
|
-
|
|
|
+ )
|
|
|
cancelled = fulfillment_order.request_cancellation(message: "Cancelling this please.")
|
|
|
|
|
|
- assert_equal true, cancelled
|
|
|
- assert_equal 'in_progress', fulfillment_order.status
|
|
|
- assert_equal 'cancellation_requested', fulfillment_order.request_status
|
|
|
+ assert_equal(true, cancelled)
|
|
|
+ assert_equal('in_progress', fulfillment_order.status)
|
|
|
+ assert_equal('cancellation_requested', fulfillment_order.request_status)
|
|
|
end
|
|
|
end
|
|
|
|
|
@@ -417,17 +430,18 @@ class FulFillmentOrderTest < Test::Unit::TestCase
|
|
|
fulfillment_order: fulfillment_order.attributes.merge(status: 'cancelled',
|
|
|
request_status: 'cancellation_accepted')
|
|
|
}
|
|
|
- fake 'fulfillment_orders',
|
|
|
+ fake(
|
|
|
+ 'fulfillment_orders',
|
|
|
url: "#{@url_prefix}/fulfillment_orders/519788021/cancellation_request/accept.json",
|
|
|
method: :post,
|
|
|
request_body: ActiveSupport::JSON.encode(request_body),
|
|
|
body: ActiveSupport::JSON.encode(fake_response)
|
|
|
-
|
|
|
+ )
|
|
|
accepted = fulfillment_order.accept_cancellation_request(message: message)
|
|
|
|
|
|
- assert_equal true, accepted
|
|
|
- assert_equal 'cancelled', fulfillment_order.status
|
|
|
- assert_equal 'cancellation_accepted', fulfillment_order.request_status
|
|
|
+ assert_equal(true, accepted)
|
|
|
+ assert_equal('cancelled', fulfillment_order.status)
|
|
|
+ assert_equal('cancellation_accepted', fulfillment_order.request_status)
|
|
|
end
|
|
|
end
|
|
|
|
|
@@ -445,17 +459,18 @@ class FulFillmentOrderTest < Test::Unit::TestCase
|
|
|
fulfillment_order: fulfillment_order.attributes.merge(status: 'in_progress',
|
|
|
request_status: 'cancellation_rejected')
|
|
|
}
|
|
|
- fake 'fulfillment_orders',
|
|
|
+ fake(
|
|
|
+ 'fulfillment_orders',
|
|
|
url: "#{@url_prefix}/fulfillment_orders/519788021/cancellation_request/reject.json",
|
|
|
method: :post,
|
|
|
request_body: request_body,
|
|
|
body: ActiveSupport::JSON.encode(fake_response)
|
|
|
-
|
|
|
+ )
|
|
|
rejected = fulfillment_order.reject_cancellation_request(message: message)
|
|
|
|
|
|
- assert_equal true, rejected
|
|
|
- assert_equal 'in_progress', fulfillment_order.status
|
|
|
- assert_equal 'cancellation_rejected', fulfillment_order.request_status
|
|
|
+ assert_equal(true, rejected)
|
|
|
+ assert_equal('in_progress', fulfillment_order.status)
|
|
|
+ assert_equal('cancellation_rejected', fulfillment_order.request_status)
|
|
|
end
|
|
|
end
|
|
|
end
|