2018-03-08 02:05:19 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require_relative 'helper'
|
|
|
|
require 'query'
|
|
|
|
|
|
|
|
describe Query do
|
2020-05-02 16:14:47 +02:00
|
|
|
it 'builds a query hash' do
|
2020-05-02 18:08:47 +02:00
|
|
|
_(Query.build(date: '2014-01-01')).must_be_kind_of Hash
|
2020-05-02 16:14:47 +02:00
|
|
|
end
|
|
|
|
|
2018-03-08 02:05:19 +01:00
|
|
|
it 'returns given amount' do
|
|
|
|
query = Query.new(amount: '100')
|
2020-05-02 18:08:47 +02:00
|
|
|
_(query.amount).must_equal 100.0
|
2018-03-08 02:05:19 +01:00
|
|
|
end
|
|
|
|
|
2018-07-05 21:19:37 +02: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
|
|
|
|
|
|
|
|
it 'returns given base' do
|
|
|
|
query = Query.new(base: 'USD')
|
2020-05-02 18:08:47 +02:00
|
|
|
_(query.base).must_equal 'USD'
|
2018-03-08 02:05:19 +01:00
|
|
|
end
|
|
|
|
|
2018-09-18 13:56:11 +02:00
|
|
|
it 'upcases given base' do
|
|
|
|
query = Query.new(base: 'usd')
|
2020-05-02 18:08:47 +02:00
|
|
|
_(query.base).must_equal 'USD'
|
2018-09-18 13:56:11 +02:00
|
|
|
end
|
|
|
|
|
2018-03-08 02:05:19 +01:00
|
|
|
it 'defaults base to nothing' do
|
|
|
|
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
|
|
|
|
|
2018-07-05 21:19:37 +02:00
|
|
|
it 'aliases base with from' do
|
2018-03-08 02:05:19 +01:00
|
|
|
query = Query.new(from: 'USD')
|
2020-05-02 18:08:47 +02:00
|
|
|
_(query.base).must_equal 'USD'
|
2018-03-08 02:05:19 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns given symbols' do
|
|
|
|
query = Query.new(symbols: 'USD,GBP')
|
2020-05-02 18:08:47 +02:00
|
|
|
_(query.symbols).must_equal %w[USD GBP]
|
2018-03-08 02:05:19 +01:00
|
|
|
end
|
|
|
|
|
2018-09-18 13:56:11 +02:00
|
|
|
it 'upcases given symbols' do
|
|
|
|
query = Query.new(symbols: 'usd,gbp')
|
2020-05-02 18:08:47 +02:00
|
|
|
_(query.symbols).must_equal %w[USD GBP]
|
2018-09-18 13:56:11 +02:00
|
|
|
end
|
|
|
|
|
2018-07-05 21:19:37 +02:00
|
|
|
it 'aliases symbols with to' do
|
2018-03-08 02:05:19 +01:00
|
|
|
query = Query.new(to: 'USD')
|
2020-05-02 18:08:47 +02:00
|
|
|
_(query.symbols).must_equal ['USD']
|
2018-03-08 02:05:19 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'defaults symbols to nothing' do
|
|
|
|
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
|
|
|
|
|
|
|
|
it 'returns given date' do
|
2018-07-05 21:19:37 +02:00
|
|
|
date = '2014-01-01'
|
|
|
|
query = Query.new(date: date)
|
2020-05-02 18:08:47 +02:00
|
|
|
_(query.date).must_equal Date.parse(date)
|
2018-03-08 02:05:19 +01:00
|
|
|
end
|
|
|
|
|
2018-07-05 21:19:37 +02:00
|
|
|
it 'returns given date interval' do
|
|
|
|
start_date = '2014-01-01'
|
|
|
|
end_date = '2014-12-31'
|
|
|
|
query = Query.new(start_date: start_date, end_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
|