Sha256: 0692b0eec1015881ba63c8438291df2d6639a7075e202355ead0b1e81494d776
Contents?: true
Size: 1.79 KB
Versions: 4
Compression:
Stored size: 1.79 KB
Contents
require_relative "../test_helper" class TokenCacheTest < SequelTestCase def setup @cache = Underway::TokenCache.new(Underway::DB.instance.database) end def test_can_store_and_retrieve_a_token Timecop.freeze(DateTime.parse("2018-02-12T09:00:00+00:00")) do @cache.store_installation_auth_token( id: 1, token: "some-token", expires_at: "2018-02-12T10:00:00Z" ) assert_equal "some-token", @cache.lookup_installation_auth_token(id: 1) end end def test_retrieves_the_newest_token Timecop.freeze(DateTime.parse("2018-02-12T09:00:00+00:00")) do @cache.store_installation_auth_token( id: 1, token: "first-token", expires_at: "2018-02-12T10:00:00Z" ) @cache.store_installation_auth_token( id: 1, token: "second-token", expires_at: "2018-02-12T11:00:00Z" ) assert_equal "second-token", @cache.lookup_installation_auth_token(id: 1) end end def test_returns_nil_when_looking_up_a_token_that_does_not_exist assert_nil @cache.lookup_installation_auth_token(id: "non-existent") end def test_returns_nil_for_tokens_that_have_expired Timecop.freeze(DateTime.parse("2018-02-12T09:00:00+00:00")) do @cache.store_installation_auth_token( id: 1, token: "some-token", expires_at: "2018-02-12T08:00:00Z" ) assert_nil @cache.lookup_installation_auth_token(id: 1) end end def test_retrieves_a_token_when_the_expiry_is_equal_to_now Timecop.freeze(DateTime.parse("2018-02-12T09:00:00+00:00")) do @cache.store_installation_auth_token( id: 1, token: "some-token", expires_at: "2018-02-12T09:00:00Z" ) assert_equal "some-token", @cache.lookup_installation_auth_token(id: 1) end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
underway-2.0.0 | test/lib/token_cache_test.rb |
underway-1.1.0 | test/lib/token_cache_test.rb |
underway-1.0.1 | test/lib/token_cache_test.rb |
underway-1.0.0 | test/lib/token_cache_test.rb |