Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug for SessionStorage#with_shopify_session #1488

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Unreleased
* Support Unified Admin [#1658](https://github.com/Shopify/shopify_app/pull/1658)
* Set `access_scopes` column to string by default [#1636](https://github.com/Shopify/shopify_app/pull/1636)
* Fixes a bug with `EnsureBilling` causing infinite redirect in embedded apps [#1578](https://github.com/Shopify/shopify_app/pull/1578)
* Modifies SessionStorage#with_shopify_session to call a block with a supplied session instance [#1488](https://github.com/Shopify/shopify_app/pull/1488)

21.4.1 (Feb 21, 2023)
----------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class AfterAuthenticateJob < ActiveJob::Base
def perform(shop_domain:)
shop = Shop.find_by(shopify_domain: shop_domain)

shop.with_shopify_session do
shop.with_shopify_session do |session|
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/shopify_app/session/session_storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ module SessionStorage
end

def with_shopify_session(&block)
ShopifyAPI::Auth::Session.temp(shop: shopify_domain, access_token: shopify_token) do
yield block
ShopifyAPI::Auth::Session.temp(shop: shopify_domain, access_token: shopify_token) do |session|
block.call(session)
end
end
end
Expand Down
27 changes: 27 additions & 0 deletions test/shopify_app/session/session_storage_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

require "test_helper"

module Shopify
class SessionStorageTest < ActiveSupport::TestCase
TEST_SHOPIFY_DOMAIN = "example.myshopify.com"
TEST_SHOPIFY_TOKEN = "1234567890abcdef"

test "#with_shopify_session should be supplied ShopifyAPI::Auth::Session in block argument" do
shop_mock = MockShopInstance.new(
shopify_domain: TEST_SHOPIFY_DOMAIN,
shopify_token: TEST_SHOPIFY_TOKEN,
)
shop_mock.class_eval do
include ActiveModel::Validations
include ShopifyApp::SessionStorage
end

shop_mock.with_shopify_session do |session|
assert_instance_of ShopifyAPI::Auth::Session, session
assert_equal TEST_SHOPIFY_DOMAIN, session.shop
assert_equal TEST_SHOPIFY_TOKEN, session.access_token
end
end
end
end