Skip to content

Commit

Permalink
Throw error on bad input
Browse files Browse the repository at this point in the history
  • Loading branch information
rezaansyed committed Feb 23, 2021
1 parent 1da3feb commit f254346
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
15 changes: 5 additions & 10 deletions lib/shopify_api/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,6 @@ def api_version=(version)
end
end

def access_scopes=(access_scopes)
return unless access_scopes

@access_scopes = begin
ShopifyAPI::ApiAccess.new(access_scopes)
rescue
nil
end
end

def valid?
domain.present? && token.present? && api_version.is_a?(ApiVersion)
end
Expand Down Expand Up @@ -191,6 +181,11 @@ def state

private

def access_scopes=(access_scopes)
return unless access_scopes
@access_scopes = ShopifyAPI::ApiAccess.new(access_scopes)
end

def parameterize(params)
URI.escape(params.collect { |k, v| "#{k}=#{v}" }.join('&'))
end
Expand Down
17 changes: 9 additions & 8 deletions test/session_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,15 @@ def setup
assert_equal "read_products", session.access_scopes.to_s
end

test "set access_scopes to nil if bad access scopes are provided" do
session = ShopifyAPI::Session.new(
domain: "testshop.myshopify.com",
token: "any-token",
access_scopes: { bad_input: "bad_input" },
api_version: any_api_version
)
assert_nil session.access_scopes
test "session instantiation raises error if bad access scopes are provided" do
assert_raises do
ShopifyAPI::Session.new(
domain: "testshop.myshopify.com",
token: "any-token",
access_scopes: { bad_input: "bad_input" },
api_version: any_api_version
)
end
end

test "raise error if params passed but signature omitted" do
Expand Down

0 comments on commit f254346

Please sign in to comment.