|
1 | 1 | require 'test_helper' |
2 | 2 |
|
| 3 | +module Shopify |
| 4 | + class AfterAuthenticateJob < ActiveJob::Base |
| 5 | + def perform; end |
| 6 | + end |
| 7 | +end |
| 8 | + |
3 | 9 | module ShopifyApp |
4 | 10 | class SessionsControllerTest < ActionController::TestCase |
5 | 11 |
|
@@ -140,6 +146,50 @@ class SessionsControllerTest < ActionController::TestCase |
140 | 146 | assert_equal 'Cerrar sesión', flash[:notice] |
141 | 147 | end |
142 | 148 |
|
| 149 | + test "#callback calls #perform_after_authenticate_job and performs inline when inline is true" do |
| 150 | + ShopifyApp.configure do |config| |
| 151 | + config.after_authenticate_job = { job: Shopify::AfterAuthenticateJob, inline: true } |
| 152 | + end |
| 153 | + |
| 154 | + Shopify::AfterAuthenticateJob.expects(:perform_now) |
| 155 | + |
| 156 | + mock_shopify_omniauth |
| 157 | + get :callback, params: { shop: 'shop' } |
| 158 | + end |
| 159 | + |
| 160 | + test "#callback calls #perform_after_authenticate_job and performs asynchronous when inline isn't true" do |
| 161 | + ShopifyApp.configure do |config| |
| 162 | + config.after_authenticate_job = { job: Shopify::AfterAuthenticateJob, inline: false } |
| 163 | + end |
| 164 | + |
| 165 | + Shopify::AfterAuthenticateJob.expects(:perform_later) |
| 166 | + |
| 167 | + mock_shopify_omniauth |
| 168 | + get :callback, params: { shop: 'shop' } |
| 169 | + end |
| 170 | + |
| 171 | + test "#callback doesn't call #perform_after_authenticate_job if job is nil" do |
| 172 | + ShopifyApp.configure do |config| |
| 173 | + config.after_authenticate_job = { job: nil, inline: false } |
| 174 | + end |
| 175 | + |
| 176 | + Shopify::AfterAuthenticateJob.expects(:perform_later).never |
| 177 | + |
| 178 | + mock_shopify_omniauth |
| 179 | + get :callback, params: { shop: 'shop' } |
| 180 | + end |
| 181 | + |
| 182 | + test "#callback calls #perform_after_authenticate_job and performs async if inline isn't present" do |
| 183 | + ShopifyApp.configure do |config| |
| 184 | + config.after_authenticate_job = { job: Shopify::AfterAuthenticateJob } |
| 185 | + end |
| 186 | + |
| 187 | + Shopify::AfterAuthenticateJob.expects(:perform_later) |
| 188 | + |
| 189 | + mock_shopify_omniauth |
| 190 | + get :callback, params: { shop: 'shop' } |
| 191 | + end |
| 192 | + |
143 | 193 | private |
144 | 194 |
|
145 | 195 | def mock_shopify_omniauth |
|
0 commit comments