2018-03-08 02:05:19 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-11-19 20:06:47 +01:00
|
|
|
require_relative "helper"
|
|
|
|
require "currency"
|
|
|
|
require "minitest/autorun"
|
2018-03-08 02:05:19 +01:00
|
|
|
|
|
|
|
describe Currency do
|
2024-11-19 20:06:47 +01:00
|
|
|
describe ".latest" do
|
|
|
|
it "returns latest rates" do
|
2018-10-03 15:48:30 +02:00
|
|
|
data = Currency.latest.all
|
2024-11-19 20:06:47 +01:00
|
|
|
_(data.count).must_be(:>, 1)
|
2018-03-08 02:05:19 +01:00
|
|
|
end
|
2018-10-03 15:48:30 +02:00
|
|
|
end
|
2018-03-08 02:05:19 +01:00
|
|
|
|
2024-11-19 20:06:47 +01:00
|
|
|
describe ".between" do
|
2018-10-03 15:48:30 +02:00
|
|
|
let(:day) do
|
2024-11-19 20:06:47 +01:00
|
|
|
Date.parse("2010-01-01")
|
2018-07-05 21:19:37 +02:00
|
|
|
end
|
2018-03-08 02:05:19 +01:00
|
|
|
|
2024-11-19 20:06:47 +01:00
|
|
|
it "returns everything up to a year" do
|
2020-05-02 16:18:52 +02:00
|
|
|
interval = day..day + 365
|
2024-11-19 20:06:47 +01:00
|
|
|
_(Currency.between(interval).map(:date).uniq.count).must_be(:>, 52)
|
2018-07-05 21:19:37 +02:00
|
|
|
end
|
2018-03-08 02:05:19 +01:00
|
|
|
|
2024-11-19 20:06:47 +01:00
|
|
|
it "samples weekly over a year" do
|
2020-05-02 16:18:52 +02:00
|
|
|
interval = day..day + 366
|
2024-11-19 20:06:47 +01:00
|
|
|
_(Currency.between(interval).map(:date).uniq.count).must_be(:<, 54)
|
2018-07-05 21:19:37 +02:00
|
|
|
end
|
2018-03-08 02:05:19 +01:00
|
|
|
|
2024-11-19 20:06:47 +01:00
|
|
|
it "sorts by date when sampling" do
|
2020-05-02 19:34:38 +02:00
|
|
|
interval = day..day + 366
|
2018-10-03 15:48:30 +02:00
|
|
|
dates = Currency.between(interval).map(:date)
|
2024-11-19 20:06:47 +01:00
|
|
|
_(dates).must_equal(dates.sort)
|
2018-07-05 21:19:37 +02:00
|
|
|
end
|
2018-10-03 15:48:30 +02:00
|
|
|
end
|
2018-07-05 21:19:37 +02:00
|
|
|
|
2024-11-19 20:06:47 +01:00
|
|
|
describe ".only" do
|
|
|
|
it "filters symbols" do
|
|
|
|
iso_codes = ["CAD", "USD"]
|
2018-10-03 15:48:30 +02:00
|
|
|
data = Currency.latest.only(*iso_codes).all
|
2024-11-19 20:06:47 +01:00
|
|
|
_(data.map(&:iso_code).sort).must_equal(iso_codes)
|
2018-07-05 21:19:37 +02:00
|
|
|
end
|
|
|
|
|
2024-11-19 20:06:47 +01:00
|
|
|
it "returns nothing if no matches" do
|
|
|
|
_(Currency.only("FOO").all).must_be_empty
|
2018-07-05 21:19:37 +02:00
|
|
|
end
|
2018-03-08 02:05:19 +01:00
|
|
|
end
|
|
|
|
end
|