diff --git a/__tests__/Api/BankAccount.unit.rb b/__tests__/Api/BankAccount.unit.rb index a597a97..25961ca 100755 --- a/__tests__/Api/BankAccount.unit.rb +++ b/__tests__/Api/BankAccount.unit.rb @@ -215,7 +215,7 @@ it "handles errors returned by the api" do bankAccountApiMock = double("ApiClient") bankAccountApi = BankAccountsApi.new(bankAccountApiMock) - bankAccountVerify = BankAccountVerify.new + bankAccountVerify = BankAccountVerify.new(amounts: [11, 35]) allow(bankAccountApi).to receive(:verify).and_raise("exception thrown in verification test") begin @@ -228,7 +228,7 @@ it "verifies a bank account" do bankAccountApiMock = double("ApiClient") bankAccountApi = BankAccountsApi.new(bankAccountApiMock) - bankAccountVerify = BankAccountVerify.new + bankAccountVerify = BankAccountVerify.new(amounts: [11, 35]) fakeBankAccount = BankAccount.new fakeBankAccount.verified = true fakeBankAccount.id = "bank_fakeId" diff --git a/__tests__/Integration/Postcard.spec.rb b/__tests__/Integration/Postcard.spec.rb index a1d40da..97621cf 100755 --- a/__tests__/Integration/Postcard.spec.rb +++ b/__tests__/Integration/Postcard.spec.rb @@ -126,6 +126,38 @@ before(:all) do api = TestFixtures.api_client_with_test_key() @postcardApi = PostcardsApi.new(api) + + addressEditable1 = AddressEditable.new({ + name: "Thing T. Thing", + address_line1: "1313 CEMETERY LN", + address_city: "WESTFIELD", + address_state: "NJ", + address_zip: "07000", + }) + + addressEditable2 = AddressEditable.new({ + name: "FESTER", + address_line1: "001 CEMETERY LN", + address_line2: "SUITE 666", + address_city: "WESTFIELD", + address_state: "NJ", + address_zip: "07000", + }) + + dummyPostcard = PostcardEditable.new({ + to: addressEditable1, + from: addressEditable2, + front: TestFixtures.FILE_LOCATION_4x6, + back: TestFixtures.FILE_LOCATION_4x6, + use_type: 'marketing' + }) + + response1 = @postcardApi.create(dummyPostcard) + response2 = @postcardApi.create(dummyPostcard) + response3 = @postcardApi.create(dummyPostcard) + response4 = @postcardApi.create(dummyPostcard) + response5 = @postcardApi.create(dummyPostcard) + @postcardIds = [response1.id, response2.id, response3.id, response4.id, response5.id] end it "lists postcards with limit, before, and after params" do @@ -168,6 +200,10 @@ end end end + + after(:all) do + @postcardIds.each { |id| @postcardApi.cancel(id) } + end end describe "cancel" do diff --git a/__tests__/Integration/SelfMailer.spec.rb b/__tests__/Integration/SelfMailer.spec.rb index 88b33f6..a824711 100755 --- a/__tests__/Integration/SelfMailer.spec.rb +++ b/__tests__/Integration/SelfMailer.spec.rb @@ -138,13 +138,31 @@ use_type: SfmUseType::MARKETING }) + selfMailerEditable4 = SelfMailerEditable.new({ + to: addr, + inside: TestFixtures.FILE_LOCATION_6X18, + outside: TestFixtures.FILE_LOCATION_6X18, + use_type: SfmUseType::MARKETING + }) + + selfMailerEditable5 = SelfMailerEditable.new({ + to: addr, + inside: TestFixtures.FILE_LOCATION_6X18, + outside: TestFixtures.FILE_LOCATION_6X18, + use_type: SfmUseType::MARKETING + }) + response1 = @selfMailerApi.create(selfMailerEditable1) response2 = @selfMailerApi.create(selfMailerEditable2) response3 = @selfMailerApi.create(selfMailerEditable3) + response4 = @selfMailerApi.create(selfMailerEditable4) + response5 = @selfMailerApi.create(selfMailerEditable5) @selfMailer1Id = response1.id @selfMailer2Id = response2.id @selfMailer3Id = response3.id + @selfMailer4Id = response4.id + @selfMailer5Id = response5.id end it "lists self mailers with limit, before, and after params" do @@ -232,6 +250,8 @@ @selfMailerApi.delete(@selfMailer1Id) @selfMailerApi.delete(@selfMailer2Id) @selfMailerApi.delete(@selfMailer3Id) + @selfMailerApi.delete(@selfMailer4Id) + @selfMailerApi.delete(@selfMailer5Id) end end diff --git a/lib/lob/models/bank_account.rb b/lib/lob/models/bank_account.rb index 9c9c33a..90d37d4 100755 --- a/lib/lob/models/bank_account.rb +++ b/lib/lob/models/bank_account.rb @@ -55,6 +55,9 @@ class BankAccount attr_accessor :object + # The type of microdeposit verification used for this bank account. Either "amounts" or "descriptor_code", or null once verified. + attr_accessor :microdeposit_type + class EnumAttributeValidator attr_reader :datatype attr_reader :allowable_values @@ -93,7 +96,8 @@ def self.attribute_map :'date_created' => :'date_created', :'date_modified' => :'date_modified', :'deleted' => :'deleted', - :'object' => :'object' + :'object' => :'object', + :'microdeposit_type' => :'microdeposit_type' } end @@ -118,7 +122,8 @@ def self.openapi_types :'date_created' => :'Time', :'date_modified' => :'Time', :'deleted' => :'Boolean', - :'object' => :'String' + :'object' => :'String', + :'microdeposit_type' => :'String' } end @@ -127,6 +132,7 @@ def self.openapi_nullable Set.new([ :'description', :'signature_url', + :'microdeposit_type', ]) end @@ -206,6 +212,10 @@ def initialize(attributes = {}) else self.object = 'bank_account' end + + if attributes.key?(:'microdeposit_type') + self.microdeposit_type = attributes[:'microdeposit_type'] + end end # Show invalid properties with the reasons. Usually used together with valid? @@ -428,7 +438,8 @@ def ==(o) date_created == o.date_created && date_modified == o.date_modified && deleted == o.deleted && - object == o.object + object == o.object && + microdeposit_type == o.microdeposit_type end # @see the `==` method @@ -440,7 +451,7 @@ def eql?(o) # Calculates hash code according to all attributes. # @return [Integer] Hash code def hash - [description, routing_number, account_number, account_type, signatory, metadata, id, signature_url, bank_name, verified, date_created, date_modified, deleted, object].hash + [description, routing_number, account_number, account_type, signatory, metadata, id, signature_url, bank_name, verified, date_created, date_modified, deleted, object, microdeposit_type].hash end diff --git a/lib/lob/models/bank_account_verify.rb b/lib/lob/models/bank_account_verify.rb index e04adb9..776d981 100755 --- a/lib/lob/models/bank_account_verify.rb +++ b/lib/lob/models/bank_account_verify.rb @@ -18,10 +18,14 @@ class BankAccountVerify # In live mode, an array containing the two micro deposits (in cents) placed in the bank account. In test mode, no micro deposits will be placed, so any two integers between `1` and `100` will work. attr_accessor :amounts + # The 6-character code (beginning with SM) from the bank statement descriptor of the single $0.01 microdeposit. Required when microdeposit_type is descriptor_code. + attr_accessor :descriptor_code + # Attribute mapping from ruby-style variable name to JSON key. def self.attribute_map { - :'amounts' => :'amounts' + :'amounts' => :'amounts', + :'descriptor_code' => :'descriptor_code' } end @@ -33,7 +37,8 @@ def self.acceptable_attributes # Attribute type mapping. def self.openapi_types { - :'amounts' => :'Array' + :'amounts' => :'Array', + :'descriptor_code' => :'String' } end @@ -63,22 +68,51 @@ def initialize(attributes = {}) self.amounts = value end end + + if attributes.key?(:'descriptor_code') + self.descriptor_code = attributes[:'descriptor_code'] + end + + has_amounts = !@amounts.nil? + has_descriptor_code = !@descriptor_code.nil? + + if !has_amounts && !has_descriptor_code + fail ArgumentError, 'one of "amounts" or "descriptor_code" must be provided' + end + + if has_amounts && has_descriptor_code + fail ArgumentError, 'only one of "amounts" or "descriptor_code" may be provided' + 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 - if @amounts.nil? - invalid_properties.push('invalid value for "amounts", amounts cannot be nil.') + + if @amounts.nil? && @descriptor_code.nil? + invalid_properties.push('one of "amounts" or "descriptor_code" must be provided') end - if @amounts.length > 2 - invalid_properties.push('invalid value for "amounts", number of items must be less than or equal to 2.') + if !@amounts.nil? && !@descriptor_code.nil? + invalid_properties.push('only one of "amounts" or "descriptor_code" may be provided') + end + + if !@amounts.nil? + if @amounts.length > 2 + invalid_properties.push('invalid value for "amounts", number of items must be less than or equal to 2.') + end + + if @amounts.length < 2 + invalid_properties.push('invalid value for "amounts", number of items must be greater than or equal to 2.') + end end - if @amounts.length < 2 - invalid_properties.push('invalid value for "amounts", number of items must be greater than or equal to 2.') + if !@descriptor_code.nil? + pattern = Regexp.new(/^SM[a-zA-Z0-9]{4}$/) + if @descriptor_code !~ pattern + invalid_properties.push("invalid value for \"descriptor_code\", must conform to the pattern #{pattern}.") + end end invalid_properties @@ -87,9 +121,15 @@ def list_invalid_properties # Check to see if the all the properties in the model are valid # @return true if the model is valid def valid? - return false if @amounts.nil? - return false if @amounts.length > 2 - return false if @amounts.length < 2 + return false if @amounts.nil? && @descriptor_code.nil? + return false if !@amounts.nil? && !@descriptor_code.nil? + if !@amounts.nil? + return false if @amounts.length > 2 + return false if @amounts.length < 2 + end + if !@descriptor_code.nil? + return false if @descriptor_code !~ Regexp.new(/^SM[a-zA-Z0-9]{4}$/) + end true end @@ -111,12 +151,28 @@ def amounts=(amounts) @amounts = amounts end + # Custom attribute writer method with validation + # @param [Object] descriptor_code Value to be assigned + def descriptor_code=(descriptor_code) + if descriptor_code.nil? + fail ArgumentError, 'descriptor_code cannot be nil' + end + + pattern = Regexp.new(/^SM[a-zA-Z0-9]{4}$/) + if descriptor_code !~ pattern + fail ArgumentError, "invalid value for \"descriptor_code\", must conform to the pattern #{pattern}." + end + + @descriptor_code = descriptor_code + 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 && - amounts == o.amounts + amounts == o.amounts && + descriptor_code == o.descriptor_code end # @see the `==` method @@ -128,7 +184,7 @@ def eql?(o) # Calculates hash code according to all attributes. # @return [Integer] Hash code def hash - [amounts].hash + [amounts, descriptor_code].hash end diff --git a/lib/lob/version.rb b/lib/lob/version.rb index 3c3aa57..e8b7db0 100755 --- a/lib/lob/version.rb +++ b/lib/lob/version.rb @@ -11,5 +11,5 @@ =end module Lob - VERSION = '6.0.9' + VERSION = '6.1.0' end diff --git a/spec/api/bank_accounts_api_spec.rb b/spec/api/bank_accounts_api_spec.rb index beba961..54cf0dd 100755 --- a/spec/api/bank_accounts_api_spec.rb +++ b/spec/api/bank_accounts_api_spec.rb @@ -13,89 +13,122 @@ require 'spec_helper' require 'json' -# Unit tests for Lob::BankAccountsApi -# Automatically generated by openapi-generator (https://openapi-generator.tech) -# Please update as you see appropriate describe 'BankAccountsApi' do before do - # run before each test @api_instance = Lob::BankAccountsApi.new end - after do - # run after each test - end - describe 'test an instance of BankAccountsApi' do it 'should create an instance of BankAccountsApi' do expect(@api_instance).to be_instance_of(Lob::BankAccountsApi) end end - # unit tests for bank_account_create - # create - # Creates a new bank account with the provided properties. Bank accounts created in live mode will need to be verified via micro deposits before being able to send live checks. The deposits will appear in the bank account in 2-3 business days and have the description \"VERIFICATION\". - # @param bank_account_writable - # @param [Hash] opts the optional parameters - # @return [BankAccount] describe 'bank_account_create test' do it 'should work' do # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end - # unit tests for bank_account_delete - # delete - # Permanently deletes a bank account. It cannot be undone. - # @param bank_id id of the bank account - # @param [Hash] opts the optional parameters - # @return [BankAccountDeletion] describe 'bank_account_delete test' do it 'should work' do # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end - # unit tests for bank_account_retrieve - # get - # Retrieves the details of an existing bank account. You need only supply the unique bank account identifier that was returned upon bank account creation. - # @param bank_id id of the bank account - # @param [Hash] opts the optional parameters - # @return [BankAccount] describe 'bank_account_retrieve test' do it 'should work' do # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end - # unit tests for bank_account_verify - # verify - # Verify a bank account in order to create a check. - # @param bank_id id of the bank account to be verified - # @param bank_account_verify - # @param [Hash] opts the optional parameters - # @return [BankAccount] describe 'bank_account_verify test' do it 'should work' do # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end - # unit tests for bank_accounts_list - # list - # Returns a list of your bank accounts. The bank accounts are returned sorted by creation date, with the most recently created bank accounts appearing first. - # @param [Hash] opts the optional parameters - # @option opts [Integer] :limit How many results to return. - # @option opts [String] :before A reference to a list entry used for paginating to the previous set of entries. This field is pre-populated in the `previous_url` field in the return response. - # @option opts [String] :after A reference to a list entry used for paginating to the next set of entries. This field is pre-populated in the `next_url` field in the return response. - # @option opts [Array] :include Request that the response include the total count by specifying `include[]=total_count`. - # @option opts [Hash] :date_created Filter by date created. - # @option opts [Hash] :metadata Filter by metadata key-value pair`. - # @return [BankAccountList] describe 'bank_accounts_list test' do it 'should work' do # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers end end + describe 'BankAccountVerify model' do + it 'accepts amounts' do + verify = Lob::BankAccountVerify.new(amounts: [11, 35]) + expect(verify.amounts).to eq([11, 35]) + expect(verify.descriptor_code).to be_nil + end + + it 'accepts a valid descriptor_code' do + verify = Lob::BankAccountVerify.new(descriptor_code: 'SM11AA') + expect(verify.descriptor_code).to eq('SM11AA') + expect(verify.amounts).to be_nil + end + + it 'raises when neither amounts nor descriptor_code is provided' do + expect { + Lob::BankAccountVerify.new({}) + }.to raise_error(ArgumentError, /one of "amounts" or "descriptor_code" must be provided/) + end + + it 'raises when both amounts and descriptor_code are provided' do + expect { + Lob::BankAccountVerify.new(amounts: [11, 35], descriptor_code: 'SM11AA') + }.to raise_error(ArgumentError, /only one of "amounts" or "descriptor_code" may be provided/) + end + + it 'raises when descriptor_code does not match the pattern' do + expect { + Lob::BankAccountVerify.new(descriptor_code: 'INVALID') + }.to raise_error(ArgumentError, /must conform to the pattern/) + end + + it 'raises when descriptor_code does not start with SM' do + expect { + Lob::BankAccountVerify.new(descriptor_code: 'AB1234') + }.to raise_error(ArgumentError, /must conform to the pattern/) + end + + it 'raises when descriptor_code is too short' do + expect { + Lob::BankAccountVerify.new(descriptor_code: 'SM123') + }.to raise_error(ArgumentError, /must conform to the pattern/) + end + + it 'raises when descriptor_code is too long' do + expect { + Lob::BankAccountVerify.new(descriptor_code: 'SM12345') + }.to raise_error(ArgumentError, /must conform to the pattern/) + end + + it 'is valid with amounts' do + verify = Lob::BankAccountVerify.new(amounts: [11, 35]) + expect(verify.valid?).to be true + end + + it 'is valid with descriptor_code' do + verify = Lob::BankAccountVerify.new(descriptor_code: 'SM11AA') + expect(verify.valid?).to be true + end + end + + describe 'BankAccount model microdeposit_type' do + it 'accepts microdeposit_type "amounts"' do + account = Lob::BankAccount.new(microdeposit_type: 'amounts') + expect(account.microdeposit_type).to eq('amounts') + end + + it 'accepts microdeposit_type "descriptor_code"' do + account = Lob::BankAccount.new(microdeposit_type: 'descriptor_code') + expect(account.microdeposit_type).to eq('descriptor_code') + end + + it 'defaults microdeposit_type to nil when not provided' do + account = Lob::BankAccount.new({}) + expect(account.microdeposit_type).to be_nil + end + end + end