Skip to content

Commit

Permalink
Merge pull request #53 from platanus/remove-quantity-check
Browse files Browse the repository at this point in the history
refactor(security): Remove deposits quantity
  • Loading branch information
juanweitz committed Dec 5, 2018
2 parents d34371c + 092edd9 commit 63d5976
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 43 deletions.
4 changes: 1 addition & 3 deletions lib/bank_api/clients/banco_security/company_client.rb
Expand Up @@ -93,9 +93,7 @@ def execute_batch_transfers(transfers_data)
def get_deposits_from_transfers_section
goto_deposits
select_deposits_range
deposits = deposits_from_txt
validate_deposits(deposits) unless deposits.empty?
deposits
deposits_from_txt
end

def get_deposits_from_balance_section(account_number)
Expand Down
14 changes: 0 additions & 14 deletions lib/bank_api/clients/banco_security/concerns/deposits.rb
Expand Up @@ -106,27 +106,13 @@ def deposits_account_details_url
browser.search("a:contains('Descargar TXT')").first.attribute("href")
end

def total_deposits
pages_info = wait(".k-pager-info")
matches = pages_info.text.match(/(\d+)[a-z\s-]+(\d+)[a-z\s-]+(\d+)/)
matches[3].to_i
end

def any_deposits?
browser.search(
"#gridPrincipalRecibidas " \
".k-label:contains('No se han encontrado transacciones para la búsqueda seleccionada.')"
).none?
end

def validate_deposits(deposits)
total_deposits_ = total_deposits
unless deposits.count == total_deposits_
raise BankApi::Deposit::QuantityError, "Expected #{total_deposits_} deposits," +
" got #{deposits.count}."
end
end

def timezone
@timezone ||= Timezone['America/Santiago']
end
Expand Down
1 change: 0 additions & 1 deletion lib/bank_api/exceptions.rb
Expand Up @@ -6,7 +6,6 @@ class MissingAccountBalance < StandardError; end
end
module Deposit
class FetchError < StandardError; end
class QuantityError < StandardError; end
end
module Withdrawal
class FetchError < StandardError; end
Expand Down
25 changes: 0 additions & 25 deletions spec/bank_api/clients/banco_security/company_client_spec.rb
Expand Up @@ -273,31 +273,6 @@ def mock_json_fetch
end
end

describe "#validate_deposits" do
before do
mock_validate_credentials
mock_site_navigation
mock_wait_for_deposits_fetch
allow(subject).to receive(:any_deposits?).and_return(true)
end

context "with less deposits" do
let(:deposits) { [{}] * 30 }

before do
allow(subject).to receive(:deposits_from_txt).and_return(deposits)
allow(subject).to receive(:total_deposits).and_return(50)
end

it "raises error" do
expect { perform }.to raise_error(
BankApi::Deposit::QuantityError, "Expected 50 deposits," +
" got 30."
)
end
end
end

describe "ensure browser.close" do
before do
mock_validate_credentials
Expand Down

0 comments on commit 63d5976

Please sign in to comment.