Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alanhill committed Jul 18, 2017
1 parent 79bbb27 commit 6b6152e
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .byebug_history
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
exit
config[:inline].present?
config[:job].present?
config
next
2 changes: 1 addition & 1 deletion lib/shopify_app/sessions_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def return_address
def perform_after_authenticate_job
config = ShopifyApp.configuration.after_authenticate_job

return unless config && config[:job].present? && config[:inline].present?
return unless config && config[:job].present? && config[:inline].in?([true, false])

if config[:inline]
config[:job].perform_now(shop_domain: session[:shopify_domain])
Expand Down
51 changes: 51 additions & 0 deletions test/controllers/sessions_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
require 'test_helper'

module Shopify
class AfterAuthenticateJob < ActiveJob::Base
def perform; end
end
end

module ShopifyApp
class SessionsControllerTest < ActionController::TestCase

Expand Down Expand Up @@ -149,6 +155,51 @@ class SessionsControllerTest < ActionController::TestCase
assert_equal 'Cerrar sesión', flash[:notice]
end

test "#callback calls #perform_after_authenticate_job and performs inline when inline is true" do
ShopifyApp.configure do |config|
config.after_authenticate_job = { job: Shopify::AfterAuthenticateJob, inline: true }
end

Shopify::AfterAuthenticateJob.expects(:perform_now)

mock_shopify_omniauth
get :callback, params: { shop: 'shop' }
end

test "#callback calls #perform_after_authenticate_job and performs asynchronous when inline is false" do
ShopifyApp.configure do |config|
config.after_authenticate_job = { job: Shopify::AfterAuthenticateJob, inline: false }
end

Shopify::AfterAuthenticateJob.expects(:perform_later)

mock_shopify_omniauth
get :callback, params: { shop: 'shop' }
end

test "#callback doesn't call #perform_after_authenticate_job if job is nil" do
ShopifyApp.configure do |config|
config.after_authenticate_job = { job: nil, inline: false }
end

Shopify::AfterAuthenticateJob.expects(:perform_later).never

mock_shopify_omniauth
get :callback, params: { shop: 'shop' }
end

test "#callback doesn't call #perform_after_authenticate_job if inline is nil" do
ShopifyApp.configure do |config|
config.after_authenticate_job = { job: Shopify::AfterAuthenticateJob, inline: nil }
end

Shopify::AfterAuthenticateJob.expects(:perform_later).never
Shopify::AfterAuthenticateJob.expects(:perform_now).never

mock_shopify_omniauth
get :callback, params: { shop: 'shop' }
end

private

def mock_shopify_omniauth
Expand Down

0 comments on commit 6b6152e

Please sign in to comment.