2018-03-08 02:05:19 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-11-19 20:06:47 +01:00
|
|
|
require_relative "helper"
|
|
|
|
require "query"
|
2018-03-08 02:05:19 +01:00
|
|
|
|
|
|
|
describe Query do
|
2024-11-19 20:06:47 +01:00
|
|
|
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
|
|
|
|
|
2024-11-19 20:06:47 +01:00
|
|
|
it "returns given amount" do
|
|
|
|
query = Query.new(amount: "100")
|
|
|
|
_(query.amount).must_equal(100.0)
|
2018-03-08 02:05:19 +01:00
|
|
|
end
|
|
|
|
|
2024-11-19 20:06:47 +01:00
|
|
|
it "defaults amount to nothing" do
|
2018-03-08 02:05:19 +01:00
|
|
|
query = Query.new
|
2020-05-02 18:08:47 +02:00
|
|
|
_(query.amount).must_be_nil
|
2018-03-08 02:05:19 +01:00
|
|
|
end
|
|
|
|
|
2024-11-19 20:06:47 +01:00
|
|
|
it "returns given base" do
|
|
|
|
query = Query.new(base: "USD")
|
|
|
|
_(query.base).must_equal("USD")
|
2018-03-08 02:05:19 +01:00
|
|
|
end
|
|
|
|
|
2024-11-19 20:06:47 +01:00
|
|
|
it "upcases given base" do
|
|
|
|
query = Query.new(base: "usd")
|
|
|
|
_(query.base).must_equal("USD")
|
2018-09-18 13:56:11 +02:00
|
|
|
end
|
|
|
|
|
2024-11-19 20:06:47 +01:00
|
|
|
it "defaults base to nothing" do
|
2018-03-08 02:05:19 +01:00
|
|
|
query = Query.new
|
2020-05-02 18:08:47 +02:00
|
|
|
_(query.base).must_be_nil
|
2018-03-08 02:05:19 +01:00
|
|
|
end
|
|
|
|
|
2024-11-19 20:06:47 +01:00
|
|
|
it "aliases base with from" do
|
|
|
|
query = Query.new(from: "USD")
|
|
|
|
_(query.base).must_equal("USD")
|
2018-03-08 02:05:19 +01:00
|
|
|
end
|
|
|
|
|
2024-11-19 20:06:47 +01:00
|
|
|
it "returns given symbols" do
|
|
|
|
query = Query.new(symbols: "USD,GBP")
|
|
|
|
_(query.symbols).must_equal(["USD", "GBP"])
|
2018-03-08 02:05:19 +01:00
|
|
|
end
|
|
|
|
|
2024-11-19 20:06:47 +01:00
|
|
|
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
|
|
|
|
|
2024-11-19 20:06:47 +01:00
|
|
|
it "aliases symbols with to" do
|
|
|
|
query = Query.new(to: "USD")
|
|
|
|
_(query.symbols).must_equal(["USD"])
|
2018-03-08 02:05:19 +01:00
|
|
|
end
|
|
|
|
|
2024-11-19 20:06:47 +01:00
|
|
|
it "defaults symbols to nothing" do
|
2018-03-08 02:05:19 +01:00
|
|
|
query = Query.new
|
2020-05-02 18:08:47 +02:00
|
|
|
_(query.symbols).must_be_nil
|
2018-03-08 02:05:19 +01:00
|
|
|
end
|
|
|
|
|
2024-11-19 20:06:47 +01:00
|
|
|
it "returns given date" do
|
|
|
|
date = "2014-01-01"
|
2023-02-28 17:49:48 +01:00
|
|
|
query = Query.new(date:)
|
2024-11-19 20:06:47 +01:00
|
|
|
_(query.date).must_equal(Date.parse(date))
|
2018-03-08 02:05:19 +01:00
|
|
|
end
|
|
|
|
|
2024-11-19 20:06:47 +01:00
|
|
|
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)))
|
2018-03-08 02:05:19 +01:00
|
|
|
end
|
|
|
|
end
|