Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rezaansyed committed Jan 26, 2021
1 parent bcbaaa3 commit a8c0d6c
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/controllers/sessions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class SessionsControllerTest < ActionController::TestCase
@routes = ShopifyApp::Engine.routes
ShopifyApp::SessionRepository.shop_storage = ShopifyApp::InMemoryShopSessionStore
ShopifyApp.configuration = nil
ShopifyApp.configuration.allow_jwt_authentication = true
ShopifyApp.configuration.allow_cookie_authentication = false
ShopifyApp.configuration.embedded_app = true

I18n.locale = :en
Expand Down Expand Up @@ -149,6 +151,31 @@ class SessionsControllerTest < ActionController::TestCase
assert_match(/Shopify App — Installation/, response.body)
end

test "#new sets session[:user_tokens] to true if online tokens are expected" do
session[:shop_id] = 1
shop_session = ShopifyAPI::Session.new(
domain: 'my-shop',
token: '1234',
api_version: nil,
)
ShopifyApp::SessionRepository.user_storage.stubs(:present?).returns(true)
ShopifyApp::SessionRepository.stubs(:retrieve_shop_session).with(session[:shop_id]).returns(shop_session)

get :new, params: { shop: 'my-shop' }

assert session[:user_tokens]
end

test "#new sets session[:user_tokens] to false if there is no existing offline token" do
session[:shop_id] = 1
ShopifyApp::SessionRepository.user_storage.stubs(:present?).returns(true)
ShopifyApp::SessionRepository.stubs(:retrieve_shop_session).with(session[:shop_id]).returns(nil)

get :new, params: { shop: 'my-shop' }

refute session[:user_tokens]
end

['my-shop', 'my-shop.myshopify.com', 'https://my-shop.myshopify.com',
'http://my-shop.myshopify.com'].each do |good_url|
test "#create should authenticate the shop for the URL (#{good_url})" do
Expand Down

0 comments on commit a8c0d6c

Please sign in to comment.