From ccfdab0d54dd988a294dcf320ddf6523398bf26f Mon Sep 17 00:00:00 2001 From: James Klein Date: Fri, 24 Sep 2021 17:51:47 -0600 Subject: [PATCH] Adds mechanism, tagline, state, latitude, longitude, and technology_type to project responses (#47) --- .github/PULL_REQUEST_TEMPLATE.md | 2 +- CHANGELOG.md | 6 + Gemfile.lock | 2 +- lib/patch_ruby.rb | 2 + lib/patch_ruby/api_client.rb | 2 +- .../models/parent_technology_type.rb | 239 +++++++++++++++++ lib/patch_ruby/models/project.rb | 85 +++++- lib/patch_ruby/models/technology_type.rb | 248 ++++++++++++++++++ lib/patch_ruby/version.rb | 2 +- spec/factories/parent_technology_type.rb | 8 + spec/factories/projects.rb | 7 + spec/factories/sdgs.rb | 10 + spec/factories/technology_type.rb | 9 + spec/integration/projects_spec.rb | 19 +- spec/models/project_spec.rb | 12 +- 15 files changed, 641 insertions(+), 12 deletions(-) create mode 100644 lib/patch_ruby/models/parent_technology_type.rb create mode 100644 lib/patch_ruby/models/technology_type.rb create mode 100644 spec/factories/parent_technology_type.rb create mode 100644 spec/factories/sdgs.rb create mode 100644 spec/factories/technology_type.rb diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index b3f9d31..cb9ce56 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -11,5 +11,5 @@ - [ ] Have you added an integration test for the changes? - [ ] Have you built the gem locally and made queries against it successfully? - [ ] Did you update the changelog? -- [ ] Did you bump the package version? +- [ ] Did you bump the package version [in the code generator](https://github.com/patch-technology/client-code-generation/blob/main/configs/ruby-config.json#L11-L12)? - [ ] For breaking changes, did you plan for the release of the new SDK versions and deploy the API to production? diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b10f57..f4444de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ 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.14.0] - 2021-09-21 + +### Added + +- Adds mechanism, tagline, state, latitude, longitude, and technology_type to project responses + ## [1.13.0] - 2021-09-10 ### Added diff --git a/Gemfile.lock b/Gemfile.lock index ef4fb72..a5758d0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - patch_ruby (1.13.0) + patch_ruby (1.14.0) typhoeus (~> 1.0, >= 1.0.1) GEM diff --git a/lib/patch_ruby.rb b/lib/patch_ruby.rb index 3f61445..8fcf5bd 100644 --- a/lib/patch_ruby.rb +++ b/lib/patch_ruby.rb @@ -35,6 +35,7 @@ require 'patch_ruby/models/order' require 'patch_ruby/models/order_list_response' require 'patch_ruby/models/order_response' +require 'patch_ruby/models/parent_technology_type' require 'patch_ruby/models/photo' require 'patch_ruby/models/preference' require 'patch_ruby/models/preference_list_response' @@ -44,6 +45,7 @@ require 'patch_ruby/models/project_response' require 'patch_ruby/models/sdg' require 'patch_ruby/models/standard' +require 'patch_ruby/models/technology_type' # APIs require 'patch_ruby/api/estimates_api' diff --git a/lib/patch_ruby/api_client.rb b/lib/patch_ruby/api_client.rb index 050f3c6..2dd8e19 100644 --- a/lib/patch_ruby/api_client.rb +++ b/lib/patch_ruby/api_client.rb @@ -31,7 +31,7 @@ class ApiClient # @option config [Configuration] Configuration for initializing the object, default to Configuration.default def initialize(config = Configuration.default) @config = config - @user_agent = "patch-ruby/1.13.0" + @user_agent = "patch-ruby/1.14.0" @default_headers = { 'Content-Type' => 'application/json', 'User-Agent' => @user_agent diff --git a/lib/patch_ruby/models/parent_technology_type.rb b/lib/patch_ruby/models/parent_technology_type.rb new file mode 100644 index 0000000..06f3795 --- /dev/null +++ b/lib/patch_ruby/models/parent_technology_type.rb @@ -0,0 +1,239 @@ +=begin +#Patch API V1 + +#The core API used to integrate with Patch's service + +The version of the OpenAPI document: v1 +Contact: developers@usepatch.com +Generated by: https://openapi-generator.tech +OpenAPI Generator version: 5.2.1 + +=end + +require 'date' +require 'time' + +module Patch + class ParentTechnologyType + # Unique identifier for this type of technology. + attr_accessor :slug + + # Name of this technology type. + attr_accessor :name + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :'slug' => :'slug', + :'name' => :'name' + } + end + + # Returns all the JSON keys this model knows about + def self.acceptable_attributes + attribute_map.values + end + + # Attribute type mapping. + def self.openapi_types + { + :'slug' => :'String', + :'name' => :'String' + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new([ + ]) + end + + + # Allows models with corresponding API classes to delegate API operations to those API classes + # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id + # Eg. Order.create_order delegates to OrdersApi.new.create_order + def self.method_missing(message, *args, &block) + if Object.const_defined?('Patch::ParentTechnologyTypesApi::OPERATIONS') && Patch::ParentTechnologyTypesApi::OPERATIONS.include?(message) + Patch::ParentTechnologyTypesApi.new.send(message, *args) + else + super + end + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + fail ArgumentError, "The input argument (attributes) must be a hash in `Patch::ParentTechnologyType` initialize method" + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + fail ArgumentError, "`#{k}` is not a valid attribute in `Patch::ParentTechnologyType`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect + end + h[k.to_sym] = v + } + + if attributes.key?(:'slug') + self.slug = attributes[:'slug'] + end + + if attributes.key?(:'name') + self.name = attributes[:'name'] + end + end + + # Show invalid properties with the reasons. Usually used together with valid? + # @return Array for valid properties with the reasons + def list_invalid_properties + invalid_properties = Array.new + invalid_properties + end + + # Check to see if the all the properties in the model are valid + # @return true if the model is valid + def valid? + true + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(o) + return true if self.equal?(o) + self.class == o.class && + slug == o.slug && + name == o.name + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(o) + self == o + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [slug, name].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + new.build_from_hash(attributes) + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + self.class.openapi_types.each_pair do |key, type| + if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key) + self.send("#{key}=", nil) + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[self.class.attribute_map[key]].is_a?(Array) + self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) }) + end + elsif !attributes[self.class.attribute_map[key]].nil? + self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]])) + end + end + + self + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def _deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + else # model + # models (e.g. Pet) or oneOf + klass = Patch.const_get(type) + klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = self.send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to? :to_hash + value.to_hash + else + value + end + end + end +end diff --git a/lib/patch_ruby/models/project.rb b/lib/patch_ruby/models/project.rb index bc94974..a9a91a9 100644 --- a/lib/patch_ruby/models/project.rb +++ b/lib/patch_ruby/models/project.rb @@ -30,9 +30,21 @@ class Project # The type of carbon removal project, currently available project types are Biomass, Dac, Forestry, Mineralization, Ocean, Renewables, Soil. attr_accessor :type + # The mechanism of the project. removal or avoidance. + attr_accessor :mechanism + # The country of origin of the project. attr_accessor :country + # The state where this project is located. + attr_accessor :state + + # The latitude at which this project is located. + attr_accessor :latitude + + # The longitude at which this project is located. + attr_accessor :longitude + # The name of the project developer. attr_accessor :developer @@ -51,6 +63,11 @@ class Project # An array returning the UN Sustainable Development Goals associated with this project. attr_accessor :sdgs + attr_accessor :technology_type + + # A short description of the project + attr_accessor :tagline + class EnumAttributeValidator attr_reader :datatype attr_reader :allowable_values @@ -81,13 +98,19 @@ def self.attribute_map :'name' => :'name', :'description' => :'description', :'type' => :'type', + :'mechanism' => :'mechanism', :'country' => :'country', + :'state' => :'state', + :'latitude' => :'latitude', + :'longitude' => :'longitude', :'developer' => :'developer', :'photos' => :'photos', :'average_price_per_tonne_cents_usd' => :'average_price_per_tonne_cents_usd', :'remaining_mass_g' => :'remaining_mass_g', :'standard' => :'standard', - :'sdgs' => :'sdgs' + :'sdgs' => :'sdgs', + :'technology_type' => :'technology_type', + :'tagline' => :'tagline' } end @@ -104,22 +127,32 @@ def self.openapi_types :'name' => :'String', :'description' => :'String', :'type' => :'String', + :'mechanism' => :'String', :'country' => :'String', + :'state' => :'String', + :'latitude' => :'Float', + :'longitude' => :'Float', :'developer' => :'String', :'photos' => :'Array', :'average_price_per_tonne_cents_usd' => :'Integer', :'remaining_mass_g' => :'Integer', :'standard' => :'Standard', - :'sdgs' => :'Array' + :'sdgs' => :'Array', + :'technology_type' => :'TechnologyType', + :'tagline' => :'String' } end # List of attributes with nullable: true def self.openapi_nullable Set.new([ + :'state', + :'latitude', + :'longitude', :'photos', :'standard', - :'sdgs' + :'sdgs', + :'tagline' ]) end @@ -170,10 +203,26 @@ def initialize(attributes = {}) self.type = attributes[:'type'] end + if attributes.key?(:'mechanism') + self.mechanism = attributes[:'mechanism'] + end + if attributes.key?(:'country') self.country = attributes[:'country'] end + if attributes.key?(:'state') + self.state = attributes[:'state'] + end + + if attributes.key?(:'latitude') + self.latitude = attributes[:'latitude'] + end + + if attributes.key?(:'longitude') + self.longitude = attributes[:'longitude'] + end + if attributes.key?(:'developer') self.developer = attributes[:'developer'] end @@ -201,6 +250,14 @@ def initialize(attributes = {}) self.sdgs = value end end + + if attributes.key?(:'technology_type') + self.technology_type = attributes[:'technology_type'] + end + + if attributes.key?(:'tagline') + self.tagline = attributes[:'tagline'] + end end # Show invalid properties with the reasons. Usually used together with valid? @@ -251,6 +308,8 @@ def valid? return false if @description.nil? type_validator = EnumAttributeValidator.new('String', ["biomass", "dac", "forestry", "mineralization", "ocean", "renewables", "soil"]) return false unless type_validator.valid?(@type) + mechanism_validator = EnumAttributeValidator.new('String', ["removal", "avoidance"]) + return false unless mechanism_validator.valid?(@mechanism) return false if @country.nil? return false if @developer.nil? return false if @average_price_per_tonne_cents_usd.nil? @@ -268,6 +327,16 @@ def type=(type) @type = type end + # Custom attribute writer method checking allowed values (enum). + # @param [Object] mechanism Object to be assigned + def mechanism=(mechanism) + validator = EnumAttributeValidator.new('String', ["removal", "avoidance"]) + unless validator.valid?(mechanism) + fail ArgumentError, "invalid value for \"mechanism\", must be one of #{validator.allowable_values}." + end + @mechanism = mechanism + end + # Checks equality by comparing each attribute. # @param [Object] Object to be compared def ==(o) @@ -278,13 +347,19 @@ def ==(o) name == o.name && description == o.description && type == o.type && + mechanism == o.mechanism && country == o.country && + state == o.state && + latitude == o.latitude && + longitude == o.longitude && developer == o.developer && photos == o.photos && average_price_per_tonne_cents_usd == o.average_price_per_tonne_cents_usd && remaining_mass_g == o.remaining_mass_g && standard == o.standard && - sdgs == o.sdgs + sdgs == o.sdgs && + technology_type == o.technology_type && + tagline == o.tagline end # @see the `==` method @@ -296,7 +371,7 @@ def eql?(o) # Calculates hash code according to all attributes. # @return [Integer] Hash code def hash - [id, production, name, description, type, country, developer, photos, average_price_per_tonne_cents_usd, remaining_mass_g, standard, sdgs].hash + [id, production, name, description, type, mechanism, country, state, latitude, longitude, developer, photos, average_price_per_tonne_cents_usd, remaining_mass_g, standard, sdgs, technology_type, tagline].hash end # Builds the object from hash diff --git a/lib/patch_ruby/models/technology_type.rb b/lib/patch_ruby/models/technology_type.rb new file mode 100644 index 0000000..bd06c93 --- /dev/null +++ b/lib/patch_ruby/models/technology_type.rb @@ -0,0 +1,248 @@ +=begin +#Patch API V1 + +#The core API used to integrate with Patch's service + +The version of the OpenAPI document: v1 +Contact: developers@usepatch.com +Generated by: https://openapi-generator.tech +OpenAPI Generator version: 5.2.1 + +=end + +require 'date' +require 'time' + +module Patch + class TechnologyType + # Unique identifier for this type of technology. + attr_accessor :slug + + # Name of this technology type. + attr_accessor :name + + attr_accessor :parent_technology_type + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :'slug' => :'slug', + :'name' => :'name', + :'parent_technology_type' => :'parent_technology_type' + } + end + + # Returns all the JSON keys this model knows about + def self.acceptable_attributes + attribute_map.values + end + + # Attribute type mapping. + def self.openapi_types + { + :'slug' => :'String', + :'name' => :'String', + :'parent_technology_type' => :'ParentTechnologyType' + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new([ + ]) + end + + + # Allows models with corresponding API classes to delegate API operations to those API classes + # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id + # Eg. Order.create_order delegates to OrdersApi.new.create_order + def self.method_missing(message, *args, &block) + if Object.const_defined?('Patch::TechnologyTypesApi::OPERATIONS') && Patch::TechnologyTypesApi::OPERATIONS.include?(message) + Patch::TechnologyTypesApi.new.send(message, *args) + else + super + end + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + fail ArgumentError, "The input argument (attributes) must be a hash in `Patch::TechnologyType` initialize method" + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + fail ArgumentError, "`#{k}` is not a valid attribute in `Patch::TechnologyType`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect + end + h[k.to_sym] = v + } + + if attributes.key?(:'slug') + self.slug = attributes[:'slug'] + end + + if attributes.key?(:'name') + self.name = attributes[:'name'] + end + + if attributes.key?(:'parent_technology_type') + self.parent_technology_type = attributes[:'parent_technology_type'] + end + end + + # Show invalid properties with the reasons. Usually used together with valid? + # @return Array for valid properties with the reasons + def list_invalid_properties + invalid_properties = Array.new + invalid_properties + end + + # Check to see if the all the properties in the model are valid + # @return true if the model is valid + def valid? + true + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(o) + return true if self.equal?(o) + self.class == o.class && + slug == o.slug && + name == o.name && + parent_technology_type == o.parent_technology_type + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(o) + self == o + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [slug, name, parent_technology_type].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + new.build_from_hash(attributes) + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + self.class.openapi_types.each_pair do |key, type| + if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key) + self.send("#{key}=", nil) + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[self.class.attribute_map[key]].is_a?(Array) + self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) }) + end + elsif !attributes[self.class.attribute_map[key]].nil? + self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]])) + end + end + + self + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def _deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + else # model + # models (e.g. Pet) or oneOf + klass = Patch.const_get(type) + klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = self.send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to? :to_hash + value.to_hash + else + value + end + end + end +end diff --git a/lib/patch_ruby/version.rb b/lib/patch_ruby/version.rb index c456466..007156f 100644 --- a/lib/patch_ruby/version.rb +++ b/lib/patch_ruby/version.rb @@ -11,5 +11,5 @@ =end module Patch - VERSION = '1.13.0' + VERSION = '1.14.0' end diff --git a/spec/factories/parent_technology_type.rb b/spec/factories/parent_technology_type.rb new file mode 100644 index 0000000..6db0d85 --- /dev/null +++ b/spec/factories/parent_technology_type.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :parent_technology_type, class: Patch::ParentTechnologyType do + slug { "forestry" } + name { "Forestry" } + end +end diff --git a/spec/factories/projects.rb b/spec/factories/projects.rb index dea7ab7..2e7a05e 100644 --- a/spec/factories/projects.rb +++ b/spec/factories/projects.rb @@ -1,6 +1,9 @@ FactoryBot.define do factory :project, class: Patch::Project do sequence(:id) { |n| n } + association(:technology_type) + sdgs { build_list(:sdg, 1) } + production { false } name { "New Project" } description { "New Descirption" } @@ -11,5 +14,9 @@ average_price_per_tonne_cents_usd { 120 } remaining_mass_g { 1_000 } standard { 'european_biochar_certificate' } + state { 'CO' } + latitude { 45.0 } + longitude { 45.0 } + mechanism { 'removal' } end end diff --git a/spec/factories/sdgs.rb b/spec/factories/sdgs.rb new file mode 100644 index 0000000..c8bbab9 --- /dev/null +++ b/spec/factories/sdgs.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :sdg, class: Patch::Sdg do + description { "Take urgent action to combat climate change and its impacts." } + number { 13 } + title { "Climate Action" } + url { "https://sdgs.un.org/goals/goal13" } + end +end diff --git a/spec/factories/technology_type.rb b/spec/factories/technology_type.rb new file mode 100644 index 0000000..78401ff --- /dev/null +++ b/spec/factories/technology_type.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :technology_type, class: Patch::TechnologyType do + slug { "reforestation" } + name { "Reforestation" } + association(:parent_technology_type) + end +end diff --git a/spec/integration/projects_spec.rb b/spec/integration/projects_spec.rb index 2ef98e8..8729140 100644 --- a/spec/integration/projects_spec.rb +++ b/spec/integration/projects_spec.rb @@ -42,9 +42,26 @@ it 'returns the expected fields' do project = Patch::Project.retrieve_projects(page: 1).data.first + keys = attributes_for(:project).keys + expect(project.to_hash.keys).to include(*keys) + expect(project.photos).to be_an_instance_of(Array) - expect(project.average_price_per_tonne_cents_usd).to be_an_instance_of(Integer) + expect(project.average_price_per_tonne_cents_usd) + .to be_an_instance_of(Integer) expect(project.remaining_mass_g).to be_an_instance_of(Integer) + expect(project.state).to be_an_instance_of(String) + expect(project.longitude).to be_an_instance_of(Float) + expect(project.latitude).to be_an_instance_of(Float) + + expect(project.technology_type) + .to be_an_instance_of(Patch::TechnologyType) + expect(project.technology_type.name).to be_an_instance_of(String) + expect(project.technology_type.slug).to be_an_instance_of(String) + + parent_type = project.technology_type.parent_technology_type + expect(parent_type).to be_an_instance_of(Patch::ParentTechnologyType) + expect(parent_type.name).to be_an_instance_of(String) + expect(parent_type.slug).to be_an_instance_of(String) end end end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 01b5cea..6e813cc 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -41,10 +41,18 @@ photos: @instance.photos, average_price_per_tonne_cents_usd: @instance.average_price_per_tonne_cents_usd, remaining_mass_g: @instance.remaining_mass_g, - standard: @instance.standard + state: @instance.state, + longitude: @instance.longitude, + latitude: @instance.latitude, + standard: @instance.standard, + mechanism: @instance.mechanism, + technology_type: @instance.technology_type.to_hash, + sdgs: @instance.sdgs.map(&:to_hash) } } - let(:nullable_properties) { Set.new([:photos, :standard, :sdgs]) } + let(:nullable_properties) do + Set.new(%i[photos standard sdgs state latitude longitude tagline]) + end end describe 'test an instance of Project' do