Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kevingrozav
Copy link

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.

Copy link
Member

@jsdelfino jsdelfino left a 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);
Copy link
Member

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);
Copy link
Member

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);
Copy link
Member

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) => {
Copy link
Member

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);
Copy link
Member

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) => {
Copy link
Member

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) => {
Copy link
Member

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) => {
Copy link
Member

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) => {
Copy link
Member

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', {
Copy link
Member

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.

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.

2 participants