Sha256: 985aee8ef9cd01377ba9c75b516a66189aac6db531ebc8648ee800220a7bbedc

Contents?: true

Size: 1.75 KB

Versions: 2

Compression:

Stored size: 1.75 KB

Contents

require 'test_helper'

class TestSessionStore
  attr_reader :storage
  def initialize
    @storage = []
  end

  def retrieve(id)
    storage[id]
  end

  def store(session)
    id = storage.length
    storage[id] = session
    id
  end
end

class TestSessionStoreClass
  def self.store(session)
  end

  def self.retrieve(id)
  end
end

class ShopifySessionRepositoryTest < Minitest::Test
  attr_reader :session_store, :session
  def setup
    @session_store = TestSessionStore.new
    @session = ShopifyAPI::Session.new('shop.myshopify.com', 'abracadabra')
    ShopifySessionRepository.storage = session_store
  end

  def teardown
    ShopifySessionRepository.storage = nil
  end

  def test_adding_a_session_to_the_repository
    assert_equal 0, ShopifySessionRepository.store(session)
    assert_equal session, session_store.retrieve(0)
  end

  def test_retrieving_a_session_from_the_repository
    session_store.storage[9] = session
    assert_equal session, ShopifySessionRepository.retrieve(9)
  end

  def test_retrieving_a_session_for_an_id_that_does_not_exist
    ShopifySessionRepository.store(session)
    assert !ShopifySessionRepository.retrieve(100), "The session with id 100 should not exist in the Repository"
  end

  def test_retrieving_a_session_for_a_misconfigured_shops_repository
    ShopifySessionRepository.storage = nil
    assert_raises ShopifySessionRepository::ConfigurationError do
      ShopifySessionRepository.retrieve(0)
    end

    assert_raises ShopifySessionRepository::ConfigurationError do
      ShopifySessionRepository.store(session)
    end
  end

  def test_accepts_a_string_and_constantizes_it
    ShopifySessionRepository.storage = 'TestSessionStoreClass'
    assert_equal TestSessionStoreClass, ShopifySessionRepository.storage
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
shopify_app-5.0.2 test/lib/shopify_app/shopify_session_repository_test.rb
shopify_app-5.0.1 test/lib/shopify_app/shopify_session_repository_test.rb