Skip to content

Commit

Permalink
Handle valid? check for access_scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
rezaansyed committed Feb 23, 2021
1 parent f254346 commit 4aab6ef
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/shopify_api/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def api_version=(version)
end

def valid?
domain.present? && token.present? && api_version.is_a?(ApiVersion)
domain.present? && token.present? && api_version.is_a?(ApiVersion) && valid_access_scopes?
end

def expires_in
Expand Down Expand Up @@ -181,6 +181,10 @@ def state

private

def valid_access_scopes?
access_scopes.nil? || access_scopes.is_a?(ShopifyAPI::ApiAccess)
end

def access_scopes=(access_scopes)
return unless access_scopes
@access_scopes = ShopifyAPI::ApiAccess.new(access_scopes)
Expand Down
33 changes: 33 additions & 0 deletions test/session_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,39 @@ def setup
assert(session.valid?)
end

test "be valid with nil access_scopes" do
session = ShopifyAPI::Session.new(
domain: "testshop.myshopify.com",
token: "any-token",
api_version: any_api_version,
access_scopes: nil
)

assert(session.valid?)
end

test "be valid with string of access_scopes" do
session = ShopifyAPI::Session.new(
domain: "testshop.myshopify.com",
token: "any-token",
api_version: any_api_version,
access_scopes: "read_products, write_orders"
)

assert(session.valid?)
end

test "be valid with a collection of access_scopes" do
session = ShopifyAPI::Session.new(
domain: "testshop.myshopify.com",
token: "any-token",
api_version: any_api_version,
access_scopes: %w(read_products write_orders)
)

assert(session.valid?)
end

test "not raise error without params" do
assert_nothing_raised do
ShopifyAPI::Session.new(domain: "testshop.myshopify.com", token: "any-token", api_version: any_api_version)
Expand Down

0 comments on commit 4aab6ef

Please sign in to comment.