@@ -33,6 +33,17 @@ def setup
33
33
assert fulfillment . cancel
34
34
assert_equal 'cancelled' , fulfillment . status
35
35
end
36
+
37
+ should "be able to cancel fulfillment that uses fulfiment orders" do
38
+ fake_fulfillment = ActiveSupport ::JSON . decode ( load_fixture ( 'fulfillment' ) ) [ 'fulfillment' ]
39
+ fake_fulfillment [ 'status' ] = 'cancelled'
40
+ fake "fulfillments/#{ fake_fulfillment [ 'id' ] } /cancel" , method : :post ,
41
+ body : ActiveSupport ::JSON . encode ( fulfillment : fake_fulfillment )
42
+
43
+ fulfillment = ShopifyAPI ::Fulfillment . new ( id : fake_fulfillment [ 'id' ] )
44
+ assert fulfillment . cancel ( using_fulfillment_orders : true )
45
+ assert_equal 'cancelled' , fulfillment . status
46
+ end
36
47
end
37
48
38
49
context "#open" do
@@ -56,6 +67,70 @@ def setup
56
67
assert_equal 450789469 , fulfillment . order_id
57
68
end
58
69
end
70
+
71
+ context "#create" do
72
+ should "be able to create a fulfillment order fulfillment" do
73
+ create_fulfillment_attributes = {
74
+ message : "The message for this FO fulfillment" ,
75
+ notify_customer : true ,
76
+ tracking_info : {
77
+ number : "XSDFHYR23475" ,
78
+ url : "https://tracking.example.com/XSDFHYR23475" ,
79
+ company : "TFTC - the fulfillment/tracking company"
80
+ } ,
81
+ line_items_by_fulfillment_order : [
82
+ {
83
+ fulfillment_order_id : 3 ,
84
+ fulfillment_order_line_items : [ { id : 2 , quantity : 1 } ]
85
+ }
86
+ ]
87
+ }
88
+ request_body = { fulfillment : create_fulfillment_attributes }
89
+ response_body = { fulfillment : create_fulfillment_attributes . merge ( id : 346743624 ) }
90
+ fake "fulfillments" , :method => :post ,
91
+ request_body : ActiveSupport ::JSON . encode ( request_body ) ,
92
+ body : ActiveSupport ::JSON . encode ( response_body )
93
+
94
+ fulfillment = ShopifyAPI ::Fulfillment . new ( create_fulfillment_attributes )
95
+ assert fulfillment . save
96
+ assert_equal 346743624 , fulfillment . id
97
+ end
98
+ end
99
+
100
+ context "#update_tracking" do
101
+ should "be able to update tracking info for a fulfillment" do
102
+ tracking_info = {
103
+ number : 'JSDHFHAG' ,
104
+ url : 'https://example.com/fulfillment_tracking/JSDHFHAG' ,
105
+ company : 'ACME co' ,
106
+ }
107
+ fake_fulfillment = ActiveSupport ::JSON . decode ( load_fixture ( 'fulfillment' ) ) [ 'fulfillment' ]
108
+ fake_fulfillment [ 'tracking_number' ] = tracking_info [ :number ]
109
+ fake_fulfillment [ 'tracking_numbers' ] = [ tracking_info [ :number ] ]
110
+ fake_fulfillment [ 'tracking_url' ] = tracking_info [ :url ]
111
+ fake_fulfillment [ 'tracking_urls' ] = [ tracking_info [ :url ] ]
112
+ fake_fulfillment [ 'tracking_company' ] = tracking_info [ :company ]
113
+
114
+ request_body = {
115
+ fulfillment : {
116
+ tracking_info : tracking_info ,
117
+ notify_customer : true
118
+ }
119
+ }
120
+ fake "fulfillments/#{ fake_fulfillment [ 'id' ] } /update_tracking" , method : :post ,
121
+ request_body : ActiveSupport ::JSON . encode ( request_body ) ,
122
+ body : ActiveSupport ::JSON . encode ( fulfillment : fake_fulfillment )
123
+
124
+ fulfillment = ShopifyAPI ::Fulfillment . new ( id : fake_fulfillment [ 'id' ] )
125
+ assert fulfillment . update_tracking ( tracking_info : tracking_info , notify_customer : true )
126
+
127
+ assert_equal tracking_info [ :number ] , fulfillment . tracking_number
128
+ assert_equal [ tracking_info [ :number ] ] , fulfillment . tracking_numbers
129
+ assert_equal tracking_info [ :url ] , fulfillment . tracking_url
130
+ assert_equal [ tracking_info [ :url ] ] , fulfillment . tracking_urls
131
+ assert_equal tracking_info [ :company ] , fulfillment . tracking_company
132
+ end
133
+ end
59
134
end
60
135
61
136
end
0 commit comments