Skip to content

Commit 447b66c

Browse files
committed
Address code review comments
1 parent 3f0c967 commit 447b66c

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

lib/shopify_api/auth/session.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def expired?
4848

4949
sig { returns(T::Boolean) }
5050
def refresh_token_expired?
51-
@refresh_token_expires ? @refresh_token_expires < Time.now : false
51+
@refresh_token_expires ? @refresh_token_expires < Time.now + 60 : false
5252
end
5353

5454
sig do

test/auth/session_test.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ def test_expired_with_passed_expiry_date
5555
def test_refresh_token_expired_with_no_expiry_date
5656
session = ShopifyAPI::Auth::Session.new(shop: "test-shop", refresh_token_expires: nil)
5757

58-
assert_equal(false, session.refresh_token_expired?)
58+
refute(session.refresh_token_expired?)
5959
end
6060

6161
def test_refresh_token_expired_with_future_expiry_date
6262
session = ShopifyAPI::Auth::Session.new(shop: "test-shop", refresh_token_expires: Time.now + 1 * 60 * 60)
6363

64-
assert_equal(false, session.refresh_token_expired?)
64+
refute(session.refresh_token_expired?)
6565
end
6666

6767
def test_refresh_token_expired_with_passed_expiry_date
@@ -70,6 +70,18 @@ def test_refresh_token_expired_with_passed_expiry_date
7070
assert(session.refresh_token_expired?)
7171
end
7272

73+
def test_refresh_token_expiring_within_buffer
74+
session = ShopifyAPI::Auth::Session.new(shop: "test-shop", refresh_token_expires: Time.now + 59)
75+
76+
assert(session.refresh_token_expired?)
77+
end
78+
79+
def test_refresh_token_expiring_immediately_before_buffer
80+
session = ShopifyAPI::Auth::Session.new(shop: "test-shop", refresh_token_expires: Time.now + 61)
81+
82+
refute(session.refresh_token_expired?)
83+
end
84+
7385
def test_temp
7486
session = ShopifyAPI::Auth::Session.new(shop: "test-shop1", access_token: "token1")
7587

test/test_helper.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@ def modify_context(
8888
response_as_struct: response_as_struct || ShopifyAPI::Context.response_as_struct,
8989
api_host: api_host || ShopifyAPI::Context.api_host,
9090
expiring_offline_access_tokens:
91-
expiring_offline_access_tokens || ShopifyAPI::Context.expiring_offline_access_tokens,
91+
if !expiring_offline_access_tokens.nil?
92+
expiring_offline_access_tokens
93+
else
94+
ShopifyAPI::Context.expiring_offline_access_tokens
95+
end,
9296
)
9397
end
9498
end

0 commit comments

Comments
 (0)