-
Notifications
You must be signed in to change notification settings - Fork 474
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add move, cancel, close actions FulfillmentOrder #635
Add move, cancel, close actions FulfillmentOrder #635
Conversation
A few questions:
|
1d26023
to
6dae6dd
Compare
d4f26b4
to
cfb265f
Compare
6dae6dd
to
e66255e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of comments to make sure I am following the logic here. Thank you again for handling this 🙏
body = { fulfillment_order: { new_location_id: new_location_id } }.to_json | ||
keyed_fos = load_keyed_attributes_from_response(post(:move, {}, body)) | ||
if keyed_fos&.fetch('original_fulfillment_order', nil)&.attributes | ||
load(keyed_fos['original_fulfillment_order'].attributes, false, true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just for my personal comprehension here but what are you trying to achieve here ? Specifically why does this check only apply to the original_fulfillment_order
?
Are you using it to determine wether or not we got here with the error message
payload ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was a bit uncertain about this one. The request is made using an instance of a FulfillmentOrder, e.g. fulfillment_order.move(...)
where the server responds with multiple keyed FOs. I took the one named original_fulfillment_order
to represent the mutation of the fulfillment_order
that was the subject of the .move
and so load the attributes of original_fulfillment_order
into itself.
This is following the pattern where responses that return a single FO and calling load_attributes_from_response
will load the calling object's attrributes from the only keyed value.
|
||
def cancel | ||
keyed_fos = load_keyed_attributes_from_response(post(:cancel, {}, only_id)) | ||
if keyed_fos&.fetch('fulfillment_order', nil)&.attributes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same question as above about why specifically this key ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This key represents the mutation of the subject FO resource issuing the .cancel
.
e66255e
to
634d2b3
Compare
702b858
to
c72bff7
Compare
634d2b3
to
a47cdba
Compare
else | ||
[key, FulfillmentOrder.new(fo_attributes)] | ||
end | ||
end.to_h |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: a simpler way to do this would be to use transform_values
method:
keyed_fulfillment_orders.transform_values do |fulfillment_order|
fulfillment_order.nil? nil : FulfillmentOrder.new(fulfillment_order)
end
def move(new_location_id:) | ||
body = { fulfillment_order: { new_location_id: new_location_id } }.to_json | ||
keyed_fos = load_keyed_fulfillment_orders_from_response(post(:move, {}, body)) | ||
if keyed_fos&.fetch('original_fulfillment_order', nil)&.attributes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe consider extracting this into a private method def load_attributes_from_response_for(fulfillment_order_key:)
since it's used both in this PR and in https://github.com/Shopify/shopify_api/pull/637/files
test/fulfillment_order_test.rb
Outdated
fulfillment_order = ShopifyAPI::FulfillmentOrder.find(519788021) | ||
new_location_id = 5 | ||
|
||
original = fulfillment_order.clone |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was confused reading this at first, would be easier to understand if we rename this to original_fulfillment_order_response
an moved_fulfillment_order_response
so that it's more clear the intention of declaring these variables.
test/fulfillment_order_test.rb
Outdated
assert_equal 3, response_fos.count | ||
original_fulfillment_order = response_fos['original_fulfillment_order'] | ||
refute_nil original_fulfillment_order | ||
assert_equal 'ShopifyAPI::FulfillmentOrder', original_fulfillment_order.class.name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: assert original_fulfillment_order.is_a?(ShopifyApi::FulfillmentOrder)
assert_equal new_location_id, moved_fulfillment_order.assigned_location_id | ||
|
||
remaining_fulfillment_order = response_fos['remaining_fulfillment_order'] | ||
assert_nil remaining_fulfillment_order |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can be compressed to assert_nil response_fos['remaining_fulfillment_order']
test/fulfillment_order_test.rb
Outdated
|
||
assert_equal 'cancelled', fulfillment_order.status | ||
assert_equal 2, response_fos.count | ||
fulfillment_order = response_fos['fulfillment_order'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rename this to something other than fulfillment_order
, maybe response_fulfillment_order
.
fde9c1e
to
738e870
Compare
a47cdba
to
1a48c0e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One small necessary change (allowing apps to provide a message when closing a fulfillment order) and some nits. Other than that LGTM!
1a48c0e
to
2bbefa9
Compare
d110aeb
to
0870528
Compare
2bbefa9
to
741c27e
Compare
0870528
to
b0350cb
Compare
621057d
to
563d01d
Compare
6fc2312
to
50bd958
Compare
50bd958
to
6fc2312
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great after reading all the conversations from previous reviews. It is interesting that the caller fulfillment_order
needs to be loaded manually. I think the fact that we want to support both order/#{order_id}/fulfillment_orders
and fulfillment_orders/#{fulfillment_order_id}
made things a bit tricky. Also we return multiple keyed resources.
563d01d
to
eb38d9a
Compare
This PR adds the following POST requests:
POST fulfillment_orders/:fulfillment_order_id/move
POST fulfillment_orders/:fulfillment_order_id/cancel
POST fulfillment_orders/:fulfillment_order_id/close
GET requests are in PR #633
Subsequent PRs will add other fulfillment order related write requests to relevant resources.
The approach I took was to add the
move
,cancel
, andclose
actions on theFulfillmentOrder
resource.Because there's already a legacy
Fulfillment
resource, I named the fulfillment orders fulfillment asFulfillmentOrderFulfillment
.Since all that's really needed is the
fulfillment_order_id
, if it's known you can do (rather than querying it first):