solidus_easypost 2.0.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +6 -0
- data/.github/stale.yml +4 -4
- data/.github_changelog_generator +2 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +3 -0
- data/.rubocop_todo.yml +12 -47
- data/CHANGELOG.md +113 -0
- data/LICENSE +1 -1
- data/README.md +111 -21
- data/app/controllers/spree/admin/postage_labels_controller.rb +20 -0
- data/app/decorators/models/solidus_easypost/spree/carton_decorator.rb +38 -0
- data/app/decorators/models/solidus_easypost/spree/shipment_decorator.rb +18 -23
- data/app/models/solidus_easypost/parcel_dimension.rb +34 -0
- data/app/models/solidus_easypost/return_authorization.rb +2 -13
- data/app/overrides/spree/admin/orders/_shipment/add_postage_label.html.erb.deface +10 -0
- data/bin/rails +0 -1
- data/bin/rails-engine +0 -2
- data/bin/rails-sandbox +1 -2
- data/bin/sandbox +2 -0
- data/config/initializers/webhooks.rb +7 -0
- data/config/locales/en.yml +7 -4
- data/config/routes.rb +5 -1
- data/db/migrate/20201025110912_add_tracker_id_to_cartons.rb +6 -0
- data/lib/generators/solidus_easypost/install/install_generator.rb +7 -1
- data/lib/generators/solidus_easypost/install/templates/initializer.rb +26 -0
- data/lib/solidus_easypost/address_builder.rb +45 -0
- data/lib/solidus_easypost/calculator/base_dimension_calculator.rb +28 -0
- data/lib/solidus_easypost/calculator/weight_dimension_calculator.rb +22 -0
- data/lib/solidus_easypost/configuration.rb +25 -2
- data/lib/solidus_easypost/errors/unknown_partial_resource_error.rb +11 -0
- data/lib/solidus_easypost/estimator.rb +37 -0
- data/lib/solidus_easypost/parcel_builder.rb +27 -0
- data/lib/solidus_easypost/shipment_builder.rb +32 -0
- data/lib/solidus_easypost/shipping_method_selector.rb +17 -0
- data/lib/solidus_easypost/shipping_rate_calculator.rb +9 -0
- data/lib/solidus_easypost/testing_support/factories/address_factory.rb +10 -0
- data/lib/solidus_easypost/testing_support/factories/product_factory.rb +7 -0
- data/lib/solidus_easypost/testing_support/factories/shipment_factory.rb +30 -0
- data/lib/solidus_easypost/testing_support/factories/shipping_method_factory.rb +8 -0
- data/lib/solidus_easypost/testing_support/factories/stock_location_factory.rb +10 -0
- data/lib/solidus_easypost/testing_support/factories/variant_factory.rb +7 -0
- data/lib/solidus_easypost/testing_support/factories.rb +3 -0
- data/lib/solidus_easypost/tracker_webhook_handler.rb +14 -0
- data/lib/solidus_easypost/version.rb +1 -1
- data/lib/solidus_easypost.rb +11 -0
- data/solidus_easypost.gemspec +8 -5
- data/spec/cassettes/{Spree_Address/_easypost_address/is_an_EasyPost_Address_object.yml → address_builder/from_address.yml} +19 -23
- data/spec/cassettes/{Spree_StockLocation/_easypost_address/is_an_EasyPost_Address_object.yml → address_builder/from_stock_location.yml} +19 -23
- data/spec/cassettes/{Spree_Stock_Estimator/_shipping_rates/when_rates_are_found/when_shipping_methods_exist/when_shipping_methods_are_front_end_visible/has_the_correct_costs.yml → estimator.yml} +0 -0
- data/spec/cassettes/integration/checkout.yml +377 -0
- data/spec/cassettes/integration/order_shipping/with_purchase_labels.yml +373 -0
- data/spec/cassettes/integration/order_shipping/without_purchase_labels.yml +251 -0
- data/spec/cassettes/{Spree_Stock_Package/_easypost_parcel/is_an_EasyPost_Parcel_object.yml → parcel_builder/from_package.yml} +17 -22
- data/spec/cassettes/{Spree_Stock_Package/_easypost_parcel/has_the_correct_attributes.yml → parcel_builder/from_return_authorization.yml} +17 -22
- data/spec/cassettes/postage_labels/show.yml +72 -0
- data/spec/cassettes/return_authorization.yml +310 -0
- data/spec/cassettes/{Spree_Stock_Package/_easypost_shipment/is_an_EasyPost_Shipment_object.yml → shipment_builder/from_package.yml} +74 -92
- data/spec/cassettes/{Spree_Stock_Estimator/_shipping_rates/when_rates_are_found/when_shipping_methods_exist/create_no_new_shipping_methods.yml → shipment_builder/from_return_authorization.yml} +77 -95
- data/spec/cassettes/shipment_builder/from_shipment.yml +250 -0
- data/spec/controllers/spree/admin/postage_labels_controller_spec.rb +18 -0
- data/spec/features/admin/postage_labels_spec.rb +18 -0
- data/spec/integration/checkout_spec.rb +45 -0
- data/spec/integration/order_shipping_spec.rb +33 -0
- data/spec/models/solidus_easypost/parcel_dimension_spec.rb +80 -0
- data/spec/models/solidus_easypost/return_authorization_spec.rb +7 -40
- data/spec/models/spree/carton_spec.rb +57 -0
- data/spec/models/spree/shipment_spec.rb +48 -59
- data/spec/models/spree/shipping_rate_spec.rb +14 -7
- data/spec/solidus_easypost/address_builder_spec.rb +17 -0
- data/spec/solidus_easypost/calculator/weight_dimension_calculator_spec.rb +39 -0
- data/spec/solidus_easypost/estimator_spec.rb +52 -0
- data/spec/solidus_easypost/parcel_builder_spec.rb +113 -0
- data/spec/solidus_easypost/shipment_builder_spec.rb +28 -0
- data/spec/solidus_easypost/shipping_method_selector_spec.rb +33 -0
- data/spec/solidus_easypost/shipping_rate_calculator_spec.rb +12 -0
- data/spec/solidus_easypost/tracker_webhook_handler_spec.rb +58 -0
- data/spec/spec_helper.rb +11 -7
- data/spec/support/easypost.rb +3 -1
- data/spec/support/helpers/api_stubs.rb +40 -0
- data/spec/support/helpers/configuration.rb +28 -0
- data/spec/support/helpers/shipping_methods.rb +26 -0
- data/spec/support/solidus.rb +1 -0
- data/spec/support/vcr.rb +1 -0
- metadata +118 -85
- data/app/decorators/models/solidus_easypost/spree/address_decorator.rb +0 -30
- data/app/decorators/models/solidus_easypost/spree/stock/estimator_decorator.rb +0 -15
- data/app/decorators/models/solidus_easypost/spree/stock/package_decorator.rb +0 -27
- data/app/decorators/models/solidus_easypost/spree/stock_location_decorator.rb +0 -26
- data/app/models/solidus_easypost/estimator.rb +0 -51
- data/lib/solidus_easypost/factories.rb +0 -24
- data/spec/cassettes/SolidusEasypost_ReturnAuthorization/_easypost_shipment/is_an_EasyPost_Shipment_object.yml +0 -271
- data/spec/cassettes/SolidusEasypost_ReturnAuthorization/_return_label/has_the_correct_fields.yml +0 -336
- data/spec/cassettes/SolidusEasypost_ReturnAuthorization/_return_label/is_an_EasyPost_PackageLabel_object.yml +0 -336
- data/spec/cassettes/Spree_Address/_easypost_address/has_the_correct_attributes.yml +0 -69
- data/spec/cassettes/Spree_Order/_refresh_shipment_rates/can_get_rates_from_easy_post.yml +0 -271
- data/spec/cassettes/Spree_Order/_refresh_shipment_rates/create_shipping_methods_for_the_rates.yml +0 -269
- data/spec/cassettes/Spree_Shipment/_buys_a_shipping_rate_after_transitioning_to_ship.yml +0 -403
- data/spec/cassettes/Spree_Shipment/_easypost_shipment/when_it_is_a_new_shipment/behaves_like_an_easypost_shipment/is_an_EasyPost_Shipment_object.yml +0 -271
- data/spec/cassettes/Spree_Shipment/_easypost_shipment/when_it_is_a_new_shipment/calls_the_api.yml +0 -200
- data/spec/cassettes/Spree_Shipment/_easypost_shipment/when_it_is_an_existing_shipment/behaves_like_an_easypost_shipment/is_an_EasyPost_Shipment_object.yml +0 -334
- data/spec/cassettes/Spree_Shipment/_easypost_shipment/when_it_is_an_existing_shipment/loads_the_existing_shipment.yml +0 -271
- data/spec/cassettes/Spree_StockLocation/_easypost_address/has_the_correct_attributes.yml +0 -69
- data/spec/cassettes/Spree_Stock_Estimator/_shipping_rates/when_rates_are_found/when_shipping_methods_dont_exist/creates_new_shipping_methods.yml +0 -269
- data/spec/cassettes/Spree_Stock_Estimator/_shipping_rates/when_rates_are_found/when_shipping_methods_dont_exist/is_empty.yml +0 -269
- data/spec/cassettes/Spree_Stock_Estimator/_shipping_rates/when_rates_are_found/when_shipping_methods_exist/when_shipping_methods_are_front_end_visible/has_the_correct_names.yml +0 -269
- data/spec/cassettes/Spree_Stock_Estimator/_shipping_rates/when_rates_are_found/when_shipping_methods_exist/when_shipping_methods_are_not_front_end_visible/is_empty.yml +0 -269
- data/spec/cassettes/Spree_Stock_Package/_easypost_shipment/calls_the_api.yml +0 -200
- data/spec/factories/spree_modification.rb +0 -25
- data/spec/models/spree/address_spec.rb +0 -31
- data/spec/models/spree/order_spec.rb +0 -31
- data/spec/models/spree/stock/estimator_spec.rb +0 -80
- data/spec/models/spree/stock/package_spec.rb +0 -35
- data/spec/models/spree/stock_location_spec.rb +0 -31
- data/spec/support/shipping_method_helpers.rb +0 -43
@@ -1,200 +0,0 @@
|
|
1
|
-
---
|
2
|
-
http_interactions:
|
3
|
-
- request:
|
4
|
-
method: post
|
5
|
-
uri: https://api.easypost.com/v2/addresses
|
6
|
-
body:
|
7
|
-
encoding: UTF-8
|
8
|
-
string: address[street1]=A%20Different%20Road&address[street2]=Northwest&address[city]=Manville&address[zip]=08835&address[phone]=555-555-0199&address[company]=Company&address[name]=John%20Doe&address[state]=NJ&address[country]=US
|
9
|
-
headers:
|
10
|
-
Accept:
|
11
|
-
- "*/*"
|
12
|
-
User-Agent:
|
13
|
-
- EasyPost/v2 RubyClient/3.0.1
|
14
|
-
Authorization:
|
15
|
-
- Bearer CvzYtuda6KRI9JjG7SAHbA
|
16
|
-
Content-Type:
|
17
|
-
- application/x-www-form-urlencoded
|
18
|
-
Content-Length:
|
19
|
-
- '222'
|
20
|
-
Accept-Encoding:
|
21
|
-
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
22
|
-
Host:
|
23
|
-
- api.easypost.com
|
24
|
-
response:
|
25
|
-
status:
|
26
|
-
code: 201
|
27
|
-
message: Created
|
28
|
-
headers:
|
29
|
-
X-Frame-Options:
|
30
|
-
- SAMEORIGIN
|
31
|
-
X-Xss-Protection:
|
32
|
-
- 1; mode=block
|
33
|
-
X-Content-Type-Options:
|
34
|
-
- nosniff
|
35
|
-
X-Ep-Request-Uuid:
|
36
|
-
- 43c6543d5dca6f16ee72769000010e06
|
37
|
-
Cache-Control:
|
38
|
-
- no-cache, no-store, must-revalidate, private
|
39
|
-
Pragma:
|
40
|
-
- no-cache
|
41
|
-
Expires:
|
42
|
-
- '0'
|
43
|
-
Location:
|
44
|
-
- "/api/v2/addresses/adr_9c58e500570b4bac916cf15d0b65306f"
|
45
|
-
Content-Type:
|
46
|
-
- application/json; charset=utf-8
|
47
|
-
X-Runtime:
|
48
|
-
- '0.029879'
|
49
|
-
Transfer-Encoding:
|
50
|
-
- chunked
|
51
|
-
X-Node:
|
52
|
-
- bigweb10sj
|
53
|
-
X-Version-Label:
|
54
|
-
- easypost-201911120131-f5c72b1880-master
|
55
|
-
X-Backend:
|
56
|
-
- easypost
|
57
|
-
X-Proxied:
|
58
|
-
- extlb2wdc 2744487620
|
59
|
-
- intlb1sj ff5a2958df
|
60
|
-
- intlb2wdc ff5a2958df
|
61
|
-
Strict-Transport-Security:
|
62
|
-
- max-age=15768000; includeSubDomains; preload
|
63
|
-
body:
|
64
|
-
encoding: ASCII-8BIT
|
65
|
-
string: '{"id":"adr_9c58e500570b4bac916cf15d0b65306f","object":"Address","created_at":"2019-11-12T08:36:38Z","updated_at":"2019-11-12T08:36:38Z","name":"John
|
66
|
-
Doe","company":"Company","street1":"A Different Road","street2":"Northwest","city":"Manville","state":"NJ","zip":"08835","country":"US","phone":"5555550199","email":null,"mode":"test","carrier_facility":null,"residential":null,"federal_tax_id":null,"state_tax_id":null,"verifications":{}}'
|
67
|
-
http_version:
|
68
|
-
recorded_at: Tue, 12 Nov 2019 08:36:38 GMT
|
69
|
-
- request:
|
70
|
-
method: post
|
71
|
-
uri: https://api.easypost.com/v2/addresses
|
72
|
-
body:
|
73
|
-
encoding: UTF-8
|
74
|
-
string: address[street1]=131%20S%208th%20Ave&address[city]=Manville&address[zip]=08835&address[phone]=(202)%20456-1111&address[name]=NY%20Warehouse&address[company]=NY%20Warehouse&address[state]=NJ&address[country]=US
|
75
|
-
headers:
|
76
|
-
Accept:
|
77
|
-
- "*/*"
|
78
|
-
User-Agent:
|
79
|
-
- EasyPost/v2 RubyClient/3.0.1
|
80
|
-
Authorization:
|
81
|
-
- Bearer CvzYtuda6KRI9JjG7SAHbA
|
82
|
-
Content-Type:
|
83
|
-
- application/x-www-form-urlencoded
|
84
|
-
Content-Length:
|
85
|
-
- '209'
|
86
|
-
Accept-Encoding:
|
87
|
-
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
88
|
-
Host:
|
89
|
-
- api.easypost.com
|
90
|
-
response:
|
91
|
-
status:
|
92
|
-
code: 201
|
93
|
-
message: Created
|
94
|
-
headers:
|
95
|
-
X-Frame-Options:
|
96
|
-
- SAMEORIGIN
|
97
|
-
X-Xss-Protection:
|
98
|
-
- 1; mode=block
|
99
|
-
X-Content-Type-Options:
|
100
|
-
- nosniff
|
101
|
-
X-Ep-Request-Uuid:
|
102
|
-
- 43c6543d5dca6f16ee82f63300010e0f
|
103
|
-
Cache-Control:
|
104
|
-
- no-cache, no-store, must-revalidate, private
|
105
|
-
Pragma:
|
106
|
-
- no-cache
|
107
|
-
Expires:
|
108
|
-
- '0'
|
109
|
-
Location:
|
110
|
-
- "/api/v2/addresses/adr_fb51793815514df0a43917b3cf1c7e96"
|
111
|
-
Content-Type:
|
112
|
-
- application/json; charset=utf-8
|
113
|
-
X-Runtime:
|
114
|
-
- '0.029274'
|
115
|
-
Transfer-Encoding:
|
116
|
-
- chunked
|
117
|
-
X-Node:
|
118
|
-
- bigweb2sj
|
119
|
-
X-Version-Label:
|
120
|
-
- easypost-201911120131-f5c72b1880-master
|
121
|
-
X-Backend:
|
122
|
-
- easypost
|
123
|
-
X-Proxied:
|
124
|
-
- extlb2wdc 2744487620
|
125
|
-
- intlb1wdc ff5a2958df
|
126
|
-
- intlb2sj ff5a2958df
|
127
|
-
Strict-Transport-Security:
|
128
|
-
- max-age=15768000; includeSubDomains; preload
|
129
|
-
body:
|
130
|
-
encoding: ASCII-8BIT
|
131
|
-
string: '{"id":"adr_fb51793815514df0a43917b3cf1c7e96","object":"Address","created_at":"2019-11-12T08:36:38Z","updated_at":"2019-11-12T08:36:38Z","name":"NY
|
132
|
-
Warehouse","company":"NY Warehouse","street1":"131 S 8th Ave","street2":null,"city":"Manville","state":"NJ","zip":"08835","country":"US","phone":"2024561111","email":null,"mode":"test","carrier_facility":null,"residential":null,"federal_tax_id":null,"state_tax_id":null,"verifications":{}}'
|
133
|
-
http_version:
|
134
|
-
recorded_at: Tue, 12 Nov 2019 08:36:39 GMT
|
135
|
-
- request:
|
136
|
-
method: post
|
137
|
-
uri: https://api.easypost.com/v2/parcels
|
138
|
-
body:
|
139
|
-
encoding: UTF-8
|
140
|
-
string: parcel[weight]=10.0
|
141
|
-
headers:
|
142
|
-
Accept:
|
143
|
-
- "*/*"
|
144
|
-
User-Agent:
|
145
|
-
- EasyPost/v2 RubyClient/3.0.1
|
146
|
-
Authorization:
|
147
|
-
- Bearer CvzYtuda6KRI9JjG7SAHbA
|
148
|
-
Content-Type:
|
149
|
-
- application/x-www-form-urlencoded
|
150
|
-
Content-Length:
|
151
|
-
- '19'
|
152
|
-
Accept-Encoding:
|
153
|
-
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
154
|
-
Host:
|
155
|
-
- api.easypost.com
|
156
|
-
response:
|
157
|
-
status:
|
158
|
-
code: 201
|
159
|
-
message: Created
|
160
|
-
headers:
|
161
|
-
X-Frame-Options:
|
162
|
-
- SAMEORIGIN
|
163
|
-
X-Xss-Protection:
|
164
|
-
- 1; mode=block
|
165
|
-
X-Content-Type-Options:
|
166
|
-
- nosniff
|
167
|
-
X-Ep-Request-Uuid:
|
168
|
-
- 43c6543d5dca6f17ee824c2900010e16
|
169
|
-
Cache-Control:
|
170
|
-
- no-cache, no-store, must-revalidate, private
|
171
|
-
Pragma:
|
172
|
-
- no-cache
|
173
|
-
Expires:
|
174
|
-
- '0'
|
175
|
-
Location:
|
176
|
-
- "/api/v2/parcels/prcl_87cf02727d354a2a98b112bfc3585735"
|
177
|
-
Content-Type:
|
178
|
-
- application/json; charset=utf-8
|
179
|
-
X-Runtime:
|
180
|
-
- '0.025857'
|
181
|
-
Transfer-Encoding:
|
182
|
-
- chunked
|
183
|
-
X-Node:
|
184
|
-
- bigweb2sj
|
185
|
-
X-Version-Label:
|
186
|
-
- easypost-201911120131-f5c72b1880-master
|
187
|
-
X-Backend:
|
188
|
-
- easypost
|
189
|
-
X-Proxied:
|
190
|
-
- extlb2wdc 2744487620
|
191
|
-
- intlb1sj ff5a2958df
|
192
|
-
- intlb2wdc ff5a2958df
|
193
|
-
Strict-Transport-Security:
|
194
|
-
- max-age=15768000; includeSubDomains; preload
|
195
|
-
body:
|
196
|
-
encoding: ASCII-8BIT
|
197
|
-
string: '{"id":"prcl_87cf02727d354a2a98b112bfc3585735","object":"Parcel","created_at":"2019-11-12T08:36:39Z","updated_at":"2019-11-12T08:36:39Z","length":null,"width":null,"height":null,"predefined_package":null,"weight":10.0,"mode":"test"}'
|
198
|
-
http_version:
|
199
|
-
recorded_at: Tue, 12 Nov 2019 08:36:39 GMT
|
200
|
-
recorded_with: VCR 5.0.0
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spree/testing_support/factories'
|
4
|
-
require 'solidus_easypost/factories'
|
5
|
-
|
6
|
-
FactoryBot.modify do
|
7
|
-
factory :shipping_method do
|
8
|
-
admin_name { 'Stuff' }
|
9
|
-
available_to_users { true }
|
10
|
-
end
|
11
|
-
|
12
|
-
factory :stock_location do
|
13
|
-
address1 { '131 S 8th Ave' }
|
14
|
-
city { 'Manville' }
|
15
|
-
association(:state, name: 'New Jersey', abbr: 'NJ')
|
16
|
-
zipcode { '08835' }
|
17
|
-
end
|
18
|
-
|
19
|
-
factory :address do
|
20
|
-
address1 { '215 N 7th Ave' }
|
21
|
-
city { 'Manville' }
|
22
|
-
association(:state, name: 'New Jersey', abbr: 'NJ')
|
23
|
-
zipcode { '08835' }
|
24
|
-
end
|
25
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe Spree::Address, :vcr do
|
6
|
-
let(:address) { create :address }
|
7
|
-
|
8
|
-
describe '#easypost_address' do
|
9
|
-
subject { address.easypost_address }
|
10
|
-
|
11
|
-
it 'is an EasyPost::Address object' do
|
12
|
-
expect(subject).to be_a(EasyPost::Address)
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'has the correct attributes' do
|
16
|
-
# combination of original address factory from easy post
|
17
|
-
# and the spree_modification factories
|
18
|
-
expect(subject).to have_attributes(
|
19
|
-
name: 'John Doe',
|
20
|
-
company: 'Company',
|
21
|
-
street1: '215 N 7th Ave',
|
22
|
-
street2: 'Northwest',
|
23
|
-
city: 'Manville',
|
24
|
-
state: 'NJ',
|
25
|
-
zip: '08835',
|
26
|
-
country: 'US',
|
27
|
-
phone: '5555550199'
|
28
|
-
)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe Spree::Order, :vcr do
|
6
|
-
let(:order) do
|
7
|
-
create(:order_with_line_items, line_items_count: 1) do |order|
|
8
|
-
order.variants.each { |v| v.update! weight: 10 }
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
describe '#refresh_shipment_rates' do
|
13
|
-
it "can get rates from easy post" do
|
14
|
-
order.refresh_shipment_rates
|
15
|
-
|
16
|
-
rates = order.shipments.first.shipping_rates
|
17
|
-
|
18
|
-
expect(rates.all? { |rate| rate.cost.present? }).to be_present
|
19
|
-
expect(rates.all?(&:easy_post_shipment_id?)).to be_present
|
20
|
-
expect(rates.all?(&:easy_post_rate_id?)).to be_present
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'create shipping methods for the rates' do
|
24
|
-
order.refresh_shipment_rates
|
25
|
-
|
26
|
-
rates = order.shipments.first.shipping_rates
|
27
|
-
|
28
|
-
expect(rates).to(be_all { |rate| rate.shipping_method.present? })
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,80 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe Spree::Stock::Estimator, :vcr do
|
6
|
-
if Spree.solidus_gem_version < Gem::Version.new("1.3")
|
7
|
-
let(:estimator) { described_class.new(shipment.order) }
|
8
|
-
else
|
9
|
-
let(:estimator) { described_class.new }
|
10
|
-
end
|
11
|
-
|
12
|
-
let!(:shipment) { create :shipment }
|
13
|
-
let(:package) { shipment.to_package }
|
14
|
-
|
15
|
-
describe '#shipping_rates' do
|
16
|
-
subject { estimator.shipping_rates package }
|
17
|
-
|
18
|
-
context 'when rates are found' do
|
19
|
-
context 'when shipping methods exist' do
|
20
|
-
before { create_shipping_methods }
|
21
|
-
|
22
|
-
it 'create no new shipping methods' do
|
23
|
-
expect { subject }.not_to change(Spree::ShippingMethod, :count)
|
24
|
-
end
|
25
|
-
|
26
|
-
context 'when shipping methods are front end visible' do
|
27
|
-
let(:rate_names) { ["USPS Express", "USPS First", "USPS ParcelSelect", "USPS Priority"] }
|
28
|
-
let(:rate_costs) { [3.82, 6.85, 6.95, 22.74] }
|
29
|
-
|
30
|
-
it 'has the correct names' do
|
31
|
-
names = subject.map(&:name).sort
|
32
|
-
expect(names).to eq rate_names
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'has the correct costs' do
|
36
|
-
costs = subject.map(&:cost).sort
|
37
|
-
expect(costs).to eq rate_costs
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context 'when shipping methods are not front end visible' do
|
42
|
-
before { Spree::ShippingMethod.find_each { |x| x.update!(available_to_users: false) } }
|
43
|
-
|
44
|
-
it 'is empty' do
|
45
|
-
expect(subject).to be_empty
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
context 'when shipping methods dont exist' do
|
51
|
-
# new shipping methods are backend only
|
52
|
-
it 'is empty' do
|
53
|
-
expect(subject).to be_empty
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'creates new shipping methods' do
|
57
|
-
expect { subject }.to change { Spree::ShippingMethod.count }.by 4
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
context 'when no rates are found' do
|
63
|
-
let(:package) do
|
64
|
-
instance_double(Spree::Stock::Package, easypost_shipment: fake_shipment)
|
65
|
-
end
|
66
|
-
|
67
|
-
let(:fake_shipment) do
|
68
|
-
double(EasyPost::Shipment, rates: [])
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'is empty' do
|
72
|
-
expect(subject).to be_empty
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'create no new shipping methods' do
|
76
|
-
expect { subject }.not_to change(Spree::ShippingMethod, :count)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Spree::Stock::Package, :vcr do
|
6
|
-
let(:package) { create(:shipment).to_package }
|
7
|
-
|
8
|
-
describe '#easypost_parcel' do
|
9
|
-
subject { package.easypost_parcel }
|
10
|
-
|
11
|
-
it 'is an EasyPost::Parcel object' do
|
12
|
-
expect(subject).to be_a(EasyPost::Parcel)
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'has the correct attributes' do
|
16
|
-
expect(subject).to have_attributes(
|
17
|
-
object: 'Parcel',
|
18
|
-
weight: 10.0
|
19
|
-
)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe '#easypost_shipment' do
|
24
|
-
subject { package.easypost_shipment }
|
25
|
-
|
26
|
-
it 'is an EasyPost::Shipment object' do
|
27
|
-
expect(subject).to be_a(EasyPost::Shipment)
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'calls the api' do
|
31
|
-
expect(EasyPost::Shipment).to receive(:create).with(anything)
|
32
|
-
subject
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe Spree::StockLocation, :vcr do
|
6
|
-
let(:stock_location) { create :stock_location }
|
7
|
-
|
8
|
-
describe '#easypost_address' do
|
9
|
-
subject { stock_location.easypost_address }
|
10
|
-
|
11
|
-
it 'is an EasyPost::Address object' do
|
12
|
-
expect(subject).to be_a(EasyPost::Address)
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'has the correct attributes' do
|
16
|
-
# combination of original address factory from easy post
|
17
|
-
# and the spree_modification factories
|
18
|
-
expect(subject).to have_attributes(
|
19
|
-
name: 'NY Warehouse',
|
20
|
-
company: 'NY Warehouse',
|
21
|
-
street1: '131 S 8th Ave',
|
22
|
-
street2: nil,
|
23
|
-
city: 'Manville',
|
24
|
-
state: 'NJ',
|
25
|
-
zip: '08835',
|
26
|
-
country: 'US',
|
27
|
-
phone: '2024561111'
|
28
|
-
)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ShippingMethodHelpers
|
4
|
-
FIXTURE_PARAMS = [
|
5
|
-
{
|
6
|
-
name: "USPS First",
|
7
|
-
available_to_users: true,
|
8
|
-
admin_name: "USPS First",
|
9
|
-
code: "First"
|
10
|
-
},
|
11
|
-
{
|
12
|
-
name: "USPS Priority",
|
13
|
-
available_to_users: true,
|
14
|
-
admin_name: "USPS Priority",
|
15
|
-
code: "Priority"
|
16
|
-
},
|
17
|
-
{
|
18
|
-
name: "USPS ParcelSelect",
|
19
|
-
available_to_users: true,
|
20
|
-
admin_name: "USPS ParcelSelect",
|
21
|
-
code: "ParcelSelect"
|
22
|
-
},
|
23
|
-
{
|
24
|
-
name: "USPS Express",
|
25
|
-
available_to_users: true,
|
26
|
-
admin_name: "USPS Express",
|
27
|
-
code: "Express"
|
28
|
-
}
|
29
|
-
].freeze
|
30
|
-
|
31
|
-
def create_shipping_methods
|
32
|
-
shipping_category = create :shipping_category
|
33
|
-
FIXTURE_PARAMS.each do |params|
|
34
|
-
params[:calculator] = Spree::Calculator::Shipping::FlatRate.new
|
35
|
-
params[:shipping_categories] = [shipping_category]
|
36
|
-
Spree::ShippingMethod.create! params
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
RSpec.configure do |config|
|
42
|
-
config.include ShippingMethodHelpers
|
43
|
-
end
|