Sha256: 71ba3fc0dee6e95ca1a0f03762899011948f297a2f6e6866c945e50205e6fb6f

Contents?: true

Size: 1006 Bytes

Versions: 3

Compression:

Stored size: 1006 Bytes

Contents

# frozen_string_literal: true

require 'json'
require 'money/bank/open_exchange_rates_bank'

ERROR_MSG = 'Integration test failed!'
cache_path = '/tmp/latest.json'
to_currency = 'CAD'
app_id = ENV['OXR_APP_ID']

if app_id.nil? || app_id.empty?
  puts 'OXR_APP_ID env var not set skipping integration tests'
  exit 0
end

begin
  puts 'OXR version', Money::Bank::OpenExchangeRatesBank::VERSION

  oxr = Money::Bank::OpenExchangeRatesBank.new
  oxr.cache = cache_path
  oxr.app_id = app_id
  oxr.update_rates
  oxr.save_rates

  Money.default_bank = oxr

  cad_rate = Money.default_bank.get_rate('USD', to_currency)

  json_to_currency = JSON.parse(File.read(cache_path))['rates'][to_currency]
  puts 'JSON to_currency', json_to_currency
  puts 'Money to_currency', cad_rate
  # rubocop:disable Style/AndOr
  json_to_currency == cad_rate or raise ERROR_MSG
  # rubocop:enable Style/AndOr
  # rubocop:disable Style/RescueStandardError
rescue
  # rubocop:enable Style/RescueStandardError
  raise ERROR_MSG
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
money-open-exchange-rates-1.4.2 test/integration/api.rb
money-open-exchange-rates-1.4.1 test/integration/api.rb
money-open-exchange-rates-1.4.0 test/integration/api.rb