patch_ruby 1.24.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +1 -1
- data/README.md +11 -11
- data/lib/patch_ruby/api/estimates_api.rb +142 -2
- data/lib/patch_ruby/api/order_line_items_api.rb +269 -0
- data/lib/patch_ruby/api/orders_api.rb +99 -4
- data/lib/patch_ruby/api/projects_api.rb +12 -2
- data/lib/patch_ruby/api/technology_types_api.rb +7 -2
- data/lib/patch_ruby/api_client.rb +3 -3
- data/lib/patch_ruby/api_error.rb +2 -2
- data/lib/patch_ruby/configuration.rb +2 -2
- data/lib/patch_ruby/models/create_air_shipping_estimate_request.rb +3 -3
- data/lib/patch_ruby/models/create_bitcoin_estimate_request.rb +2 -2
- data/lib/patch_ruby/models/create_ecommerce_estimate_request.rb +373 -0
- data/lib/patch_ruby/models/create_ethereum_estimate_request.rb +2 -2
- data/lib/patch_ruby/models/create_flight_estimate_request.rb +2 -2
- data/lib/patch_ruby/models/create_hotel_estimate_request.rb +2 -2
- data/lib/patch_ruby/models/create_mass_estimate_request.rb +2 -2
- data/lib/patch_ruby/models/create_order_line_item_request.rb +375 -0
- data/lib/patch_ruby/models/create_order_request.rb +8 -67
- data/lib/patch_ruby/models/create_rail_shipping_estimate_request.rb +3 -3
- data/lib/patch_ruby/models/create_road_shipping_estimate_request.rb +3 -3
- data/lib/patch_ruby/models/create_sea_shipping_estimate_request.rb +3 -3
- data/lib/patch_ruby/models/create_shipping_estimate_request.rb +2 -2
- data/lib/patch_ruby/models/create_success_response.rb +2 -2
- data/lib/patch_ruby/models/create_vehicle_estimate_request.rb +2 -2
- data/lib/patch_ruby/models/delete_order_line_item_response.rb +257 -0
- data/lib/patch_ruby/models/delete_order_response.rb +257 -0
- data/lib/patch_ruby/models/error_response.rb +2 -2
- data/lib/patch_ruby/models/estimate.rb +2 -2
- data/lib/patch_ruby/models/estimate_list_response.rb +2 -2
- data/lib/patch_ruby/models/estimate_response.rb +2 -2
- data/lib/patch_ruby/models/highlight.rb +2 -2
- data/lib/patch_ruby/models/inventory.rb +2 -2
- data/lib/patch_ruby/models/meta_index_object.rb +2 -2
- data/lib/patch_ruby/models/order.rb +11 -115
- data/lib/patch_ruby/models/order_issued_to.rb +2 -2
- data/lib/patch_ruby/models/{order_inventory.rb → order_line_item.rb} +19 -9
- data/lib/patch_ruby/models/{order_inventory_project.rb → order_line_item_project.rb} +7 -7
- data/lib/patch_ruby/models/{allocation.rb → order_line_item_response.rb} +33 -40
- data/lib/patch_ruby/models/order_list_response.rb +2 -2
- data/lib/patch_ruby/models/order_response.rb +2 -2
- data/lib/patch_ruby/models/parent_technology_type.rb +2 -2
- data/lib/patch_ruby/models/photo.rb +2 -2
- data/lib/patch_ruby/models/place_order_request.rb +2 -2
- data/lib/patch_ruby/models/project.rb +13 -53
- data/lib/patch_ruby/models/project_list_response.rb +2 -2
- data/lib/patch_ruby/models/project_response.rb +2 -2
- data/lib/patch_ruby/models/sdg.rb +2 -2
- data/lib/patch_ruby/models/standard.rb +2 -2
- data/lib/patch_ruby/models/technology_type.rb +2 -2
- data/lib/patch_ruby/models/technology_type_list_response.rb +2 -2
- data/lib/patch_ruby/models/update_order_line_item_request.rb +366 -0
- data/lib/patch_ruby/version.rb +3 -3
- data/lib/patch_ruby.rb +11 -5
- data/patch_ruby.gemspec +2 -2
- data/spec/api/order_line_items_api_spec.rb +78 -0
- data/spec/api_client_spec.rb +2 -2
- data/spec/configuration_spec.rb +2 -2
- data/spec/factories/create_order_requests.rb +4 -2
- data/spec/factories/orders.rb +5 -4
- data/spec/factories/projects.rb +1 -4
- data/spec/integration/estimates_spec.rb +29 -16
- data/spec/integration/orders_spec.rb +85 -44
- data/spec/integration/projects_spec.rb +2 -4
- data/spec/models/create_order_request_spec.rb +10 -3
- data/spec/models/order_spec.rb +8 -23
- data/spec/models/project_spec.rb +1 -4
- data/spec/spec_helper.rb +2 -2
- metadata +35 -31
- data/spec/factories/allocations.rb +0 -7
- data/spec/models/allocation_spec.rb +0 -59
data/patch_ruby.gemspec
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
3
|
=begin
|
4
|
-
#Patch API
|
4
|
+
#Patch API V2
|
5
5
|
|
6
6
|
#The core API used to integrate with Patch's service
|
7
7
|
|
8
|
-
The version of the OpenAPI document:
|
8
|
+
The version of the OpenAPI document: 2
|
9
9
|
Contact: engineering@usepatch.com
|
10
10
|
Generated by: https://openapi-generator.tech
|
11
11
|
OpenAPI Generator version: 5.3.1
|
@@ -0,0 +1,78 @@
|
|
1
|
+
=begin
|
2
|
+
#Patch API V2
|
3
|
+
|
4
|
+
#The core API used to integrate with Patch's service
|
5
|
+
|
6
|
+
The version of the OpenAPI document: 2
|
7
|
+
Contact: engineering@usepatch.com
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
OpenAPI Generator version: 5.3.1
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'spec_helper'
|
14
|
+
require 'json'
|
15
|
+
|
16
|
+
# Unit tests for Patch::OrderLineItemsApi
|
17
|
+
# Automatically generated by openapi-generator (https://openapi-generator.tech)
|
18
|
+
# Please update as you see appropriate
|
19
|
+
describe 'OrderLineItemsApi' do
|
20
|
+
before do
|
21
|
+
# run before each test
|
22
|
+
@api_instance = Patch::OrderLineItemsApi.new
|
23
|
+
end
|
24
|
+
|
25
|
+
after do
|
26
|
+
# run after each test
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'test an instance of OrderLineItemsApi' do
|
30
|
+
it 'should create an instance of OrderLineItemsApi' do
|
31
|
+
expect(@api_instance).to be_instance_of(Patch::OrderLineItemsApi)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# unit tests for create_order_line_item
|
36
|
+
# Creates an order line item
|
37
|
+
# Creates a line item on an order that is in the `draft` state.
|
38
|
+
# @param order_id
|
39
|
+
# @param create_order_line_item_request
|
40
|
+
# @param [Hash] opts the optional parameters
|
41
|
+
# @option opts [Integer] :patch_version
|
42
|
+
# @return [OrderLineItemResponse]
|
43
|
+
describe 'create_order_line_item test' do
|
44
|
+
it 'should work' do
|
45
|
+
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# unit tests for delete_order_line_item
|
50
|
+
# Deletes an order line item
|
51
|
+
# Deletes a line item on an order that is in the `draft` state.
|
52
|
+
# @param order_id
|
53
|
+
# @param serial_number
|
54
|
+
# @param [Hash] opts the optional parameters
|
55
|
+
# @option opts [Integer] :patch_version
|
56
|
+
# @return [DeleteOrderLineItemResponse]
|
57
|
+
describe 'delete_order_line_item test' do
|
58
|
+
it 'should work' do
|
59
|
+
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# unit tests for update_order_line_item
|
64
|
+
# Updates an order line item
|
65
|
+
# Updates a line item on an order that is in the `draft` state.
|
66
|
+
# @param order_id
|
67
|
+
# @param serial_number
|
68
|
+
# @param update_order_line_item_request
|
69
|
+
# @param [Hash] opts the optional parameters
|
70
|
+
# @option opts [Integer] :patch_version
|
71
|
+
# @return [OrderLineItemResponse]
|
72
|
+
describe 'update_order_line_item test' do
|
73
|
+
it 'should work' do
|
74
|
+
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
data/spec/api_client_spec.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
=begin
|
2
|
-
#Patch API
|
2
|
+
#Patch API V2
|
3
3
|
|
4
4
|
#The core API used to integrate with Patch's service
|
5
5
|
|
6
|
-
The version of the OpenAPI document:
|
6
|
+
The version of the OpenAPI document: 2
|
7
7
|
Contact: engineering@usepatch.com
|
8
8
|
Generated by: https://openapi-generator.tech
|
9
9
|
OpenAPI Generator version: 5.3.1
|
data/spec/configuration_spec.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
=begin
|
2
|
-
#Patch API
|
2
|
+
#Patch API V2
|
3
3
|
|
4
4
|
#The core API used to integrate with Patch's service
|
5
5
|
|
6
|
-
The version of the OpenAPI document:
|
6
|
+
The version of the OpenAPI document: 2
|
7
7
|
Contact: engineering@usepatch.com
|
8
8
|
Generated by: https://openapi-generator.tech
|
9
9
|
OpenAPI Generator version: 5.3.1
|
@@ -1,8 +1,10 @@
|
|
1
1
|
FactoryBot.define do
|
2
2
|
factory :create_order_request, class: Patch::CreateOrderRequest do
|
3
3
|
sequence(:project_id) { |n| n }
|
4
|
-
|
5
|
-
|
4
|
+
amount { 100 }
|
5
|
+
unit { "g" }
|
6
|
+
total_price { 100 }
|
7
|
+
currency { "USD" }
|
6
8
|
metadata { {} }
|
7
9
|
end
|
8
10
|
end
|
data/spec/factories/orders.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
FactoryBot.define do
|
2
2
|
factory :order, class: Patch::Order do
|
3
3
|
sequence(:id) { |n| n }
|
4
|
-
|
4
|
+
amount { 1_000 }
|
5
|
+
unit { "g" }
|
5
6
|
production { false }
|
6
7
|
state { "draft" }
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
price { 500 }
|
9
|
+
patch_fee { 5 }
|
10
|
+
currency { "USD" }
|
10
11
|
metadata { {} }
|
11
12
|
end
|
12
13
|
end
|
data/spec/factories/projects.rb
CHANGED
@@ -7,12 +7,9 @@ FactoryBot.define do
|
|
7
7
|
production { false }
|
8
8
|
name { "New Project" }
|
9
9
|
description { "New Descirption" }
|
10
|
-
type { "biomass" }
|
11
10
|
country { "DK" }
|
12
|
-
|
11
|
+
project_partner { "Danish Developer" }
|
13
12
|
photos { [] }
|
14
|
-
average_price_per_tonne_cents_usd { 120 }
|
15
|
-
remaining_mass_g { 1_000 }
|
16
13
|
standard { 'european_biochar_certificate' }
|
17
14
|
state { 'CO' }
|
18
15
|
latitude { 45.0 }
|
@@ -90,7 +90,6 @@ RSpec.describe 'Estimates Integration' do
|
|
90
90
|
expect(create_estimate_response.data.mass_g).to be >= 10_000
|
91
91
|
end
|
92
92
|
|
93
|
-
|
94
93
|
it 'supports creating bitcoin estimates with partial information' do
|
95
94
|
bitcoin_estimate = Patch::Estimate.create_bitcoin_estimate()
|
96
95
|
|
@@ -172,6 +171,20 @@ RSpec.describe 'Estimates Integration' do
|
|
172
171
|
expect(create_estimate_response.data.id).not_to be_nil
|
173
172
|
end
|
174
173
|
|
174
|
+
it 'supports creating ecommerce estimates' do
|
175
|
+
distance_m = 100_000_000
|
176
|
+
package_mass_g = 10_000
|
177
|
+
create_estimate_response = Patch::Estimate.create_ecommerce_estimate(
|
178
|
+
distance_m: distance_m,
|
179
|
+
package_mass_g: package_mass_g,
|
180
|
+
transportation_method: 'rail',
|
181
|
+
create_order: false
|
182
|
+
)
|
183
|
+
|
184
|
+
expect(create_estimate_response.data.type).to eq 'ecommerce'
|
185
|
+
expect(create_estimate_response.data.mass_g).to be >= 10_000
|
186
|
+
end
|
187
|
+
|
175
188
|
context "when creating an air shipping estimate" do
|
176
189
|
it "supports creating an estimate using airports" do
|
177
190
|
air_shipping_estimate = Patch::Estimate.create_air_shipping_estimate(
|
@@ -182,7 +195,7 @@ RSpec.describe 'Estimates Integration' do
|
|
182
195
|
origin_airport: "SFO"
|
183
196
|
)
|
184
197
|
expect(air_shipping_estimate.data.type).to eq('shipping_air')
|
185
|
-
expect(air_shipping_estimate.data.mass_g).to be
|
198
|
+
expect(air_shipping_estimate.data.mass_g).to be > 0
|
186
199
|
end
|
187
200
|
|
188
201
|
it "supports creating an estimate with an order" do
|
@@ -194,8 +207,8 @@ RSpec.describe 'Estimates Integration' do
|
|
194
207
|
origin_airport: "SFO"
|
195
208
|
)
|
196
209
|
expect(air_shipping_estimate.data.type).to eq('shipping_air')
|
197
|
-
expect(air_shipping_estimate.data.mass_g).to be
|
198
|
-
expect(air_shipping_estimate.data.order.amount).to be
|
210
|
+
expect(air_shipping_estimate.data.mass_g).to be > 0
|
211
|
+
expect(air_shipping_estimate.data.order.amount).to be > 0
|
199
212
|
end
|
200
213
|
end
|
201
214
|
|
@@ -210,7 +223,7 @@ RSpec.describe 'Estimates Integration' do
|
|
210
223
|
origin_locode: "USSD2"
|
211
224
|
)
|
212
225
|
expect(rail_shipping_estimate.data.type).to eq('shipping_rail')
|
213
|
-
expect(rail_shipping_estimate.data.mass_g).to be
|
226
|
+
expect(rail_shipping_estimate.data.mass_g).to be > 0
|
214
227
|
end
|
215
228
|
|
216
229
|
it "supports creating an estimate using postal codes" do
|
@@ -225,7 +238,7 @@ RSpec.describe 'Estimates Integration' do
|
|
225
238
|
origin_postal_code: "90210"
|
226
239
|
)
|
227
240
|
expect(rail_shipping_estimate.data.type).to eq('shipping_rail')
|
228
|
-
expect(rail_shipping_estimate.data.mass_g).to be
|
241
|
+
expect(rail_shipping_estimate.data.mass_g).to be > 0
|
229
242
|
end
|
230
243
|
|
231
244
|
it "supports creating an estimate with an order" do
|
@@ -236,8 +249,8 @@ RSpec.describe 'Estimates Integration' do
|
|
236
249
|
origin_locode: "USSD2"
|
237
250
|
)
|
238
251
|
expect(rail_shipping_estimate.data.type).to eq('shipping_rail')
|
239
|
-
expect(rail_shipping_estimate.data.mass_g).to be
|
240
|
-
expect(rail_shipping_estimate.data.order.amount).to be
|
252
|
+
expect(rail_shipping_estimate.data.mass_g).to be > 0
|
253
|
+
expect(rail_shipping_estimate.data.order.amount).to be > 0
|
241
254
|
end
|
242
255
|
end
|
243
256
|
|
@@ -252,7 +265,7 @@ RSpec.describe 'Estimates Integration' do
|
|
252
265
|
origin_locode: "USSD2"
|
253
266
|
)
|
254
267
|
expect(road_shipping_estimate.data.type).to eq('shipping_road')
|
255
|
-
expect(road_shipping_estimate.data.mass_g).to be
|
268
|
+
expect(road_shipping_estimate.data.mass_g).to be > 0
|
256
269
|
end
|
257
270
|
|
258
271
|
it "supports creating an estimate using postal codes" do
|
@@ -266,7 +279,7 @@ RSpec.describe 'Estimates Integration' do
|
|
266
279
|
origin_postal_code: "90210"
|
267
280
|
)
|
268
281
|
expect(road_shipping_estimate.data.type).to eq('shipping_road')
|
269
|
-
expect(road_shipping_estimate.data.mass_g).to be
|
282
|
+
expect(road_shipping_estimate.data.mass_g).to be > 0
|
270
283
|
end
|
271
284
|
|
272
285
|
it "supports creating an estimate with an order" do
|
@@ -277,8 +290,8 @@ RSpec.describe 'Estimates Integration' do
|
|
277
290
|
origin_locode: "USSD2"
|
278
291
|
)
|
279
292
|
expect(road_shipping_estimate.data.type).to eq('shipping_road')
|
280
|
-
expect(road_shipping_estimate.data.mass_g).to be
|
281
|
-
expect(road_shipping_estimate.data.order.amount).to be
|
293
|
+
expect(road_shipping_estimate.data.mass_g).to be > 0
|
294
|
+
expect(road_shipping_estimate.data.order.amount).to be > 0
|
282
295
|
end
|
283
296
|
end
|
284
297
|
|
@@ -293,7 +306,7 @@ RSpec.describe 'Estimates Integration' do
|
|
293
306
|
origin_locode: "FRMRS"
|
294
307
|
)
|
295
308
|
expect(sea_shipping_estimate.data.type).to eq('shipping_sea')
|
296
|
-
expect(sea_shipping_estimate.data.mass_g).to be
|
309
|
+
expect(sea_shipping_estimate.data.mass_g).to be > 0
|
297
310
|
end
|
298
311
|
|
299
312
|
it "supports creating an estimate using postal codes" do
|
@@ -307,7 +320,7 @@ RSpec.describe 'Estimates Integration' do
|
|
307
320
|
origin_postal_code: "90210"
|
308
321
|
)
|
309
322
|
expect(sea_shipping_estimate.data.type).to eq('shipping_sea')
|
310
|
-
expect(sea_shipping_estimate.data.mass_g).to be
|
323
|
+
expect(sea_shipping_estimate.data.mass_g).to be > 0
|
311
324
|
end
|
312
325
|
|
313
326
|
it "supports creating an estimate with an order" do
|
@@ -318,8 +331,8 @@ RSpec.describe 'Estimates Integration' do
|
|
318
331
|
origin_locode: "USSD2"
|
319
332
|
)
|
320
333
|
expect(sea_shipping_estimate.data.type).to eq('shipping_sea')
|
321
|
-
expect(sea_shipping_estimate.data.mass_g).to be
|
322
|
-
expect(sea_shipping_estimate.data.order.amount).to be
|
334
|
+
expect(sea_shipping_estimate.data.mass_g).to be > 0
|
335
|
+
expect(sea_shipping_estimate.data.order.amount).to be > 0
|
323
336
|
end
|
324
337
|
end
|
325
338
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
RSpec.describe 'Orders Integration' do
|
2
2
|
it 'supports create, place, cancel, retrieve and list' do
|
3
|
-
create_order_response = Patch::Order.create_order(
|
3
|
+
create_order_response = Patch::Order.create_order(amount: 100, unit: "g")
|
4
4
|
order_id = create_order_response.data.id
|
5
5
|
|
6
6
|
retrieve_order_response = Patch::Order.retrieve_order(order_id)
|
@@ -25,20 +25,21 @@ RSpec.describe 'Orders Integration' do
|
|
25
25
|
)
|
26
26
|
|
27
27
|
project_id = retrieve_project_response.data.id
|
28
|
-
average_price_per_tonne_cents_usd = retrieve_project_response.data.average_price_per_tonne_cents_usd
|
29
28
|
|
30
|
-
|
29
|
+
order_amount = 100_000
|
31
30
|
tonne_per_gram = 1_000_000
|
32
31
|
|
33
|
-
create_order_response = Patch::Order
|
32
|
+
create_order_response = Patch::Order
|
33
|
+
.create_order(amount: order_amount, unit: "g", project_id: project_id)
|
34
34
|
|
35
35
|
order = create_order_response.data
|
36
36
|
expect(create_order_response.success).to eq true
|
37
37
|
expect(order.id).not_to be_nil
|
38
38
|
expect(order.created_at).to be_a_kind_of(Time)
|
39
|
-
expect(order.
|
40
|
-
expect(order.
|
41
|
-
expect(order.
|
39
|
+
expect(order.amount).to eq(order_amount)
|
40
|
+
expect(order.unit).to eq("g")
|
41
|
+
expect(order.price).to be_kind_of(Integer)
|
42
|
+
expect(order.patch_fee).to be_kind_of(Integer)
|
42
43
|
expect(order.registry_url).not_to be_empty
|
43
44
|
end
|
44
45
|
|
@@ -48,10 +49,11 @@ RSpec.describe 'Orders Integration' do
|
|
48
49
|
)
|
49
50
|
|
50
51
|
issued_to = { email: 'envimpact@companyb.com', name: 'Company B' }
|
51
|
-
|
52
|
+
total_price = 50_00
|
52
53
|
|
53
54
|
create_order_response = Patch::Order.create_order(
|
54
|
-
|
55
|
+
total_price: total_price,
|
56
|
+
currency: "USD",
|
55
57
|
issued_to: issued_to
|
56
58
|
)
|
57
59
|
|
@@ -60,42 +62,21 @@ RSpec.describe 'Orders Integration' do
|
|
60
62
|
order = create_order_response.data
|
61
63
|
|
62
64
|
expect(order.id).not_to be_nil
|
63
|
-
expect(order.
|
65
|
+
expect(order.price + order.patch_fee).to eq total_price
|
64
66
|
expect(order.issued_to.email).to eq(issued_to[:email])
|
65
67
|
expect(order.issued_to.name).to eq(issued_to[:name])
|
66
68
|
end
|
67
69
|
|
68
|
-
it 'supports create with a total price' do
|
69
|
-
retrieve_project_response = Patch::Project.retrieve_project(
|
70
|
-
Constants::BIOMASS_TEST_PROJECT_ID
|
71
|
-
)
|
72
|
-
|
73
|
-
project_id = retrieve_project_response.data.id
|
74
|
-
total_price_cents_usd = 50_00
|
75
|
-
|
76
|
-
create_order_response = Patch::Order.create_order(
|
77
|
-
total_price_cents_usd: total_price_cents_usd,
|
78
|
-
project_id: project_id
|
79
|
-
)
|
80
|
-
|
81
|
-
expect(create_order_response.success).to eq true
|
82
|
-
|
83
|
-
order = create_order_response.data
|
84
|
-
|
85
|
-
expect(order.id).not_to be_nil
|
86
|
-
expect(order.price_cents_usd + order.patch_fee_cents_usd).to eq total_price_cents_usd
|
87
|
-
expect(order.registry_url).not_to be_empty
|
88
|
-
end
|
89
|
-
|
90
70
|
it 'supports creation with and querying by metadata' do
|
91
71
|
metadata = { user: 'john doe' }
|
92
72
|
|
93
73
|
create_order_response =
|
94
|
-
Patch::Order.create_order(
|
74
|
+
Patch::Order.create_order(amount: 100, unit: "g", metadata: metadata)
|
95
75
|
|
96
76
|
expect(create_order_response.success).to eq true
|
97
77
|
expect(create_order_response.data.id).not_to be_nil
|
98
|
-
expect(create_order_response.data.
|
78
|
+
expect(create_order_response.data.amount).to eq(100)
|
79
|
+
expect(create_order_response.data.unit).to eq("g")
|
99
80
|
expect(create_order_response.data.metadata).to eq(metadata)
|
100
81
|
|
101
82
|
retrieve_orders_response = Patch::Order.retrieve_orders(
|
@@ -109,11 +90,12 @@ RSpec.describe 'Orders Integration' do
|
|
109
90
|
|
110
91
|
it 'supports creation in draft state' do
|
111
92
|
create_order_response =
|
112
|
-
Patch::Order.create_order(
|
93
|
+
Patch::Order.create_order(amount: 100, unit: "g", state: "draft")
|
113
94
|
|
114
95
|
expect(create_order_response.success).to eq true
|
115
96
|
expect(create_order_response.data.id).not_to be_nil
|
116
|
-
expect(create_order_response.data.
|
97
|
+
expect(create_order_response.data.amount).to eq(100)
|
98
|
+
expect(create_order_response.data.unit).to eq("g")
|
117
99
|
expect(create_order_response.data.state).to eq("draft")
|
118
100
|
end
|
119
101
|
|
@@ -144,11 +126,12 @@ RSpec.describe 'Orders Integration' do
|
|
144
126
|
|
145
127
|
it 'supports create with a vintage year' do
|
146
128
|
create_order_response =
|
147
|
-
Patch::Order.create_order(
|
129
|
+
Patch::Order.create_order(amount: 100, unit: "g", vintage_year: 2022)
|
148
130
|
|
149
131
|
expect(create_order_response.success).to eq true
|
150
132
|
expect(create_order_response.data.id).not_to be_nil
|
151
|
-
expect(create_order_response.data.
|
133
|
+
expect(create_order_response.data.amount).to eq(100)
|
134
|
+
expect(create_order_response.data.unit).to eq("g")
|
152
135
|
end
|
153
136
|
|
154
137
|
it 'supports create with an amount and unit' do
|
@@ -159,16 +142,16 @@ RSpec.describe 'Orders Integration' do
|
|
159
142
|
expect(create_order_response.data.id).not_to be_nil
|
160
143
|
expect(create_order_response.data.amount).to eq(100)
|
161
144
|
expect(create_order_response.data.unit).to eq("g")
|
162
|
-
expect(create_order_response.data.
|
163
|
-
Patch::
|
145
|
+
expect(create_order_response.data.line_items[0]).to be_an_instance_of(
|
146
|
+
Patch::OrderLineItem
|
164
147
|
)
|
165
|
-
expect(create_order_response.data.
|
166
|
-
Patch::
|
148
|
+
expect(create_order_response.data.line_items[0].project).to be_an_instance_of(
|
149
|
+
Patch::OrderLineItemProject
|
167
150
|
)
|
168
|
-
expect(create_order_response.data.
|
151
|
+
expect(create_order_response.data.line_items[0].unit).to eq("g")
|
169
152
|
end
|
170
153
|
|
171
|
-
it 'supports create with a total price and currency' do
|
154
|
+
it 'supports create with a total price and foreign currency' do
|
172
155
|
create_order_response =
|
173
156
|
Patch::Order.create_order(total_price: 100, currency: "EUR")
|
174
157
|
|
@@ -178,4 +161,62 @@ RSpec.describe 'Orders Integration' do
|
|
178
161
|
).to be_within(1).of(100)
|
179
162
|
expect(create_order_response.data.currency).to eq "EUR"
|
180
163
|
end
|
164
|
+
|
165
|
+
it 'supports creating an empty draft order and adding/editing line items' do
|
166
|
+
# Create empty order
|
167
|
+
create_order_response =
|
168
|
+
Patch::Order.create_order(state: "draft")
|
169
|
+
|
170
|
+
expect(create_order_response.success).to eq true
|
171
|
+
expect(create_order_response.data.id).not_to be_nil
|
172
|
+
expect(create_order_response.data.price).to eq(0)
|
173
|
+
expect(create_order_response.data.amount).to eq(0)
|
174
|
+
expect(create_order_response.data.line_items).to eq([])
|
175
|
+
|
176
|
+
# Add project to order
|
177
|
+
order_id = create_order_response.data.id
|
178
|
+
retrieve_project_response = Patch::Project.retrieve_project(
|
179
|
+
Constants::BIOMASS_TEST_PROJECT_ID
|
180
|
+
)
|
181
|
+
project_id = retrieve_project_response.data.id
|
182
|
+
|
183
|
+
create_line_item_response = Patch::OrderLineItem
|
184
|
+
.create_order_line_item(order_id, { project_id: project_id })
|
185
|
+
|
186
|
+
expect(create_line_item_response.success).to eq(true)
|
187
|
+
expect(create_line_item_response.data.id).not_to be_nil
|
188
|
+
expect(create_line_item_response.data.amount).to eq(0)
|
189
|
+
|
190
|
+
# Update amount on line item
|
191
|
+
line_item_id = create_line_item_response.data.id
|
192
|
+
update_order_line_item_response = Patch::OrderLineItem
|
193
|
+
.update_order_line_item(order_id, line_item_id, { amount: 100000, unit: "g" })
|
194
|
+
|
195
|
+
expect(update_order_line_item_response.success).to eq(true)
|
196
|
+
expect(update_order_line_item_response.data.id).not_to be_nil
|
197
|
+
expect(update_order_line_item_response.data.amount).to eq(100000)
|
198
|
+
expect(update_order_line_item_response.data.price).to be >= 0
|
199
|
+
|
200
|
+
# Fetch order and check line item matches
|
201
|
+
retrieve_order_response = Patch::Order.retrieve_order(order_id)
|
202
|
+
expect(retrieve_order_response.data.id).to eq order_id
|
203
|
+
expect(retrieve_order_response.data.line_items.length).to eq(1)
|
204
|
+
expect(retrieve_order_response.data.line_items[0].id).to eq(line_item_id)
|
205
|
+
expect(retrieve_order_response.data.line_items[0].amount).to eq(100000)
|
206
|
+
|
207
|
+
# Delete line item
|
208
|
+
delete_line_item_response = Patch::OrderLineItem.delete_order_line_item(order_id, line_item_id)
|
209
|
+
expect(delete_line_item_response.success).to eq(true)
|
210
|
+
expect(delete_line_item_response.data).to eq(line_item_id)
|
211
|
+
|
212
|
+
# Fetch order and see it has no line items
|
213
|
+
retrieve_order_response = Patch::Order.retrieve_order(order_id)
|
214
|
+
expect(retrieve_order_response.data.id).to eq order_id
|
215
|
+
expect(retrieve_order_response.data.line_items.length).to eq(0)
|
216
|
+
|
217
|
+
# Delete order
|
218
|
+
delete_order_response = Patch::Order.delete_order(order_id)
|
219
|
+
expect(delete_order_response.success).to eq(true)
|
220
|
+
expect(delete_order_response.data).to eq(order_id)
|
221
|
+
end
|
181
222
|
end
|
@@ -34,7 +34,8 @@ RSpec.describe 'Projects Integration' do
|
|
34
34
|
minimum_available_mass = 100
|
35
35
|
projects = Patch::Project.retrieve_projects(minimum_available_mass: minimum_available_mass)
|
36
36
|
projects.data.map do |project|
|
37
|
-
|
37
|
+
project_mass = project.inventory.sum(&:amount_available)
|
38
|
+
expect(project_mass >= minimum_available_mass).to be true
|
38
39
|
end
|
39
40
|
end
|
40
41
|
|
@@ -45,9 +46,6 @@ RSpec.describe 'Projects Integration' do
|
|
45
46
|
expect(project.to_hash.keys).to include(*keys)
|
46
47
|
|
47
48
|
expect(project.photos).to be_an_instance_of(Array)
|
48
|
-
expect(project.average_price_per_tonne_cents_usd)
|
49
|
-
.to be_an_instance_of(Integer)
|
50
|
-
expect(project.remaining_mass_g).to be_an_instance_of(Integer)
|
51
49
|
expect(project.longitude).to be_an_instance_of(Float)
|
52
50
|
expect(project.latitude).to be_an_instance_of(Float)
|
53
51
|
|
@@ -29,9 +29,16 @@ describe 'CreateOrderRequest' do
|
|
29
29
|
|
30
30
|
it_behaves_like "a generated class" do
|
31
31
|
let(:instance) { @instance }
|
32
|
-
let(:instance_hash) { {
|
32
|
+
let(:instance_hash) { {
|
33
|
+
project_id: @instance.project_id,
|
34
|
+
amount: @instance.amount,
|
35
|
+
unit: @instance.unit,
|
36
|
+
total_price: @instance.total_price,
|
37
|
+
currency: @instance.currency,
|
38
|
+
metadata: @instance.metadata
|
39
|
+
} }
|
33
40
|
let(:nullable_properties) do
|
34
|
-
Set.new(%i[
|
41
|
+
Set.new(%i[project_id metadata state vintage_year total_price currency amount unit])
|
35
42
|
end
|
36
43
|
end
|
37
44
|
|
@@ -40,7 +47,7 @@ describe 'CreateOrderRequest' do
|
|
40
47
|
expect(@instance).to be_instance_of(Patch::CreateOrderRequest)
|
41
48
|
end
|
42
49
|
end
|
43
|
-
describe 'test attribute "
|
50
|
+
describe 'test attribute "amount"' do
|
44
51
|
it 'should work' do
|
45
52
|
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
|
46
53
|
end
|
data/spec/models/order_spec.rb
CHANGED
@@ -32,16 +32,17 @@ describe 'Order' do
|
|
32
32
|
let(:instance_hash) {
|
33
33
|
{
|
34
34
|
id: @instance.id,
|
35
|
-
|
35
|
+
amount: @instance.amount,
|
36
|
+
unit: @instance.unit,
|
36
37
|
production: @instance.production,
|
37
38
|
state: @instance.state,
|
38
|
-
|
39
|
-
|
40
|
-
|
39
|
+
price: @instance.price,
|
40
|
+
patch_fee: @instance.patch_fee,
|
41
|
+
currency: @instance.currency,
|
41
42
|
metadata: @instance.metadata
|
42
43
|
}
|
43
44
|
}
|
44
|
-
let(:nullable_properties) { Set.new([
|
45
|
+
let(:nullable_properties) { Set.new([]) }
|
45
46
|
end
|
46
47
|
|
47
48
|
describe 'test an instance of Order' do
|
@@ -55,7 +56,7 @@ describe 'Order' do
|
|
55
56
|
end
|
56
57
|
end
|
57
58
|
|
58
|
-
describe 'test attribute "
|
59
|
+
describe 'test attribute "amount"' do
|
59
60
|
it 'should work' do
|
60
61
|
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
|
61
62
|
end
|
@@ -77,23 +78,7 @@ describe 'Order' do
|
|
77
78
|
end
|
78
79
|
end
|
79
80
|
|
80
|
-
describe 'test attribute "
|
81
|
-
it 'should work' do
|
82
|
-
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
|
83
|
-
# validator = Petstore::EnumTest::EnumAttributeValidator.new('String', ["pending", "partially_allocated", "allocated"])
|
84
|
-
# validator.allowable_values.each do |value|
|
85
|
-
# expect { @instance.allocation_state = value }.not_to raise_error
|
86
|
-
# end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
describe 'test attribute "price_cents_usd"' do
|
91
|
-
it 'should work' do
|
92
|
-
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
describe 'test attribute "allocations"' do
|
81
|
+
describe 'test attribute "price"' do
|
97
82
|
it 'should work' do
|
98
83
|
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
|
99
84
|
end
|
data/spec/models/project_spec.rb
CHANGED
@@ -35,12 +35,9 @@ describe 'Project' do
|
|
35
35
|
name: @instance.name,
|
36
36
|
description: @instance.description,
|
37
37
|
production: @instance.production,
|
38
|
-
type: @instance.type,
|
39
38
|
country: @instance.country,
|
40
|
-
|
39
|
+
project_partner: @instance.project_partner,
|
41
40
|
photos: @instance.photos,
|
42
|
-
average_price_per_tonne_cents_usd: @instance.average_price_per_tonne_cents_usd,
|
43
|
-
remaining_mass_g: @instance.remaining_mass_g,
|
44
41
|
state: @instance.state,
|
45
42
|
longitude: @instance.longitude,
|
46
43
|
latitude: @instance.latitude,
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
=begin
|
2
|
-
#Patch API
|
2
|
+
#Patch API V2
|
3
3
|
|
4
4
|
#The core API used to integrate with Patch's service
|
5
5
|
|
6
|
-
The version of the OpenAPI document:
|
6
|
+
The version of the OpenAPI document: 2
|
7
7
|
Contact: engineering@usepatch.com
|
8
8
|
Generated by: https://openapi-generator.tech
|
9
9
|
OpenAPI Generator version: 5.3.1
|