-
Notifications
You must be signed in to change notification settings - Fork 474
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
Provide Scopes value object to encapsulate scope operations #829
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks solid!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Couple of nitpicks only.
test/api_access_test.rb
Outdated
# frozen_string_literal: true | ||
require 'test_helper' | ||
|
||
class ScopesTest < Minitest::Test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: should this class be named ApiAccessTest
?
test/api_access_test.rb
Outdated
end | ||
|
||
def test_to_a_outputs_scopes_as_an_array_of_strings_without_implied_read_scopes | ||
serialized_scopes = %w(read_products write_orders) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can either be a string or an array of scopes so that we can support two types of inputs when instantiating ApiAccess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just wondering if it made sense for serialized_scopes
to be an array - I thought the tests was slightly off in that but it seems like it's just the variable name that is ''''wrong''''. No reason to change it 🙂
It's sort of hard to picture what the big picture is with this change. Would it make sense to update the description to show a preview of how we could use this new feature in |
b0268b8
to
e37e892
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small change to the test relying on the order of the elements from to_a
.
test/api_access_test.rb
Outdated
serialized_read_products_write_orders = %w(read_products write_orders) | ||
read_products_write_orders = ShopifyAPI::ApiAccess.new(%w(read_products read_orders write_orders)) | ||
|
||
assert_equal read_products_write_orders.to_a, serialized_read_products_write_orders |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assert assumes the order of the elements. ApiAccess operates as a set, the order of the array can not be guaranteed.
There is no built in minitest assert for this, adding .sort
to the end of each array will reorder the arrays before checking equality.
e37e892
to
2d30f4d
Compare
This is a follow up on our discussion: Shopify/omniauth-shopify-oauth2#96 (comment)
What does this PR solve?
There are common operations that are used for scopes on OmniAuth and apps consuming the gem. Such operations include serializing, deserializing and normalizing scopes. This PR introduces the
Scopes
value object that will be used to perform such operations. This helps ensure that apps do not potentially write duplicate code for scopes and delegating this responsibility to the Shopify OmniAuth gem.Examples of improvements
Simplifying valid scope checks
Before
After
Delegating check for whether scopes are mismatched or subset of another