frankfurter/spec/edge_cases_spec.rb

52 lines
1.0 KiB
Ruby
Raw Normal View History

2016-10-11 17:54:28 +02:00
# frozen_string_literal: true
2017-06-14 22:16:21 +02:00
2014-05-16 21:35:16 +02:00
require_relative 'helper'
require 'rack/test'
2018-04-16 17:19:15 +02:00
require 'web/server'
2014-05-16 21:35:16 +02:00
describe 'the server' do
2014-05-16 21:35:16 +02:00
include Rack::Test::Methods
let(:app) { Web::Server.freeze }
2018-03-09 01:01:08 +01:00
def json
Oj.load(last_response.body)
end
2014-05-16 21:35:16 +02:00
it 'handles unfound pages' do
2014-07-08 16:38:40 +02:00
get '/foo'
2020-05-02 18:08:47 +02:00
_(last_response.status).must_equal 404
2014-05-16 21:35:16 +02:00
end
it 'will not process an invalid date' do
get '/2010-31-01'
2020-05-02 18:08:47 +02:00
_(last_response).must_be :unprocessable?
2014-05-16 21:35:16 +02:00
end
it 'will not process a date before 2000' do
get '/1999-01-01'
2020-05-02 18:08:47 +02:00
_(last_response).must_be :not_found?
2014-05-16 21:35:16 +02:00
end
it 'will not process an unavailable base' do
2014-05-16 21:35:16 +02:00
get '/latest?base=UAH'
2020-05-02 18:08:47 +02:00
_(last_response).must_be :not_found?
2016-10-12 00:37:29 +02:00
end
it 'handles malformed queries' do
2015-09-15 13:01:35 +02:00
get '/latest?base=USD?callback=?'
2020-05-02 18:08:47 +02:00
_(last_response).must_be :not_found?
end
2015-09-15 13:02:49 +02:00
2018-03-09 01:01:08 +01:00
it 'does not return stale dates' do
Day.db.transaction do
2015-09-15 13:02:49 +02:00
get '/latest'
2018-03-09 01:01:08 +01:00
date = json['date']
Day.latest.delete
2018-03-09 01:01:08 +01:00
get '/latest'
2020-05-02 18:08:47 +02:00
_(json['date']).wont_equal date
2015-09-15 13:02:49 +02:00
raise Sequel::Rollback
end
end
2014-05-16 21:35:16 +02:00
end