# 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
1USD2568.722594.412581.5724-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
1USD2568.722594.412581.5724-Mar-26
2GOLD1000.002000.001500.0024-Mar-26
3ATS100.00200.00150.0024-Mar-26
4NLG100.00200.00150.0024-Mar-26
5MZM100.00200.00150.0024-Mar-26
6ZWD100.00200.00150.0024-Mar-26
7CUC100.00200.00150.0024-Mar-26
8EUR2950.952980.462965.7024-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
1GOLD11,759,124.7911,876,716.0411,817,920.4224-Mar-26
2JPY17.123417.294617.209024-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