Skip to content

Commit

Permalink
adding resend email address
Browse files Browse the repository at this point in the history
  • Loading branch information
goodeats committed May 22, 2024
1 parent d81569a commit 70cdbe7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ SESSION_SECRET="super-duper-s3cret"
HONEYPOT_SECRET="super-duper-s3cret"
INTERNAL_COMMAND_TOKEN="some-made-up-token"
RESEND_API_KEY="re_blAh_blaHBlaHblahBLAhBlAh"
RESEND_EMAIL_ADDRESS="[email protected]"
SENTRY_DSN="your-dsn"

# the mocks and some code rely on these two being prefixed with "MOCK_"
Expand Down
2 changes: 1 addition & 1 deletion app/utils/email.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export async function sendEmail({
| { html: string; text: string; react?: never }
| { react: ReactElement; html?: never; text?: never }
)) {
const from = '[email protected]'
const from = process.env.RESEND_EMAIL_ADDRESS

const email = {
from,
Expand Down
9 changes: 5 additions & 4 deletions tests/e2e/onboarding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { prisma } from '#app/utils/db.server.ts'
import { readEmail } from '#tests/mocks/utils.ts'
import { createUser, expect, test as base } from '#tests/playwright-utils.ts'

const RESEND_EMAIL_ADDRESS = process.env.RESEND_EMAIL_ADDRESS
const URL_REGEX = /(?<url>https?:\/\/[^\s$.?#].[^\s]*)/
const CODE_REGEX = /Here's your verification code: (?<code>[\d\w]+)/
function extractUrl(text: string) {
Expand Down Expand Up @@ -61,7 +62,7 @@ test('onboarding with link', async ({ page, getOnboardingData }) => {
const email = await readEmail(onboardingData.email)
invariant(email, 'Email not found')
expect(email.to).toBe(onboardingData.email.toLowerCase())
expect(email.from).toBe('[email protected]')
expect(email.from).toBe(RESEND_EMAIL_ADDRESS)
expect(email.subject).toMatch(/welcome/i)
const onboardingUrl = extractUrl(email.text)
invariant(onboardingUrl, 'Onboarding URL not found')
Expand Down Expand Up @@ -121,7 +122,7 @@ test('onboarding with a short code', async ({ page, getOnboardingData }) => {
const email = await readEmail(onboardingData.email)
invariant(email, 'Email not found')
expect(email.to).toBe(onboardingData.email.toLowerCase())
expect(email.from).toBe('[email protected]')
expect(email.from).toBe(RESEND_EMAIL_ADDRESS)
expect(email.subject).toMatch(/welcome/i)
const codeMatch = email.text.match(CODE_REGEX)
const code = codeMatch?.groups?.code
Expand Down Expand Up @@ -168,7 +169,7 @@ test('reset password with a link', async ({ page, insertNewUser }) => {
invariant(email, 'Email not found')
expect(email.subject).toMatch(/password reset/i)
expect(email.to).toBe(user.email.toLowerCase())
expect(email.from).toBe('[email protected]')
expect(email.from).toBe(RESEND_EMAIL_ADDRESS)
const resetPasswordUrl = extractUrl(email.text)
invariant(resetPasswordUrl, 'Reset password URL not found')
await page.goto(resetPasswordUrl)
Expand Down Expand Up @@ -226,7 +227,7 @@ test('reset password with a short code', async ({ page, insertNewUser }) => {
invariant(email, 'Email not found')
expect(email.subject).toMatch(/password reset/i)
expect(email.to).toBe(user.email)
expect(email.from).toBe('[email protected]')
expect(email.from).toBe(RESEND_EMAIL_ADDRESS)
const codeMatch = email.text.match(CODE_REGEX)
const code = codeMatch?.groups?.code
invariant(code, 'Reset Password code not found')
Expand Down

0 comments on commit 70cdbe7

Please sign in to comment.