Skip to content
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

Add after authenticate job option #432

Merged
merged 1 commit into from
Jul 19, 2017

Conversation

alanhill
Copy link
Contributor

What

Adds the ability to generate an after authenticate job which can perform async or inline once the shop has authenticated with the app.

Branch renamed from: #428 to better reflect the changes.

@Hammadk @kevinhughes27 ready for review again - made the config a hash accepting job and inline.


def init_after_authenticate_config
initializer = load_initializer
return if initializer.include?("config.webhooks")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need to return if they have have webhooks configured?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♂️ typo


inject_into_file(
'config/initializers/shopify_app.rb',
" config.after_authenticate_job = { job: Shopify::AfterAuthenticateJob, inline: false }\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would generate this without the inline arg since most people should use it as a job

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I see - its not really a default argument the way I was thinking of it. Maybe it is better to have here since otherwise it would only live in documentation. What are your thoughts @Hammadk

Copy link
Member

@Hammadk Hammadk Jul 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that we should keep inline: false around for documentation purposes

def perform_after_authenticate_job
return unless ShopifyApp.configuration.after_authenticate_job

job = ShopifyApp.configuration.after_authenticate_job[:job]
Copy link
Member

@Hammadk Hammadk Jul 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible for ShopifyApp.configuration.after_authenticate_job to be truthy, without a job set in ShopifyApp.configuration.after_authenticate_job[:job] ?

Copy link
Member

@Hammadk Hammadk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM other than the minor comment

@alanhill alanhill force-pushed the add_after_authenticate_job_option branch 2 times, most recently from 30e37a3 to 5b60e70 Compare July 12, 2017 17:46
@alanhill
Copy link
Contributor Author

Is it possible for ShopifyApp.configuration.after_authenticate_job to be truthy, without a job set in ShopifyApp.configuration.after_authenticate_job[:job]

Yes, I switched it up to check for the presence of the config in general, then [:job] and [:inline] otherwise it would fail on a nil class.

Also removed my typo and added the error handler like I originally intended.

Ready for another quick round of 👀

@alanhill alanhill force-pushed the add_after_authenticate_job_option branch from 5b60e70 to 79bbb27 Compare July 12, 2017 19:12

return unless config && config[:job].present? && config[:inline].present?

if config[:inline]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add tests for this conditional.

Copy link
Contributor Author

@alanhill alanhill Jul 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was pondering on this for a bit. There doesn't seem to be anything testing the authentication flow of the app - installing script tags and webhooks got lucky because they are contained in their own class instead of a job firing from within the app itself and not the gem, therefore you're able to unit test vs. integration test.

I think the only way to properly tests this is to have an integration test which goes through the entire authentication flow, unless there's a simpler way that I'm missing here?

If that's the case I could attempt to address it in another PR before merging this and can put this on hold for a bit until I can get to it.

Open to other suggestions - is there a way I can test this without essentially writing an entire integration test for the auth flow?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have a look at the SessionControllerTests. One way to do this is by testing the #callback method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 ahhh that's what I was missing. TY.

@alanhill alanhill force-pushed the add_after_authenticate_job_option branch from 44e3d7e to 6b6152e Compare July 18, 2017 00:43
@alanhill
Copy link
Contributor Author

alanhill commented Jul 18, 2017

Nice call on the test 😉 totally missed that one.

Should be good for review again!

Todo before :shipit: :

  • Add to README
  • Add to Changelog
  • Bump version (minor I assume?)

.byebug_history Outdated
config[:inline].present?
config[:job].present?
config
next
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♂️


return unless config && config[:job].present? && config[:inline].in?([true, false])

if config[:inline]
Copy link
Member

@Hammadk Hammadk Jul 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a default value for config[:inline] ? If not, we won't get to this statement because most people won't set config[:inline]. We should change this to:

return unless config && config[:job].present?

if config[:inline] == true
...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default we add inline: false when you generate the job, but I see your point. So should we just consider anything but true to mean you want to perform asynchronously ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, config[:inline] == true is good because it's self documenting code. If someone thinking about running an inline job, reading this code would tell them that they need to set that value to true.


mock_shopify_omniauth
get :callback, params: { shop: 'shop' }
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation is off here.

Copy link
Member

@Hammadk Hammadk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work. This will make the Shopify app gem much more useful. Looking forward to the updates.

@alanhill alanhill force-pushed the add_after_authenticate_job_option branch 3 times, most recently from 7cf036f to debcd11 Compare July 18, 2017 20:40
@alanhill
Copy link
Contributor Author

This should be ready for review - comments are fixed up, README and Changelog added, version bumped a minor version.

README.md Outdated
@@ -23,6 +23,7 @@ Table of Contents
* [Home Controller Generator](#home-controller-generator)
* [App Proxy Controller Generator](#app-proxy-controller-generator)
* [Controllers, Routes and Views](#controllers-routes-and-views)
* [After Authenticate Job and Generator](#after-authenticate-job-an-generator)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably drop Generator from the section heading

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I think this should go after the Webhooks and ScriptTags manager sections

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed this one, updated!

README.md Outdated

You can generate an after authenticate job by running `shopify_app:add_after_authenticate_job` which will add a line in `shopify_app.rb` giving the option
to run a job of your choosing either inline or asynchronously after the shop has authenticated. By default the job will run asynchronously unless `inline: false`
is specified.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would write this more like this:

If your app needs to perform specific actions after it is installed ShopifyApp can queue or run a job of your choosing (note that we already provide support for automatically creating Webhooks and Scripttags). To configure the after authenticate job update your initializer as follows:

ShopifyApp.configure do |config|
  config.add_after_authenticate_job = { job: Shopify::AfterAuthenticateJob }
end

If you need the job to run synchronously add the inline flag:

ShopifyApp.configure do |config|
  config.add_after_authenticate_job = { job: Shopify::AfterAuthenticateJob, inline: true }
end

We've also provided a generator which creates a skeleton job and updates the initializer for you:

bin/rails g shopify_app:add_after_authenticate_job

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thanks for that, I'm awful with words.

@alanhill alanhill force-pushed the add_after_authenticate_job_option branch from debcd11 to 6f1197f Compare July 18, 2017 21:29
@alanhill
Copy link
Contributor Author

README is updated with gooder ( 😉 ) words!

@alanhill alanhill force-pushed the add_after_authenticate_job_option branch from 6f1197f to 4da222e Compare July 18, 2017 21:33
CHANGELOG.md Outdated
@@ -1,3 +1,7 @@
7.3.1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd make this 7.4 since we added a feature

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 bumped.

@alanhill alanhill force-pushed the add_after_authenticate_job_option branch from 4da222e to 3939188 Compare July 19, 2017 15:50
@kevinhughes27
Copy link
Contributor

🚢

@alanhill alanhill merged commit 1bb51d2 into master Jul 19, 2017
@alanhill alanhill deleted the add_after_authenticate_job_option branch July 19, 2017 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants