Sha256: 094d5f312e5765970d49ba2ce001e856dafef416ae4d4816c18fdbf2f10ddb15

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

require 'danconia/exchanges/bna'

module Danconia
  module Exchanges
    describe BNA do
      subject { BNA.new }

      context 'fetch_rates' do
        it 'extracts the rates from the html' do
          stub_request(:get, 'https://www.bna.com.ar/Personas').to_return body: fixture('home.html')
          rates = subject.fetch_rates

          expect(rates.select { |r| r[:rate_type] == 'billetes' }).to eq [
            {pair: 'USDARS', rate: 78.25, date: Date.new(2020, 9, 1), rate_type: 'billetes'},
            {pair: 'EURARS', rate: 89, date: Date.new(2020, 9, 1), rate_type: 'billetes'},
            {pair: 'BRLARS', rate: 14.5, date: Date.new(2020, 9, 1), rate_type: 'billetes'}
          ]

          expect(rates.select { |r| r[:rate_type] == 'divisas' }).to eq [
            {pair: 'USDARS', rate: 74.18, date: Date.new(2020, 8, 31), rate_type: 'divisas'},
            {pair: 'EURARS', rate: 88.6822, date: Date.new(2020, 8, 31), rate_type: 'divisas'}
          ]
        end

        it 'raise error if cannot parse the document' do
          stub_request(:get, 'https://www.bna.com.ar/Personas').to_return body: 'some invalid html'
          expect { subject.fetch_rates }.to raise_error Errors::APIError
        end

        def fixture file
          File.read("#{__dir__}/fixtures/bna/#{file}")
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
danconia-0.3.0 spec/danconia/exchanges/bna_spec.rb