frankfurter/spec/query_spec.rb

74 lines
1.6 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
require_relative "helper"
require "query"
describe Query do
it "builds a query hash" do
_(Query.build(date: "2014-01-01")).must_be_kind_of(Hash)
2020-05-02 16:14:47 +02:00
end
it "returns given amount" do
query = Query.new(amount: "100")
_(query.amount).must_equal(100.0)
end
it "defaults amount to nothing" do
query = Query.new
2020-05-02 18:08:47 +02:00
_(query.amount).must_be_nil
end
it "returns given base" do
query = Query.new(base: "USD")
_(query.base).must_equal("USD")
end
it "upcases given base" do
query = Query.new(base: "usd")
_(query.base).must_equal("USD")
2018-09-18 13:56:11 +02:00
end
it "defaults base to nothing" do
query = Query.new
2020-05-02 18:08:47 +02:00
_(query.base).must_be_nil
end
it "aliases base with from" do
query = Query.new(from: "USD")
_(query.base).must_equal("USD")
end
it "returns given symbols" do
query = Query.new(symbols: "USD,GBP")
_(query.symbols).must_equal(["USD", "GBP"])
end
it "upcases given symbols" do
query = Query.new(symbols: "usd,gbp")
_(query.symbols).must_equal(["USD", "GBP"])
2018-09-18 13:56:11 +02:00
end
it "aliases symbols with to" do
query = Query.new(to: "USD")
_(query.symbols).must_equal(["USD"])
end
it "defaults symbols to nothing" do
query = Query.new
2020-05-02 18:08:47 +02:00
_(query.symbols).must_be_nil
end
it "returns given date" do
date = "2014-01-01"
2023-02-28 17:49:48 +01:00
query = Query.new(date:)
_(query.date).must_equal(Date.parse(date))
end
it "returns given date interval" do
start_date = "2014-01-01"
end_date = "2014-12-31"
2023-02-28 17:49:48 +01:00
query = Query.new(start_date:, end_date:)
2020-05-02 18:08:47 +02:00
_(query.date).must_equal((Date.parse(start_date)..Date.parse(end_date)))
end
end