Sha256: 1147eb9bc5982e3ed60427f828804c983e43ba388e08a8a8c7eb00f7144eba71
Contents?: true
Size: 1.85 KB
Versions: 9
Compression:
Stored size: 1.85 KB
Contents
require 'test_helper' require 'wovnrb/text_caches/cache_base' require 'wovnrb/text_caches/memory_cache' require 'wovnrb/api_data' require 'webmock/minitest' module Wovnrb class MemoryCacheTest < WovnMiniTest def setup Wovnrb::CacheBase.set_single({}) end def teardown Wovnrb::CacheBase.reset_cache WebMock.reset! end def test_initialize Wovnrb::ApiData.new('http://wwww.example.com', Wovnrb::Store.instance) end def test_get_data token = 'a' url = 'url' stub_request(:get, "https://api.wovn.io/v0/values?token=#{token}&url=#{url}"). to_return(:body => '{"test_body": "a"}') store = Wovnrb::Store.instance store.settings('user_token' => token) api_data = Wovnrb::ApiData.new(url, store) assert_equal({'test_body' => 'a'}, api_data.get_data) end def test_get_data_when_cache_exists token = 'a' url = 'url' stub = stub_request(:get, "https://api.wovn.io/v0/values?token=#{token}&url=#{url}"). to_return(:body => '{"test_body": "a"}') store = Wovnrb::Store.instance store.settings('user_token' => token) api_data = Wovnrb::ApiData.new(url, store) assert_equal({'test_body' => 'a'}, api_data.get_data) assert_equal({'test_body' => 'a'}, api_data.get_data) assert_requested(stub, :times => 1) end def test_get_data_fail token = 'a' url = 'url' stub_request(:get, "https://api.wovn.io/v0/values?token=#{token}&url=#{url}"). to_return(:status => [500, "Internal Server Error"]) store = Wovnrb::Store.instance store.settings('user_token' => token) api_data = Wovnrb::ApiData.new(url, store) log_mock = Wovnrb::LogMock.mock_log assert_equal({}, api_data.get_data) assert(log_mock.errors[0].start_with?('API server GET request failed')) end end end
Version data entries
9 entries across 9 versions & 1 rubygems