# frozen_string_literal: true require_relative "../../helper" require "provider/adapters/lb" class Provider < Sequel::Model(:providers) module Adapters describe LB do before do VCR.insert_cassette("lb", match_requests_on: [:method, :host]) end after { VCR.eject_cassette } let(:adapter) { LB.new } it "fetches pre-EUR rates" do dataset = adapter.fetch(after: Date.new(2014, 12, 29), upto: Date.new(2014, 12, 31)) _(dataset).wont_be_empty _(dataset.first[:quote]).must_equal("LTL") end it "fetches multiple currencies per date" do dataset = adapter.fetch(after: Date.new(2014, 12, 29), upto: Date.new(2014, 12, 31)) dates = dataset.map { |r| r[:date] }.uniq sample = dataset.select { |r| r[:date] == dates.first } _(sample.size).must_be(:>, 1) end it "parses LT-type XML with correct base and quote" do xml = <<~XML LT
2014-12-30
LTL 7.6881 AED 10
XML records = adapter.parse(xml) _(records.length).must_equal(1) _(records.first[:base]).must_equal("AED") _(records.first[:quote]).must_equal("LTL") _(records.first[:rate]).must_be_close_to(0.76881, 0.00001) _(records.first[:date]).must_equal(Date.new(2014, 12, 30)) end it "parses EU-type XML with correct base and quote" do xml = <<~XML EU
2025-03-17
EUR 1 AUD 1.7160
XML records = adapter.parse(xml) _(records.length).must_equal(1) _(records.first[:base]).must_equal("EUR") _(records.first[:quote]).must_equal("AUD") _(records.first[:rate]).must_be_close_to(1.7160, 0.0001) _(records.first[:date]).must_equal(Date.new(2025, 3, 17)) end it "normalizes rate by quantity for LT type" do xml = <<~XML LT
2014-12-30
LTL 4.8611 AFN 100
XML records = adapter.parse(xml) _(records.first[:rate]).must_be_close_to(0.048611, 0.000001) end it "handles empty response" do xml = <<~XML XML records = adapter.parse(xml) _(records).must_be_empty end end end end