10000 test: confirm correct app.function handler handling by zimeg · Pull Request #2139 · slackapi/bolt-js · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

test: confirm correct app.function handler handling #2139

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

Closed

Conversation

zimeg
Copy link
Member
@zimeg zimeg commented Jun 19, 2024

Summary

This PR tests the implementation of app.function handlers across a few cases with some refactors and fixes found along the way.

Changes that extend those found in #2026 and #2128:

  • Listener middleware can now be used with app.function
  • Types are exported from the types directory
  • Inline documentation is added for editor hover hints

Preview

Experiment with an app that uses listener middleware and functions with actions after checking out and building this branch:

$ slack create baker -t zimeg/slacks -b js.bolt.cookies
$ cd baker
$ npm install ../../path/to/bolt-js
$ slack run

Then add the cookies function as a step to a workflow.

Reviewers

The tests in src/App-custom-function.spec.ts cover the use cases I could think of! Please let me know of others that should be considered 🙏

Notes

Will follow up with updates to https://slack.dev in another PR to avoid cluttering this diff too much!

Requirements

misscoded and others added 4 commits June 5, 2024 19:45
* ensure custom function middleware uses the configured token
* ensure action handlers have middleware for function executions
* ensure listener middleware is honored in function handlers
* ensure custom function middleware arguments call correct apis
* ensure custom function handlers are setup with valid arguments
* document usage of attributes and handlers inline with jsdoc
* refactor logic and types into custom function specific files
@zimeg zimeg added bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented semver:patch tests M-T: Testing work only labels Jun 19, 2024
@zimeg zimeg self-assigned this Jun 19, 2024
Copy link
codecov bot commented Jun 19, 2024

Codecov Report

Attention: Patch coverage is 88.23529% with 8 lines in your changes missing coverage. Please review.

Project coverage is 82.49%. Comparing base (ab80d52) to head (54f3692).

Files Patch % Lines
src/CustomFunction.ts 84.90% 0 Missing and 8 partials ⚠️
Additional details and impacted files
@@                 Coverage Diff                  @@
##           pre-stable-fixes    #2139      +/-   ##
====================================================
+ Coverage             80.87%   82.49%   +1.61%     
====================================================
  Files                    19       20       +1     
  Lines                  1637     1617      -20     
  Branches                461      461              
====================================================
+ Hits                   1324     1334      +10     
+ Misses                  205      179      -26     
+ Partials                108      104       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor
@WilliamBergamin WilliamBergamin left a comment

Choose a reason for hiding this comment

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

Good job 💯
Left a few comments

* Overrides for spying on mocks are below this comment
*/

async function importApp(
Copy link
Contributor

Choose a reason for hiding this comment

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

This is nice 💯!
Any chance we could bring it out of this file so the pattern can be reused by other tests? No worries if you don't have time

@@ -527,10 +536,26 @@ export default class App<AppCustomContext extends StringIndexed = StringIndexed>
}

/**
* Register CustomFunction middleware
*/
* Custom function listener and middleware that executes for a matching function callbackId.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice 💯

* @param context - the incoming payload context.
* @link https://github.com/slackapi/bolt-js/pull/2026#discussion_r1467123047
*/
private static selectToken(context: Context): string | undefined {
Copy link
Contributor
@WilliamBergamin WilliamBergamin Jun 19, 2024

Choose a reason for hiding this comment

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

I think this logic is duplicated in the App.ts 🤔
Might be a good idea to consolidate it

Copy link
Member Author

Choose a reason for hiding this comment

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

Great call once more! Had to think a bit about where this might make sense - exporting from App.ts into CustomFunction.ts felt strange - and ended up creating middleware/context.ts for similar context operations. Open to adjustments though ✨

@zimeg zimeg requested a review from WilliamBergamin June 21, 2024 18:12
@zimeg
Copy link
Member Author
zimeg commented Jun 21, 2024

@WilliamBergamin appreciate all of those suggestions and the review. The code gets pushed in a better direction with each. I'm feeling solid about these changes and am interested in tagging a new beta with it, perhaps today, since most of the remaining changes seem to be testing related 👀

@zimeg
Copy link
Member Author
zimeg commented Jun 21, 2024

Update: Holding off on tagging another beta with these changes - will mark it as draft for following up sometime soon.

@zimeg zimeg marked this pull request as draft June 21, 2024 22:28
Copy link
Contributor
@WilliamBergamin WilliamBergamin left a comment

Choose a reason for hiding this comment

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

Thanks a lot for addressing all my comments 🙏

I went over the changes one last time and added one last comment that I was previously on the fence about, let me know what you think

Also I think we can move this PR out of draft

'retryNum',
'retryReason',
...Array<keyof CustomFunctionContext>(),
Copy link
Contributor
@WilliamBergamin WilliamBergamin Jun 25, 2024

Choose a reason for hiding this comment

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

What do you think about explicitly defining fields?

I think it can make the code clearer for future maintainers and prevent a field from being accidentally added through an inherited object 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm partial to both approaches! The magic is nice to avoid forgetting to add it to context and needing to hunt for these fields, but magic is a dangerous art 😳

@misscoded misscoded force-pushed the pre-stable-fixes branch 2 times, most recently from 9df1e68 to f7966e7 Compare August 7, 2024 21:45
@filmaj filmaj deleted the branch slackapi:pre-stable-fixes August 12, 2024 19:20
@filmaj filmaj closed this Aug 12, 2024
@zimeg zimeg deleted the zimeg/test-custom-functions branch August 12, 2024 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented semver:patch tests M-T: Testing work only
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0