Fix #1805 Include headers in the request object of custom route handlers - #1806
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1806 +/- ##
==========================================
+ Coverage 82.11% 82.15% +0.04%
==========================================
Files 18 18
Lines 1526 1519 -7
Branches 442 435 -7
==========================================
- Hits 1253 1248 -5
Misses 175 175
+ Partials 98 96 -2
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
|
Hey @E-Zim, thanks for working on this! Since I am a bit busy for other things right now, I won't be able to review this PR this week. If other assigned reviewers can do within a few days, I will defer to them for PR approvals. |
| fakeReq.method = 'GET'; | ||
| receiver.requestListener(fakeReq, fakeRes); | ||
| assert(customRoutes[0].handler.calledWith({ ...fakeReq, params }, fakeRes)); | ||
| let message = Object.assign(fakeReq, { params }); |
There was a problem hiding this comment.
Since this is a test and message is a value we expect and compare against, I think renaming it something more descriptive such as expectedMessage or something similar would provide more context
Let me know what you think
There was a problem hiding this comment.
That is much more clear, nice callout! I have gone and updated all of the tests with this 👍
Summary
The changes in this PR assign
req.headersto the request object in handlers of custom routes and adds an example to the docs. Fixes #1805.Reviewers
With the changes on this branch, verify that request headers are displayed in static and dynamic routes using both Socket Mode and HTTP. You can check this by navigating to these routes with the following code:
http://localhost:3000/healthhttp://localhost:3000/music/jazzDiagnostic notes
For those curious about the changes, some findings are below. This was a neat exploration into the
Symbolobject and how objects are spread! So...Access to certain attributes of the
reqobject (such asreq.headers) was lost in the spread operator in the line below:However, similar attributes would appear when logging the
reqobject, just in aSymbolform, like so:As a result of being represented as symbols, these weren't expanded by the spread operator. From the MDN docs:
So this was causing the
{ ...req, params }object to not include all attributes ofreq!To include the missing attributes and the
paramsobject, a call toObject.assign()was used instead:This
Object.assign()method "copies all enumerable own properties", which includes these symbols and no longer requires a type assertion, so thereq.headersattribute returns!Requirements