Skip to content

Commit

Permalink
Merge pull request #1244 from Shopify/session-expired-method
Browse files Browse the repository at this point in the history
Add expired? method to check if session is expired
  • Loading branch information
gbzodek committed Nov 24, 2023
2 parents 6c2a45f + aa6a151 commit 459b04e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Note: For changes to the API, see https://shopify.dev/changelog?filter=api

## Unreleased

- [#1244](https://github.com/Shopify/shopify-api-ruby/pull/1244) Add `expired?` to `ShopifyAPI::Auth::Session` to check if the session is expired (mainly for user sessions)

## 13.3.0

- [#1241](https://github.com/Shopify/shopify-api-ruby/pull/1241) Add `api_host` to `ShopifyAPI::Context.setup`, allowing the API host to be overridden in `ShopifyAPI::Clients::HttpClient`. This context option is intended for internal Shopify use only.
Expand Down
5 changes: 5 additions & 0 deletions lib/shopify_api/auth/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ def online?
@is_online
end

sig { returns(T::Boolean) }
def expired?
@expires ? @expires < Time.now : false
end

sig do
params(
shop: String,
Expand Down
18 changes: 18 additions & 0 deletions test/auth/session_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,24 @@ def test_is_online_with_associated_user
assert(session.online?)
end

def test_expired_with_no_expiry_date
session = ShopifyAPI::Auth::Session.new(shop: "test-shop")

assert_equal(false, session.expired?)
end

def test_expired_with_future_expiry_date
session = ShopifyAPI::Auth::Session.new(shop: "test-shop", expires: Time.now + 1 * 60 * 60)

assert_equal(false, session.expired?)
end

def test_expired_with_passed_expiry_date
session = ShopifyAPI::Auth::Session.new(shop: "test-shop", expires: Time.now - 1)

assert(session.expired?)
end

def test_temp
session = ShopifyAPI::Auth::Session.new(shop: "test-shop1", access_token: "token1")

Expand Down

0 comments on commit 459b04e

Please sign in to comment.