-
Notifications
You must be signed in to change notification settings - Fork 20
Update to Async/Await #3
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
base: master
Are you sure you want to change the base?
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.
Thanks for this pull request. I have a few review comments.
src/app.js
Outdated
log('Send result %d, %o', res.statusCode, res.body); | ||
} | ||
catch(err) { | ||
log('Error sending message %o', err); |
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 like this code silently discards the caught exception. I think it should be re-thrown.
src/app.js
Outdated
}] | ||
} | ||
}); | ||
log('Send result %d, %o', res.statusCode, res.body); |
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.
An exception should be thrown is statusCode is !== 200.
src/app.js
Outdated
const app = await webapp( | ||
env.ECHO_APP_ID, env.ECHO_APP_SECRET, | ||
env.ECHO_WEBHOOK_SECRET); | ||
cb(null); |
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 don't think there's a need for a callback here as this function was converted to async.
src/app.js
Outdated
https.createServer(conf, app).listen(port, cb); | ||
}); | ||
}); | ||
const main = async (argv, env, cb) => { |
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.
The cb parameter is not needed here as the function was converted to async.
src/app.js
Outdated
} | ||
} | ||
catch(err) { | ||
cb(err); |
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.
Same comment as above, no need to call a callback here, since the function is async.
src/test/test.js
Outdated
|
||
check(); | ||
echo.webapp('testappid', 'testsecret', 'testwsecret') | ||
.then((app) => { |
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'd suggest to use await here instead of a promise (since this pull request is about using async/await)
src/test/test.js
Outdated
}); | ||
|
||
it('handles Webhook challenge requests', (done) => { | ||
it('handles Webhook challenge requests', async (done) => { |
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 don't think using a done callback like this is actually compatible with an async test function.
src/test/test.js
Outdated
echo.webapp('testappid', 'testsecret', 'testwsecret', (err, app) => { | ||
expect(err).to.equal(null); | ||
echo.webapp('testappid', 'testsecret', 'testwsecret') | ||
.then((app) => { |
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.
Suggest to convert to async/await here as well.
src/test/test.js
Outdated
// Expect the request to be rejected | ||
expect(val.statusCode).to.equal(401); | ||
echo.webapp('testappid', 'testsecret', 'testwsecret') | ||
.then((app) => { |
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.
Suggest to convert to async/await.
src/test/test.js
Outdated
const server = app.listen(0); | ||
|
||
// Post a chat message to the app | ||
post('http://localhost:' + server.address().port + '/echo', { |
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 like this call wasn't converted to async/await.
Hey Sebastian,
I refactored the both the code and the unit tests a bit for async/await with promises. Both end to end and unit tests are passing. Ill send you a screenshot of the echo from my Example space.