patch_ruby 1.21.0 → 1.24.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 +21 -0
- data/Gemfile.lock +2 -1
- data/README.md +39 -0
- data/lib/patch_ruby/api/estimates_api.rb +280 -0
- data/lib/patch_ruby/api/orders_api.rb +39 -34
- data/lib/patch_ruby/api/projects_api.rb +6 -0
- data/lib/patch_ruby/api_client.rb +1 -1
- data/lib/patch_ruby/models/allocation.rb +1 -1
- data/lib/patch_ruby/models/create_air_shipping_estimate_request.rb +374 -0
- data/lib/patch_ruby/models/create_order_request.rb +17 -7
- data/lib/patch_ruby/models/create_rail_shipping_estimate_request.rb +404 -0
- data/lib/patch_ruby/models/create_road_shipping_estimate_request.rb +507 -0
- data/lib/patch_ruby/models/create_sea_shipping_estimate_request.rb +461 -0
- data/lib/patch_ruby/models/estimate.rb +1 -1
- data/lib/patch_ruby/models/issued_to.rb +242 -0
- data/lib/patch_ruby/models/order.rb +16 -7
- data/lib/patch_ruby/models/place_order_request.rb +229 -0
- data/lib/patch_ruby/models/project.rb +2 -36
- data/lib/patch_ruby/models/v1_orders_issued_to.rb +239 -0
- data/lib/patch_ruby/version.rb +1 -1
- data/lib/patch_ruby.rb +7 -0
- data/spec/integration/estimates_spec.rb +151 -0
- data/spec/integration/orders_spec.rb +34 -0
- data/spec/integration/projects_spec.rb +43 -35
- data/spec/models/create_order_request_spec.rb +1 -1
- metadata +32 -25
@@ -0,0 +1,239 @@
|
|
1
|
+
=begin
|
2
|
+
#Patch API V1
|
3
|
+
|
4
|
+
#The core API used to integrate with Patch's service
|
5
|
+
|
6
|
+
The version of the OpenAPI document: v1
|
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 'date'
|
14
|
+
require 'time'
|
15
|
+
|
16
|
+
module Patch
|
17
|
+
class V1OrdersIssuedTo
|
18
|
+
attr_accessor :email
|
19
|
+
|
20
|
+
attr_accessor :name
|
21
|
+
|
22
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
23
|
+
def self.attribute_map
|
24
|
+
{
|
25
|
+
:'email' => :'email',
|
26
|
+
:'name' => :'name'
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
# Returns all the JSON keys this model knows about
|
31
|
+
def self.acceptable_attributes
|
32
|
+
attribute_map.values
|
33
|
+
end
|
34
|
+
|
35
|
+
# Attribute type mapping.
|
36
|
+
def self.openapi_types
|
37
|
+
{
|
38
|
+
:'email' => :'String',
|
39
|
+
:'name' => :'String'
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
# List of attributes with nullable: true
|
44
|
+
def self.openapi_nullable
|
45
|
+
Set.new([
|
46
|
+
:'email',
|
47
|
+
:'name'
|
48
|
+
])
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
# Allows models with corresponding API classes to delegate API operations to those API classes
|
53
|
+
# Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
|
54
|
+
# Eg. Order.create_order delegates to OrdersApi.new.create_order
|
55
|
+
def self.method_missing(message, *args, &block)
|
56
|
+
if Object.const_defined?('Patch::V1OrdersIssuedTosApi::OPERATIONS') && Patch::V1OrdersIssuedTosApi::OPERATIONS.include?(message)
|
57
|
+
Patch::V1OrdersIssuedTosApi.new.send(message, *args)
|
58
|
+
else
|
59
|
+
super
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Initializes the object
|
64
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
65
|
+
def initialize(attributes = {})
|
66
|
+
if (!attributes.is_a?(Hash))
|
67
|
+
fail ArgumentError, "The input argument (attributes) must be a hash in `Patch::V1OrdersIssuedTo` initialize method"
|
68
|
+
end
|
69
|
+
|
70
|
+
# check to see if the attribute exists and convert string to symbol for hash key
|
71
|
+
attributes = attributes.each_with_object({}) { |(k, v), h|
|
72
|
+
if (!self.class.attribute_map.key?(k.to_sym))
|
73
|
+
fail ArgumentError, "`#{k}` is not a valid attribute in `Patch::V1OrdersIssuedTo`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
|
74
|
+
end
|
75
|
+
h[k.to_sym] = v
|
76
|
+
}
|
77
|
+
|
78
|
+
if attributes.key?(:'email')
|
79
|
+
self.email = attributes[:'email']
|
80
|
+
end
|
81
|
+
|
82
|
+
if attributes.key?(:'name')
|
83
|
+
self.name = attributes[:'name']
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
88
|
+
# @return Array for valid properties with the reasons
|
89
|
+
def list_invalid_properties
|
90
|
+
invalid_properties = Array.new
|
91
|
+
invalid_properties
|
92
|
+
end
|
93
|
+
|
94
|
+
# Check to see if the all the properties in the model are valid
|
95
|
+
# @return true if the model is valid
|
96
|
+
def valid?
|
97
|
+
true
|
98
|
+
end
|
99
|
+
|
100
|
+
# Checks equality by comparing each attribute.
|
101
|
+
# @param [Object] Object to be compared
|
102
|
+
def ==(o)
|
103
|
+
return true if self.equal?(o)
|
104
|
+
self.class == o.class &&
|
105
|
+
email == o.email &&
|
106
|
+
name == o.name
|
107
|
+
end
|
108
|
+
|
109
|
+
# @see the `==` method
|
110
|
+
# @param [Object] Object to be compared
|
111
|
+
def eql?(o)
|
112
|
+
self == o
|
113
|
+
end
|
114
|
+
|
115
|
+
# Calculates hash code according to all attributes.
|
116
|
+
# @return [Integer] Hash code
|
117
|
+
def hash
|
118
|
+
[email, name].hash
|
119
|
+
end
|
120
|
+
|
121
|
+
# Builds the object from hash
|
122
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
123
|
+
# @return [Object] Returns the model itself
|
124
|
+
def self.build_from_hash(attributes)
|
125
|
+
new.build_from_hash(attributes)
|
126
|
+
end
|
127
|
+
|
128
|
+
# Builds the object from hash
|
129
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
130
|
+
# @return [Object] Returns the model itself
|
131
|
+
def build_from_hash(attributes)
|
132
|
+
return nil unless attributes.is_a?(Hash)
|
133
|
+
self.class.openapi_types.each_pair do |key, type|
|
134
|
+
if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
|
135
|
+
self.send("#{key}=", nil)
|
136
|
+
elsif type =~ /\AArray<(.*)>/i
|
137
|
+
# check to ensure the input is an array given that the attribute
|
138
|
+
# is documented as an array but the input is not
|
139
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
140
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
|
141
|
+
end
|
142
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
143
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
self
|
148
|
+
end
|
149
|
+
|
150
|
+
# Deserializes the data based on type
|
151
|
+
# @param string type Data type
|
152
|
+
# @param string value Value to be deserialized
|
153
|
+
# @return [Object] Deserialized data
|
154
|
+
def _deserialize(type, value)
|
155
|
+
case type.to_sym
|
156
|
+
when :Time
|
157
|
+
Time.parse(value)
|
158
|
+
when :Date
|
159
|
+
Date.parse(value)
|
160
|
+
when :String
|
161
|
+
value.to_s
|
162
|
+
when :Integer
|
163
|
+
value.to_i
|
164
|
+
when :Float
|
165
|
+
value.to_f
|
166
|
+
when :Boolean
|
167
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
168
|
+
true
|
169
|
+
else
|
170
|
+
false
|
171
|
+
end
|
172
|
+
when :Object
|
173
|
+
# generic object (usually a Hash), return directly
|
174
|
+
value
|
175
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
176
|
+
inner_type = Regexp.last_match[:inner_type]
|
177
|
+
value.map { |v| _deserialize(inner_type, v) }
|
178
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
179
|
+
k_type = Regexp.last_match[:k_type]
|
180
|
+
v_type = Regexp.last_match[:v_type]
|
181
|
+
{}.tap do |hash|
|
182
|
+
value.each do |k, v|
|
183
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
184
|
+
end
|
185
|
+
end
|
186
|
+
else # model
|
187
|
+
# models (e.g. Pet) or oneOf
|
188
|
+
klass = Patch.const_get(type)
|
189
|
+
klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
# Returns the string representation of the object
|
194
|
+
# @return [String] String presentation of the object
|
195
|
+
def to_s
|
196
|
+
to_hash.to_s
|
197
|
+
end
|
198
|
+
|
199
|
+
# to_body is an alias to to_hash (backward compatibility)
|
200
|
+
# @return [Hash] Returns the object in the form of hash
|
201
|
+
def to_body
|
202
|
+
to_hash
|
203
|
+
end
|
204
|
+
|
205
|
+
# Returns the object in the form of hash
|
206
|
+
# @return [Hash] Returns the object in the form of hash
|
207
|
+
def to_hash
|
208
|
+
hash = {}
|
209
|
+
self.class.attribute_map.each_pair do |attr, param|
|
210
|
+
value = self.send(attr)
|
211
|
+
if value.nil?
|
212
|
+
is_nullable = self.class.openapi_nullable.include?(attr)
|
213
|
+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
|
214
|
+
end
|
215
|
+
|
216
|
+
hash[param] = _to_hash(value)
|
217
|
+
end
|
218
|
+
hash
|
219
|
+
end
|
220
|
+
|
221
|
+
# Outputs non-array value in the form of hash
|
222
|
+
# For object, use to_hash. Otherwise, just return the value
|
223
|
+
# @param [Object] value Any valid value
|
224
|
+
# @return [Hash] Returns the value in the form of hash
|
225
|
+
def _to_hash(value)
|
226
|
+
if value.is_a?(Array)
|
227
|
+
value.compact.map { |v| _to_hash(v) }
|
228
|
+
elsif value.is_a?(Hash)
|
229
|
+
{}.tap do |hash|
|
230
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
231
|
+
end
|
232
|
+
elsif value.respond_to? :to_hash
|
233
|
+
value.to_hash
|
234
|
+
else
|
235
|
+
value
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
data/lib/patch_ruby/version.rb
CHANGED
data/lib/patch_ruby.rb
CHANGED
@@ -18,12 +18,16 @@ require 'patch_ruby/configuration'
|
|
18
18
|
|
19
19
|
# Models
|
20
20
|
require 'patch_ruby/models/allocation'
|
21
|
+
require 'patch_ruby/models/create_air_shipping_estimate_request'
|
21
22
|
require 'patch_ruby/models/create_bitcoin_estimate_request'
|
22
23
|
require 'patch_ruby/models/create_ethereum_estimate_request'
|
23
24
|
require 'patch_ruby/models/create_flight_estimate_request'
|
24
25
|
require 'patch_ruby/models/create_hotel_estimate_request'
|
25
26
|
require 'patch_ruby/models/create_mass_estimate_request'
|
26
27
|
require 'patch_ruby/models/create_order_request'
|
28
|
+
require 'patch_ruby/models/create_rail_shipping_estimate_request'
|
29
|
+
require 'patch_ruby/models/create_road_shipping_estimate_request'
|
30
|
+
require 'patch_ruby/models/create_sea_shipping_estimate_request'
|
27
31
|
require 'patch_ruby/models/create_shipping_estimate_request'
|
28
32
|
require 'patch_ruby/models/create_success_response'
|
29
33
|
require 'patch_ruby/models/create_vehicle_estimate_request'
|
@@ -33,6 +37,7 @@ require 'patch_ruby/models/estimate_list_response'
|
|
33
37
|
require 'patch_ruby/models/estimate_response'
|
34
38
|
require 'patch_ruby/models/highlight'
|
35
39
|
require 'patch_ruby/models/inventory'
|
40
|
+
require 'patch_ruby/models/issued_to'
|
36
41
|
require 'patch_ruby/models/meta_index_object'
|
37
42
|
require 'patch_ruby/models/order'
|
38
43
|
require 'patch_ruby/models/order_inventory'
|
@@ -41,6 +46,7 @@ require 'patch_ruby/models/order_list_response'
|
|
41
46
|
require 'patch_ruby/models/order_response'
|
42
47
|
require 'patch_ruby/models/parent_technology_type'
|
43
48
|
require 'patch_ruby/models/photo'
|
49
|
+
require 'patch_ruby/models/place_order_request'
|
44
50
|
require 'patch_ruby/models/project'
|
45
51
|
require 'patch_ruby/models/project_list_response'
|
46
52
|
require 'patch_ruby/models/project_response'
|
@@ -48,6 +54,7 @@ require 'patch_ruby/models/sdg'
|
|
48
54
|
require 'patch_ruby/models/standard'
|
49
55
|
require 'patch_ruby/models/technology_type'
|
50
56
|
require 'patch_ruby/models/technology_type_list_response'
|
57
|
+
require 'patch_ruby/models/v1_orders_issued_to'
|
51
58
|
|
52
59
|
# APIs
|
53
60
|
require 'patch_ruby/api/estimates_api'
|
@@ -171,4 +171,155 @@ RSpec.describe 'Estimates Integration' do
|
|
171
171
|
expect(create_estimate_response.data.mass_g).to be >= 100_000
|
172
172
|
expect(create_estimate_response.data.id).not_to be_nil
|
173
173
|
end
|
174
|
+
|
175
|
+
context "when creating an air shipping estimate" do
|
176
|
+
it "supports creating an estimate using airports" do
|
177
|
+
air_shipping_estimate = Patch::Estimate.create_air_shipping_estimate(
|
178
|
+
aircraft_type: "cargo",
|
179
|
+
create_order: false,
|
180
|
+
destination_airport: "JFK",
|
181
|
+
freight_mass_g: 31_300,
|
182
|
+
origin_airport: "SFO"
|
183
|
+
)
|
184
|
+
expect(air_shipping_estimate.data.type).to eq('shipping_air')
|
185
|
+
expect(air_shipping_estimate.data.mass_g).to be >= 20_000
|
186
|
+
end
|
187
|
+
|
188
|
+
it "supports creating an estimate with an order" do
|
189
|
+
air_shipping_estimate = Patch::Estimate.create_air_shipping_estimate(
|
190
|
+
aircraft_type: "cargo",
|
191
|
+
create_order: true,
|
192
|
+
destination_airport: "JFK",
|
193
|
+
freight_mass_g: 19_140,
|
194
|
+
origin_airport: "SFO"
|
195
|
+
)
|
196
|
+
expect(air_shipping_estimate.data.type).to eq('shipping_air')
|
197
|
+
expect(air_shipping_estimate.data.mass_g).to be >= 20_000
|
198
|
+
expect(air_shipping_estimate.data.order.amount).to be >= 10_000
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
context "when creating a rail shipping estimate" do
|
203
|
+
it "supports creating an estimate using locodes" do
|
204
|
+
rail_shipping_estimate = Patch::Estimate.create_rail_shipping_estimate(
|
205
|
+
create_order: false,
|
206
|
+
destination_locode: "USSEA",
|
207
|
+
emissions_scope: "wtw",
|
208
|
+
freight_mass_g: 419_060,
|
209
|
+
fuel_type: "diesel",
|
210
|
+
origin_locode: "USSD2"
|
211
|
+
)
|
212
|
+
expect(rail_shipping_estimate.data.type).to eq('shipping_rail')
|
213
|
+
expect(rail_shipping_estimate.data.mass_g).to be >= 15_000
|
214
|
+
end
|
215
|
+
|
216
|
+
it "supports creating an estimate using postal codes" do
|
217
|
+
rail_shipping_estimate = Patch::Estimate.create_rail_shipping_estimate(
|
218
|
+
create_order: false,
|
219
|
+
destination_country_code: "US",
|
220
|
+
destination_postal_code: "97209",
|
221
|
+
emissions_scope: "wtw",
|
222
|
+
freight_mass_g: 226_000,
|
223
|
+
fuel_type: "diesel",
|
224
|
+
origin_country_code: "US",
|
225
|
+
origin_postal_code: "90210"
|
226
|
+
)
|
227
|
+
expect(rail_shipping_estimate.data.type).to eq('shipping_rail')
|
228
|
+
expect(rail_shipping_estimate.data.mass_g).to be >= 4_000
|
229
|
+
end
|
230
|
+
|
231
|
+
it "supports creating an estimate with an order" do
|
232
|
+
rail_shipping_estimate = Patch::Estimate.create_rail_shipping_estimate(
|
233
|
+
create_order: true,
|
234
|
+
destination_locode: "USSEA",
|
235
|
+
freight_mass_g: 359_000,
|
236
|
+
origin_locode: "USSD2"
|
237
|
+
)
|
238
|
+
expect(rail_shipping_estimate.data.type).to eq('shipping_rail')
|
239
|
+
expect(rail_shipping_estimate.data.mass_g).to be >= 15_000
|
240
|
+
expect(rail_shipping_estimate.data.order.amount).to be >= 10_000
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
context "when creating a road shipping estimate" do
|
245
|
+
it "supports creating an estimate using locodes" do
|
246
|
+
road_shipping_estimate = Patch::Estimate.create_road_shipping_estimate(
|
247
|
+
create_order: false,
|
248
|
+
container_size_code: "20GP",
|
249
|
+
destination_locode: "USSEA",
|
250
|
+
emissions_scope: "wtw",
|
251
|
+
freight_mass_g: 124_870,
|
252
|
+
origin_locode: "USSD2"
|
253
|
+
)
|
254
|
+
expect(road_shipping_estimate.data.type).to eq('shipping_road')
|
255
|
+
expect(road_shipping_estimate.data.mass_g).to be >= 15_000
|
256
|
+
end
|
257
|
+
|
258
|
+
it "supports creating an estimate using postal codes" do
|
259
|
+
road_shipping_estimate = Patch::Estimate.create_road_shipping_estimate(
|
260
|
+
create_order: false,
|
261
|
+
destination_country_code: "US",
|
262
|
+
destination_postal_code: "97209",
|
263
|
+
emissions_scope: "wtw",
|
264
|
+
freight_mass_g: 226_000,
|
265
|
+
origin_country_code: "US",
|
266
|
+
origin_postal_code: "90210"
|
267
|
+
)
|
268
|
+
expect(road_shipping_estimate.data.type).to eq('shipping_road')
|
269
|
+
expect(road_shipping_estimate.data.mass_g).to be >= 4_000
|
270
|
+
end
|
271
|
+
|
272
|
+
it "supports creating an estimate with an order" do
|
273
|
+
road_shipping_estimate = Patch::Estimate.create_road_shipping_estimate(
|
274
|
+
create_order: true,
|
275
|
+
destination_locode: "USSEA",
|
276
|
+
freight_mass_g: 359_000,
|
277
|
+
origin_locode: "USSD2"
|
278
|
+
)
|
279
|
+
expect(road_shipping_estimate.data.type).to eq('shipping_road')
|
280
|
+
expect(road_shipping_estimate.data.mass_g).to be >= 15_000
|
281
|
+
expect(road_shipping_estimate.data.order.amount).to be >= 10_000
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
context "when creating a sea shipping estimate" do
|
286
|
+
it "supports creating an estimate using locodes" do
|
287
|
+
sea_shipping_estimate = Patch::Estimate.create_sea_shipping_estimate(
|
288
|
+
create_order: false,
|
289
|
+
container_size_code: "20GP",
|
290
|
+
destination_locode: "HKHKG",
|
291
|
+
emissions_scope: "wtw",
|
292
|
+
freight_mass_g: 124_870,
|
293
|
+
origin_locode: "FRMRS"
|
294
|
+
)
|
295
|
+
expect(sea_shipping_estimate.data.type).to eq('shipping_sea')
|
296
|
+
expect(sea_shipping_estimate.data.mass_g).to be >= 10_000
|
297
|
+
end
|
298
|
+
|
299
|
+
it "supports creating an estimate using postal codes" do
|
300
|
+
sea_shipping_estimate = Patch::Estimate.create_sea_shipping_estimate(
|
301
|
+
create_order: false,
|
302
|
+
destination_country_code: "US",
|
303
|
+
destination_postal_code: "97209",
|
304
|
+
emissions_scope: "wtw",
|
305
|
+
freight_mass_g: 226_000,
|
306
|
+
origin_country_code: "US",
|
307
|
+
origin_postal_code: "90210"
|
308
|
+
)
|
309
|
+
expect(sea_shipping_estimate.data.type).to eq('shipping_sea')
|
310
|
+
expect(sea_shipping_estimate.data.mass_g).to be >= 4_000
|
311
|
+
end
|
312
|
+
|
313
|
+
it "supports creating an estimate with an order" do
|
314
|
+
sea_shipping_estimate = Patch::Estimate.create_sea_shipping_estimate(
|
315
|
+
create_order: true,
|
316
|
+
destination_locode: "USSEA",
|
317
|
+
freight_mass_g: 359_000,
|
318
|
+
origin_locode: "USSD2"
|
319
|
+
)
|
320
|
+
expect(sea_shipping_estimate.data.type).to eq('shipping_sea')
|
321
|
+
expect(sea_shipping_estimate.data.mass_g).to be >= 15_000
|
322
|
+
expect(sea_shipping_estimate.data.order.amount).to be >= 10_000
|
323
|
+
end
|
324
|
+
end
|
174
325
|
end
|
@@ -42,6 +42,29 @@ RSpec.describe 'Orders Integration' do
|
|
42
42
|
expect(order.registry_url).not_to be_empty
|
43
43
|
end
|
44
44
|
|
45
|
+
it 'supports create with issued_to' do
|
46
|
+
retrieve_project_response = Patch::Project.retrieve_project(
|
47
|
+
Constants::BIOMASS_TEST_PROJECT_ID
|
48
|
+
)
|
49
|
+
|
50
|
+
issued_to = { email: 'envimpact@companyb.com', name: 'Company B' }
|
51
|
+
total_price_cents_usd = 50_00
|
52
|
+
|
53
|
+
create_order_response = Patch::Order.create_order(
|
54
|
+
total_price_cents_usd: total_price_cents_usd,
|
55
|
+
issued_to: issued_to
|
56
|
+
)
|
57
|
+
|
58
|
+
expect(create_order_response.success).to eq true
|
59
|
+
|
60
|
+
order = create_order_response.data
|
61
|
+
|
62
|
+
expect(order.id).not_to be_nil
|
63
|
+
expect(order.price_cents_usd + order.patch_fee_cents_usd).to eq total_price_cents_usd
|
64
|
+
expect(order.issued_to.email).to eq(issued_to[:email])
|
65
|
+
expect(order.issued_to.name).to eq(issued_to[:name])
|
66
|
+
end
|
67
|
+
|
45
68
|
it 'supports create with a total price' do
|
46
69
|
retrieve_project_response = Patch::Project.retrieve_project(
|
47
70
|
Constants::BIOMASS_TEST_PROJECT_ID
|
@@ -108,6 +131,17 @@ RSpec.describe 'Orders Integration' do
|
|
108
131
|
expect(cancel_order_response.data.state).to eq 'cancelled'
|
109
132
|
end
|
110
133
|
|
134
|
+
it 'supports place order with issued_to' do
|
135
|
+
create_estimate_to_place_response = Patch::Estimate.create_mass_estimate(mass_g: 100, create_order: true)
|
136
|
+
order_to_place_id = create_estimate_to_place_response.data.order.id
|
137
|
+
|
138
|
+
issued_to = { email: 'envimpact@companya.com', name: 'Company A' }
|
139
|
+
place_order_response = Patch::Order.place_order(order_to_place_id, issued_to: issued_to)
|
140
|
+
expect(place_order_response.data.state).to eq 'placed'
|
141
|
+
expect(place_order_response.data.issued_to.email).to eq(issued_to[:email])
|
142
|
+
expect(place_order_response.data.issued_to.name).to eq(issued_to[:name])
|
143
|
+
end
|
144
|
+
|
111
145
|
it 'supports create with a vintage year' do
|
112
146
|
create_order_response =
|
113
147
|
Patch::Order.create_order(mass_g: 100, vintage_year: 2022)
|
@@ -38,40 +38,48 @@ RSpec.describe 'Projects Integration' do
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
41
|
+
it 'returns the expected fields' do
|
42
|
+
project = Patch::Project.retrieve_projects(page: 1).data.first
|
43
|
+
|
44
|
+
keys = attributes_for(:project).keys
|
45
|
+
expect(project.to_hash.keys).to include(*keys)
|
46
|
+
|
47
|
+
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
|
+
expect(project.longitude).to be_an_instance_of(Float)
|
52
|
+
expect(project.latitude).to be_an_instance_of(Float)
|
53
|
+
|
54
|
+
expect(project.technology_type)
|
55
|
+
.to be_an_instance_of(Patch::TechnologyType)
|
56
|
+
expect(project.technology_type.name).to be_an_instance_of(String)
|
57
|
+
expect(project.technology_type.slug).to be_an_instance_of(String)
|
58
|
+
|
59
|
+
parent_type = project.technology_type.parent_technology_type
|
60
|
+
expect(parent_type).to be_an_instance_of(Patch::ParentTechnologyType)
|
61
|
+
expect(parent_type.name).to be_an_instance_of(String)
|
62
|
+
expect(parent_type.slug).to be_an_instance_of(String)
|
63
|
+
|
64
|
+
expect(project.highlights).to be_an_instance_of(Array)
|
65
|
+
|
66
|
+
inventory = project.inventory
|
67
|
+
expect(inventory).to be_an_instance_of(Array)
|
68
|
+
expect(inventory[0]).to be_an_instance_of(Patch::Inventory)
|
69
|
+
expect(inventory[0].vintage_year).to be_an_instance_of(Integer)
|
70
|
+
expect(inventory[0].amount_available).to be_an_instance_of(Integer)
|
71
|
+
expect(inventory[0].price).to be_an_instance_of(Integer)
|
72
|
+
expect(inventory[0].currency).to be_an_instance_of(String)
|
73
|
+
expect(inventory[0].unit).to be_an_instance_of(String)
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'retrieves projects in the requested language' do
|
77
|
+
projects_response = Patch::Project.retrieve_projects(accept_language: 'fr')
|
78
|
+
|
79
|
+
expect(projects_response.data.first.name).to include 'Démo' # French
|
80
|
+
|
81
|
+
project_id = projects_response.data.first.id
|
82
|
+
project_response = Patch::Project.retrieve_project(project_id, accept_language: 'fr')
|
83
|
+
expect(project_response.data.name).to include 'Démo' # Frenc
|
76
84
|
end
|
77
85
|
end
|
@@ -31,7 +31,7 @@ describe 'CreateOrderRequest' do
|
|
31
31
|
let(:instance) { @instance }
|
32
32
|
let(:instance_hash) { { project_id: @instance.project_id, mass_g: @instance.mass_g, total_price_cents_usd: @instance.total_price_cents_usd, metadata: @instance.metadata } }
|
33
33
|
let(:nullable_properties) do
|
34
|
-
Set.new(%i[mass_g total_price_cents_usd project_id metadata state vintage_year total_price currency amount unit])
|
34
|
+
Set.new(%i[mass_g total_price_cents_usd project_id metadata state vintage_year total_price currency amount unit issued_to])
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|