@@ -56,6 +56,102 @@ def setup
56
56
assert_equal 450789469 , fulfillment . order_id
57
57
end
58
58
end
59
+
60
+ context "#create" do
61
+ should "create a new fulfillment" do
62
+ create_fulfillment_attributes = {
63
+ message : "The message for this FO fulfillment" ,
64
+ notify_customer : true ,
65
+ tracking_info : {
66
+ number : "XSDFHYR23475" ,
67
+ url : "https://tracking.example.com/XSDFHYR23475" ,
68
+ company : "TFTC - the fulfillment/tracking company"
69
+ } ,
70
+ line_items_by_fulfillment_order : [
71
+ {
72
+ fulfillment_order_id : 3 ,
73
+ fulfillment_order_line_items : [ { id : 2 , quantity : 1 } ]
74
+ }
75
+ ]
76
+ }
77
+ request_body = { fulfillment : create_fulfillment_attributes }
78
+ response_body = { fulfillment : create_fulfillment_attributes . merge ( id : 346743624 ) }
79
+ fake "fulfillments" , :method => :post ,
80
+ request_body : ActiveSupport ::JSON . encode ( request_body ) ,
81
+ body : ActiveSupport ::JSON . encode ( response_body )
82
+
83
+ fulfillment = ShopifyAPI ::Fulfillment . create ( create_fulfillment_attributes )
84
+ assert fulfillment . is_a? ( ShopifyAPI ::Fulfillment )
85
+ assert fulfillment . persisted?
86
+ assert_equal 346743624 , fulfillment . id
87
+ end
88
+ end
89
+
90
+ context "#save" do
91
+ should "save a new fulfillment" do
92
+ create_fulfillment_attributes = {
93
+ message : "The message for this FO fulfillment" ,
94
+ notify_customer : true ,
95
+ tracking_info : {
96
+ number : "XSDFHYR23475" ,
97
+ url : "https://tracking.example.com/XSDFHYR23475" ,
98
+ company : "TFTC - the fulfillment/tracking company"
99
+ } ,
100
+ line_items_by_fulfillment_order : [
101
+ {
102
+ fulfillment_order_id : 3 ,
103
+ fulfillment_order_line_items : [ { id : 2 , quantity : 1 } ]
104
+ }
105
+ ]
106
+ }
107
+ request_body = { fulfillment : create_fulfillment_attributes }
108
+ response_body = { fulfillment : create_fulfillment_attributes . merge ( id : 346743624 ) }
109
+ fake "fulfillments" , :method => :post ,
110
+ request_body : ActiveSupport ::JSON . encode ( request_body ) ,
111
+ body : ActiveSupport ::JSON . encode ( response_body )
112
+
113
+ fulfillment = ShopifyAPI ::Fulfillment . new ( create_fulfillment_attributes )
114
+ assert fulfillment . save
115
+ assert fulfillment . is_a? ( ShopifyAPI ::Fulfillment )
116
+ assert fulfillment . persisted?
117
+ assert_equal 346743624 , fulfillment . id
118
+ end
119
+ end
120
+
121
+ context "#update_tracking" do
122
+ should "be able to update tracking info for a fulfillment" do
123
+ tracking_info = {
124
+ number : 'JSDHFHAG' ,
125
+ url : 'https://example.com/fulfillment_tracking/JSDHFHAG' ,
126
+ company : 'ACME co' ,
127
+ }
128
+ fake_fulfillment = ActiveSupport ::JSON . decode ( load_fixture ( 'fulfillment' ) ) [ 'fulfillment' ]
129
+ fake_fulfillment [ 'tracking_number' ] = tracking_info [ :number ]
130
+ fake_fulfillment [ 'tracking_numbers' ] = [ tracking_info [ :number ] ]
131
+ fake_fulfillment [ 'tracking_url' ] = tracking_info [ :url ]
132
+ fake_fulfillment [ 'tracking_urls' ] = [ tracking_info [ :url ] ]
133
+ fake_fulfillment [ 'tracking_company' ] = tracking_info [ :company ]
134
+
135
+ request_body = {
136
+ fulfillment : {
137
+ tracking_info : tracking_info ,
138
+ notify_customer : true
139
+ }
140
+ }
141
+ fake "fulfillments/#{ fake_fulfillment [ 'id' ] } /update_tracking" , method : :post ,
142
+ request_body : ActiveSupport ::JSON . encode ( request_body ) ,
143
+ body : ActiveSupport ::JSON . encode ( fulfillment : fake_fulfillment )
144
+
145
+ fulfillment = ShopifyAPI ::Fulfillment . new ( id : fake_fulfillment [ 'id' ] )
146
+ assert fulfillment . update_tracking ( tracking_info : tracking_info , notify_customer : true )
147
+
148
+ assert_equal tracking_info [ :number ] , fulfillment . tracking_number
149
+ assert_equal [ tracking_info [ :number ] ] , fulfillment . tracking_numbers
150
+ assert_equal tracking_info [ :url ] , fulfillment . tracking_url
151
+ assert_equal [ tracking_info [ :url ] ] , fulfillment . tracking_urls
152
+ assert_equal tracking_info [ :company ] , fulfillment . tracking_company
153
+ end
154
+ end
59
155
end
60
156
61
157
end
0 commit comments