Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

refactor: prefix email envvars with EMAIL_ (WIP: run e2e) (#266)

Guilherme Oenninge37bbe455bf5
diff --git a/.example.env b/.example.env
index 09b1604d4..2ea4cba7a 100644
--- a/.example.env
+++ b/.example.env
@@ -2,7 +2,6 @@ GO_ENV=development
LOG_LEVEL=DEBUG
DATABASE_URL=postgres://fider:fider_pw@localhost:5555/fider?sslmode=disable
JWT_SECRET=hsjl]W;&ZcHxT&FK;s%bgIQF:#ch=~#Al4:5]N;7V<qPZ3e9lT4'%;go;LIkc%k
-NOREPLY_EMAIL=
OAUTH_FACEBOOK_APPID=
OAUTH_FACEBOOK_SECRET=
@@ -13,10 +12,12 @@ OAUTH_GOOGLE_SECRET=
OAUTH_GITHUB_CLIENTID=
OAUTH_GITHUB_SECRET=
-MAILGUN_API=
-MAILGUN_DOMAIN=
+EMAIL_NOREPLY=
-SMTP_HOST=
-SMTP_PORT=
-SMTP_USERNAME=
-SMTP_PASSWORD=
+EMAIL_MAILGUN_API=
+EMAIL_MAILGUN_DOMAIN=
+
+EMAIL_SMTP_HOST=
+EMAIL_SMTP_PORT=
+EMAIL_SMTP_USERNAME=
+EMAIL_SMTP_PASSWORD=
diff --git a/.test.env b/.test.env
index 1970b8dae..e7b7a48e6 100644
--- a/.test.env
+++ b/.test.env
@@ -4,9 +4,10 @@ HOST_MODE=multi
DATABASE_URL=postgres://fider_test:fider_test_pw@localhost:5566/fider_test?sslmode=disable
AUTH_ENDPOINT=http://login.test.fider.io:3000
JWT_SECRET=SOME_RANDOM_TOKEN_JUST_FOR_TESTING
-SMTP_HOST=smtp.random.org
-SMTP_PORT=465
-SMTP_PASSWORD=random
\ No newline at end of file
+
+EMAIL_SMTP_HOST=smtp.random.org
+EMAIL_SMTP_PORT=465
+EMAIL_SMTP_PASSWORD=random
\ No newline at end of file
diff --git a/app/actions/signin.go b/app/actions/signin.go
index 2d8b397ae..101942989 100644
--- a/app/actions/signin.go
+++ b/app/actions/signin.go
@@ -31,12 +31,12 @@ func (input *SignInByEmail) Validate(user *models.User, services *app.Services)
result := validate.Success()
if input.Model.Email == "" {
- result.AddFieldFailure("email", "E-mail is required.")
+ result.AddFieldFailure("email", "Email is required.")
return result
}
if len(input.Model.Email) > 200 {
- result.AddFieldFailure("email", "E-mail must be less than 200 characters.")
+ result.AddFieldFailure("email", "Email must be less than 200 characters.")
}
emailResult := validate.Email(input.Model.Email)
diff --git a/app/actions/tenant.go b/app/actions/tenant.go
index d14c567cf..678d2ad72 100644
--- a/app/actions/tenant.go
+++ b/app/actions/tenant.go
@@ -43,7 +43,7 @@ func (input *CreateTenant) Validate(user *models.User, services *app.Services) *
}
} else {
if input.Model.Email == "" {
- result.AddFieldFailure("email", "E-mail is required.")
+ result.AddFieldFailure("email", "Email is required.")
} else {
if emailResult := validate.Email(input.Model.Email); !emailResult.Ok {
result.AddFieldFailure("email", emailResult.Messages...)
diff --git a/app/actions/user.go b/app/actions/user.go
index a495485c9..7f8113557 100644
--- a/app/actions/user.go
+++ b/app/actions/user.go
@@ -69,12 +69,12 @@ func (input *ChangeUserEmail) Validate(user *models.User, services *app.Services
result := validate.Success()
if input.Model.Email == "" {
- result.AddFieldFailure("email", "E-mail is required.")
+ result.AddFieldFailure("email", "Email is required.")
return result
}
if len(input.Model.Email) > 200 {
- result.AddFieldFailure("email", "E-mail must be less than 200 characters.")
+ result.AddFieldFailure("email", "Email must be less than 200 characters.")
return result
}
diff --git a/app/pkg/email/email.go b/app/pkg/email/email.go
index cc9092e8e..81f3afa11 100644
--- a/app/pkg/email/email.go
+++ b/app/pkg/email/email.go
@@ -51,7 +51,7 @@ func RenderMessage(templateName string, params Params) *Message {
}
// NoReply is the default 'from' address
-var NoReply = env.MustGet("NOREPLY_EMAIL")
+var NoReply = env.MustGet("EMAIL_NOREPLY")
// Recipient contains details of who is receiving the email
type Recipient struct {
diff --git a/app/pkg/email/mailgun/mailgun.go b/app/pkg/email/mailgun/mailgun.go
index 592fcf7fa..c1a8b3e9d 100644
--- a/app/pkg/email/mailgun/mailgun.go
+++ b/app/pkg/email/mailgun/mailgun.go
@@ -99,6 +99,6 @@ func (s *Sender) BatchSend(templateName string, params email.Params, from string
s.logger.Errorf("Failed to send email")
return err
}
- s.logger.Debugf("E-mail sent with response code %d.", resp.StatusCode)
+ s.logger.Debugf("Email sent with response code %d.", resp.StatusCode)
return nil
}
diff --git a/app/pkg/email/smtp/smtp.go b/app/pkg/email/smtp/smtp.go
index e3bf628c3..c39431287 100644
--- a/app/pkg/email/smtp/smtp.go
+++ b/app/pkg/email/smtp/smtp.go
@@ -52,7 +52,7 @@ func (s *Sender) Send(templateName string, params email.Params, from string, to
s.logger.Errorf("Failed to send email")
return err
}
- s.logger.Debugf("E-mail sent.")
+ s.logger.Debugf("Email sent.")
return nil
}
diff --git a/app/pkg/validate/general.go b/app/pkg/validate/general.go
index 8db6b84fc..1988473c9 100644
--- a/app/pkg/validate/general.go
+++ b/app/pkg/validate/general.go
@@ -17,11 +17,11 @@ func Email(email string) *Result {
email = strings.ToLower(email)
if len(email) > 200 {
- return Failed([]string{"E-mail address must be less than 200 characters."})
+ return Failed([]string{"Email address must be less than 200 characters."})
}
if !emailRegex.MatchString(email) {
- return Failed([]string{"E-mail address is invalid."})
+ return Failed([]string{"Email address is invalid."})
}
return Success()
diff --git a/app/services.go b/app/services.go
index c538cea21..cbb9f80c9 100644
--- a/app/services.go
+++ b/app/services.go
@@ -42,14 +42,14 @@ func NewEmailer(logger log.Logger) email.Sender {
if env.IsTest() {
return email.NewNoopSender()
}
- if env.IsDefined("MAILGUN_API") {
- return mailgun.NewSender(logger, env.MustGet("MAILGUN_DOMAIN"), env.MustGet("MAILGUN_API"))
+ if env.IsDefined("EMAIL_MAILGUN_API") {
+ return mailgun.NewSender(logger, env.MustGet("EMAIL_MAILGUN_DOMAIN"), env.MustGet("EMAIL_MAILGUN_API"))
}
return smtp.NewSender(
logger,
- env.MustGet("SMTP_HOST"),
- env.MustGet("SMTP_PORT"),
- env.MustGet("SMTP_USERNAME"),
- env.MustGet("SMTP_PASSWORD"),
+ env.MustGet("EMAIL_SMTP_HOST"),
+ env.MustGet("EMAIL_SMTP_PORT"),
+ env.MustGet("EMAIL_SMTP_USERNAME"),
+ env.MustGet("EMAIL_SMTP_PASSWORD"),
)
}
diff --git a/public/pages/site/UserSettingsPage/NotificationSettings.tsx b/public/pages/site/UserSettingsPage/NotificationSettings.tsx
index e6278951e..a73d1ac95 100644
--- a/public/pages/site/UserSettingsPage/NotificationSettings.tsx
+++ b/public/pages/site/UserSettingsPage/NotificationSettings.tsx
@@ -46,7 +46,7 @@ export class NotificationSettings extends React.Component<NotificationSettingsPr
: <i className="large toggle off icon" />;
const text = channel === WebChannel
? 'Web *'
- : 'E-mail';
+ : 'Email';
return (
<span className="option" onClick={this.toggle.bind(this, settingsKey, channel)}>
{i} {text}
diff --git a/public/pages/site/UserSettingsPage/UserSettingsPage.tsx b/public/pages/site/UserSettingsPage/UserSettingsPage.tsx
index 1aaedfc66..04c25aad9 100644
--- a/public/pages/site/UserSettingsPage/UserSettingsPage.tsx
+++ b/public/pages/site/UserSettingsPage/UserSettingsPage.tsx
@@ -89,7 +89,7 @@ export class UserSettingsPage extends React.Component<UserSettingsPageProps, Use
</div>
<DisplayError fields={['email']} error={this.state.error} />
<div className="field">
- <label htmlFor="email">E-mail <span className="info">Your email is private and will never be displayed to anyone.</span></label>
+ <label htmlFor="email">Email <span className="info">Your email is private and will never be displayed to anyone.</span></label>
{
this.state.changingEmail ?
<>
diff --git a/scripts/e2e.sh b/scripts/e2e.sh
index 328ace7d1..5fea11499 100755
--- a/scripts/e2e.sh
+++ b/scripts/e2e.sh
@@ -30,6 +30,7 @@ run_e2e () {
}
} && {
echo "Stopping Fider ..."
+ docker logs $FIDER_CONTAINER >> ./logs/e2e.log
docker rm -f $FIDER_CONTAINER
}
}
diff --git a/tests/lib/mailgun/index.ts b/tests/lib/mailgun/index.ts
index 5a4acecd8..b084f4ea7 100644
--- a/tests/lib/mailgun/index.ts
+++ b/tests/lib/mailgun/index.ts
@@ -11,7 +11,7 @@ const httpGet = (endpoint: string): Promise<any> => {
host: url.host,
port: 443,
method: 'GET',
- auth: `api:${process.env.MAILGUN_API}`,
+ auth: `api:${process.env.EMAIL_MAILGUN_API}`,
path: url.path,
};
https.get(opts, (res: http.IncomingMessage) => {
@@ -29,16 +29,16 @@ export const mailgun = {
do {
count++;
- const url = `https://api.mailgun.net/v3/${process.env.MAILGUN_DOMAIN}/events?to=${to}&event=delivered&limit=1&ascending=no`;
+ const url = `https://api.mailgun.net/v3/${process.env.EMAIL_MAILGUN_DOMAIN}/events?to=${to}&event=accepted&limit=1&ascending=no`;
const events = await httpGet(url);
- if (events.items.length > 0 && events.items[0].message.headers.to === to) {
+ if (events.items.length > 0 && events.items[0].recipient === to) {
messageUrl = events.items[0].storage.url;
} else {
await delay(500);
}
- } while (!messageUrl && count < 60);
+ } while (!messageUrl && count < 30);
- if (count === 60) {
+ if (count === 30) {
throw new Error(`Message not found for ${to}.`);
}