Skip to content

Update parameter validation #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ build/
.openapi-generator-ignore
/.openapi-generator/

.byebug_history
.byebug_history
.DS_Store
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.5.2] - 2021-03-30

### Changed

- Updated the value validation for certain parameters to match the API
- Added the `renewables` type

## [1.5.1] - 2021-03-02

### Fixed
Expand Down
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
patch_ruby (1.5.1)
patch_ruby (1.5.2)
json (~> 2.1, >= 2.1.0)
typhoeus (~> 1.0, >= 1.0.1)

Expand All @@ -23,7 +23,7 @@ GEM
ffi (>= 1.3.0)
factory_bot (6.1.0)
activesupport (>= 5.0.0)
ffi (1.14.2)
ffi (1.15.0)
i18n (1.8.7)
concurrent-ruby (~> 1.0)
json (2.5.1)
Expand Down Expand Up @@ -86,4 +86,4 @@ DEPENDENCIES
rubocop

BUNDLED WITH
2.1.4
2.2.14
10 changes: 5 additions & 5 deletions lib/patch_ruby/models/create_mass_estimate_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ def list_invalid_properties
invalid_properties.push('invalid value for "mass_g", must be smaller than or equal to 2000000000.')
end

if @mass_g < 1
invalid_properties.push('invalid value for "mass_g", must be greater than or equal to 1.')
if @mass_g < 0
invalid_properties.push('invalid value for "mass_g", must be greater than or equal to 0.')
end

invalid_properties
Expand All @@ -110,7 +110,7 @@ def list_invalid_properties
def valid?
return false if @mass_g.nil?
return false if @mass_g > 2000000000
return false if @mass_g < 1
return false if @mass_g < 0
true
end

Expand All @@ -125,8 +125,8 @@ def mass_g=(mass_g)
fail ArgumentError, 'invalid value for "mass_g", must be smaller than or equal to 2000000000.'
end

if mass_g < 1
fail ArgumentError, 'invalid value for "mass_g", must be greater than or equal to 1.'
if mass_g < 0
fail ArgumentError, 'invalid value for "mass_g", must be greater than or equal to 0.'
end

@mass_g = mass_g
Expand Down
10 changes: 5 additions & 5 deletions lib/patch_ruby/models/create_order_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ def list_invalid_properties
invalid_properties.push('invalid value for "mass_g", must be smaller than or equal to 2000000000.')
end

if !@mass_g.nil? && @mass_g < 1
invalid_properties.push('invalid value for "mass_g", must be greater than or equal to 1.')
if !@mass_g.nil? && @mass_g < 0
invalid_properties.push('invalid value for "mass_g", must be greater than or equal to 0.')
end

if !@total_price_cents_usd.nil? && @total_price_cents_usd < 1
Expand All @@ -115,7 +115,7 @@ def list_invalid_properties
# @return true if the model is valid
def valid?
return false if !@mass_g.nil? && @mass_g > 2000000000
return false if !@mass_g.nil? && @mass_g < 1
return false if !@mass_g.nil? && @mass_g < 0
return false if !@total_price_cents_usd.nil? && @total_price_cents_usd < 1
true
end
Expand All @@ -127,8 +127,8 @@ def mass_g=(mass_g)
fail ArgumentError, 'invalid value for "mass_g", must be smaller than or equal to 2000000000.'
end

if !mass_g.nil? && mass_g < 1
fail ArgumentError, 'invalid value for "mass_g", must be greater than or equal to 1.'
if !mass_g.nil? && mass_g < 0
fail ArgumentError, 'invalid value for "mass_g", must be greater than or equal to 0.'
end

@mass_g = mass_g
Expand Down
10 changes: 5 additions & 5 deletions lib/patch_ruby/models/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ def list_invalid_properties
invalid_properties.push('invalid value for "mass_g", must be smaller than or equal to 2000000000.')
end

if @mass_g < 1
invalid_properties.push('invalid value for "mass_g", must be greater than or equal to 1.')
if @mass_g < 0
invalid_properties.push('invalid value for "mass_g", must be greater than or equal to 0.')
end

if @production.nil?
Expand Down Expand Up @@ -218,7 +218,7 @@ def valid?
return false if @id.nil?
return false if @mass_g.nil?
return false if @mass_g > 2000000000
return false if @mass_g < 1
return false if @mass_g < 0
return false if @production.nil?
return false if @state.nil?
state_validator = EnumAttributeValidator.new('String', ["draft", "placed", "complete", "cancelled"])
Expand All @@ -242,8 +242,8 @@ def mass_g=(mass_g)
fail ArgumentError, 'invalid value for "mass_g", must be smaller than or equal to 2000000000.'
end

if mass_g < 1
fail ArgumentError, 'invalid value for "mass_g", must be greater than or equal to 1.'
if mass_g < 0
fail ArgumentError, 'invalid value for "mass_g", must be greater than or equal to 0.'
end

@mass_g = mass_g
Expand Down
6 changes: 3 additions & 3 deletions lib/patch_ruby/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Project
# The description of the project.
attr_accessor :description

# The type of carbon removal project, currently available project types are Biomass, Dac, Forestry, Mineralization, Ocean, Soil.
# The type of carbon removal project, currently available project types are Biomass, Dac, Forestry, Mineralization, Ocean, Renewables, Soil.
attr_accessor :type

# The country of origin of the project.
Expand Down Expand Up @@ -246,7 +246,7 @@ def valid?
return false if @production.nil?
return false if @name.nil?
return false if @description.nil?
type_validator = EnumAttributeValidator.new('String', ["biomass", "dac", "forestry", "mineralization", "ocean", "soil"])
type_validator = EnumAttributeValidator.new('String', ["biomass", "dac", "forestry", "mineralization", "ocean", "renewables", "soil"])
return false unless type_validator.valid?(@type)
return false if @country.nil?
return false if @developer.nil?
Expand All @@ -258,7 +258,7 @@ def valid?
# Custom attribute writer method checking allowed values (enum).
# @param [Object] type Object to be assigned
def type=(type)
validator = EnumAttributeValidator.new('String', ["biomass", "dac", "forestry", "mineralization", "ocean", "soil"])
validator = EnumAttributeValidator.new('String', ["biomass", "dac", "forestry", "mineralization", "ocean", "renewables", "soil"])
unless validator.valid?(type)
fail ArgumentError, "invalid value for \"type\", must be one of #{validator.allowable_values}."
end
Expand Down
2 changes: 1 addition & 1 deletion lib/patch_ruby/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
=end

module Patch
VERSION = '1.5.1'
VERSION = '1.5.2'
end
9 changes: 5 additions & 4 deletions spec/integration/orders_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@

create_order_response = Patch::Order.create_order(mass_g: order_mass_g, project_id: project_id)

order = create_order_response.data
expect(create_order_response.success).to eq true
expect(create_order_response.data.id).not_to be_nil
expect(create_order_response.data.mass_g).to eq(order_mass_g)
expect(create_order_response.data.price_cents_usd.to_i).to eq(expected_price)
expect(create_order_response.data.patch_fee_cents_usd).not_to be_empty
expect(order.id).not_to be_nil
expect(order.mass_g).to eq(order_mass_g)
expect(order.price_cents_usd.to_i).to be_between(expected_price - 1, expected_price + 1)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We added offsets to the project used in this test and it threw things slightly out of bounds.

Because of the rounded nature of the calculation, the new average_price calculation disturbed this test. I am adding a tiny bit of slack to it (+1 / - 1 is small and keep things from bigger deviations)

expect(order.patch_fee_cents_usd).not_to be_empty
end

it 'supports create with a total price' do
Expand Down