# frozen_string_literal: true
require_relative "../../helper"
require "provider/adapters/bota"
class Provider < Sequel::Model(:providers)
module Adapters
describe BOTA do
before do
VCR.insert_cassette("bota", match_requests_on: [:method, :host])
end
after { VCR.eject_cassette }
let(:adapter) { BOTA.new }
it "fetches rates with date range" do
dataset = adapter.fetch(after: Date.new(2026, 3, 24), upto: Date.new(2026, 3, 28))
_(dataset).wont_be_empty
end
it "fetches multiple currencies per date" do
dataset = adapter.fetch(after: Date.new(2026, 3, 24), upto: Date.new(2026, 3, 28))
dates = dataset.map { |r| r[:date] }.uniq
sample = dataset.select { |r| r[:date] == dates.first }
_(sample.size).must_be(:>, 1)
end
it "parses HTML table with correct base and quote" do
html = <<~HTML
| 1 | USD | 2568.72 | 2594.41 | 2581.57 | 24-Mar-26 |
HTML
records = adapter.parse(html)
_(records.length).must_equal(1)
_(records.first[:base]).must_equal("USD")
_(records.first[:quote]).must_equal("TZS")
_(records.first[:rate]).must_equal(2581.57)
_(records.first[:date]).must_equal(Date.new(2026, 3, 24))
end
it "excludes GOLD and defunct currencies" do
html = <<~HTML
| 1 | USD | 2568.72 | 2594.41 | 2581.57 | 24-Mar-26 |
| 2 | GOLD | 1000.00 | 2000.00 | 1500.00 | 24-Mar-26 |
| 3 | ATS | 100.00 | 200.00 | 150.00 | 24-Mar-26 |
| 4 | NLG | 100.00 | 200.00 | 150.00 | 24-Mar-26 |
| 5 | MZM | 100.00 | 200.00 | 150.00 | 24-Mar-26 |
| 6 | ZWD | 100.00 | 200.00 | 150.00 | 24-Mar-26 |
| 7 | CUC | 100.00 | 200.00 | 150.00 | 24-Mar-26 |
| 8 | EUR | 2950.95 | 2980.46 | 2965.70 | 24-Mar-26 |
HTML
records = adapter.parse(html)
currencies = records.map { |r| r[:base] }
_(currencies).must_include("USD")
_(currencies).must_include("EUR")
_(currencies).wont_include("GOLD")
_(currencies).wont_include("ATS")
_(currencies).wont_include("NLG")
_(currencies).wont_include("MZM")
_(currencies).wont_include("ZWD")
_(currencies).wont_include("CUC")
_(records.length).must_equal(2)
end
it "handles rates with commas in numbers" do
html = <<~HTML
| 1 | GOLD | 11,759,124.79 | 11,876,716.04 | 11,817,920.42 | 24-Mar-26 |
| 2 | JPY | 17.1234 | 17.2946 | 17.2090 | 24-Mar-26 |
HTML
records = adapter.parse(html)
# GOLD is excluded
_(records.length).must_equal(1)
_(records.first[:base]).must_equal("JPY")
_(records.first[:rate]).must_equal(17.209)
end
end
end
end