Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@kieckhafer
Copy link
Member

@kieckhafer kieckhafer commented Sep 10, 2019

Resolves parts of #5529
Impact: minor
Type: feat|refactor

Issue

email/verifySettings was a meteor method which used getGraphQLContextInMeteorMethod

Solution

Rewrite the meteor method to be a verifySMTPEmailSettings GraphQL mutation, which in turn will remove usage of getGraphQLContextInMeteorMethod.

The color of the status indicator is not reactive. This is not a regression, it is currently not reactive in master. Since there are other Meteor methods and more refactors of this code to come in the future, I've chosen to leave this as is for now.

Breaking changes

Any custom code which used the email/verifySettings meteor method will need to be updated to use the GraphQL mutation

Testing

  1. Add correct email settings and see they come back as verified
  2. Add incorrect email settings and see they come back as an error

@kieckhafer kieckhafer changed the base branch from master to develop September 10, 2019 22:33
@kieckhafer kieckhafer marked this pull request as ready for review September 13, 2019 19:30
@kieckhafer
Copy link
Member Author

kieckhafer commented Sep 13, 2019

@aldeed I'm not entirely sure why graphql-lint is failing. The message says Every argument must have a description arguments-have-descriptions, but I think they all do, unless I'm not seeing something: https://github.com/reactioncommerce/reaction/pull/5531/files#diff-abfa8cc3a4ed4b0025df75047b823930

Edit: Nevermind, figured out the issue.

Signed-off-by: Erik Kieckhafer <[email protected]>
Copy link
Contributor

@aldeed aldeed left a comment

Choose a reason for hiding this comment

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

Some comments, and if possible it would be good to add one Jest integration test for the new mutation. I think if you maybe use nock you could simulate an SMTP server that would pass verification.


const verified = await transporter.verify()
.then((result) => result)
.catch((error) => { throw new ReactionError(error.responseCode, error.response); });
Copy link
Contributor

Choose a reason for hiding this comment

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

If using async/await, it's best to stick with that and try/catch instead of also using .then and .catch.

let verified;
try {
  verified = await transporter.verify();
} catch (error) {
  throw new ReactionError(error.responseCode, error.response);
}

return verified;

clientMutationId: String

"Are the settings OK"
verified: Boolean
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe do isVerified to follow the rule about boolean naming. It should be safe to do Boolean!, too. I don't think it will ever be null when there were no errors.

"The same string you sent with the mutation params, for matching mutation calls with their responses"
clientMutationId: String

"Are the settings OK"
Copy link
Contributor

Choose a reason for hiding this comment

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

More descriptive description would be "True if the SMTP connection was made and authentication was successful."

cancelButtonText: i18next.t("app.cancel"),
confirmButtonColor: "#DD6B55",
confirmButtonText: i18next.t("app.save")
}).then(() => save()).catch(() => true));
Copy link
Contributor

Choose a reason for hiding this comment

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

If using async/await, it's best to stick with that and try/catch instead of also using .then and .catch.

let shouldSave = true;
try {
    await client.mutate({
      mutation: verifySMTPEmailSettings,
      variables: {
        input: {
          host: settings.host,
          password: settings.password,
          port: settings.port,
          service: settings.service,
          shopId: opaqueShopId,
          user: settings.user
        }
      }
    });
} catch (error) {
  shouldSave = false;
}

if (!shouldSave) {
  try {
      await Alert({
        title: i18next.t("mail.alerts.connectionFailed"),
        text: i18next.t("mail.alerts.saveAnyway"),
        type: "warning",
        showCancelButton: true,
        cancelButtonText: i18next.t("app.cancel"),
        confirmButtonColor: "#DD6B55",
        confirmButtonText: i18next.t("app.save")
      })
  } catch (error) {
    callback();
    return;
  }
}

callback();
await save();

It's still a bit weird. If it doesn't work and what you have does work, then it's fine. We should eventually make a confirm Alert that returns true/false rather than throwing so we don't need so many try/catch.

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 was struggling with getting try/catch to work, and it just wasn't, which is why i'm doing the different then...catch in both places here. I'll try again with what you've posted here, but it was just being weird.

…EmailSettings' and 'refactor-kieckhafer-removeContextInGraphQL-verifySMTPEmailSettings' of github.com:/reactioncommerce/reaction into refactor-kieckhafer-removeContextInGraphQL-verifySMTPEmailSettings
Copy link
Contributor

@aldeed aldeed left a comment

Choose a reason for hiding this comment

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

@kieckhafer One more little thing.

Signed-off-by: Erik Kieckhafer <[email protected]>
@aldeed
Copy link
Contributor

aldeed commented Sep 19, 2019

OK to merge, but holding off until integration test is added.

@aldeed aldeed mentioned this pull request Sep 23, 2019
45 tasks
@aldeed aldeed merged commit a2e8dc4 into develop Sep 25, 2019
@aldeed aldeed deleted the refactor-kieckhafer-removeContextInGraphQL-verifySMTPEmailSettings branch September 25, 2019 16:51
@kieckhafer kieckhafer mentioned this pull request Sep 25, 2019
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.

4 participants