Skip to content

Commit

Permalink
add script to send mock emails
Browse files Browse the repository at this point in the history
  • Loading branch information
kdembler committed Aug 31, 2023
1 parent e8e103f commit 78af048
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ To run the API to develop locally:
- `yarn workspace server test`: Run tests.
- `yarn workspace server dev:notify`: Run the notifier `nodemon` and `ts-node`.
- `yarn workspace server dev:db:reset`: Clear the database data and re-synchronize its schema.
- `yarn workspace server dev:emails`: Run live development preview for emails.
- `yarn workspace server dev:mockEmail email [notificationKind]`: Send mock email.
- `yarn workspace server codegen`: Run `graphql-codegen`.
- [`yarn workspace server prisma studio`][prisma studio]: Launch an administration GUI for the database.
- [`yarn workspace server prisma db push`][prisma db:push]: Synchronize `schema.prisma` with the database schema.
Expand Down
1 change: 1 addition & 0 deletions packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"dev:db:build": "yarn dev:db && yarn dev:build",
"dev:api": "yarn nodemon ./src/common/scripts/startApi.ts",
"dev:notify": "yarn nodemon ./src/notifier/scripts/notify.ts",
"dev:mockEmail": "yarn ts-node ./src/notifier/scripts/mockEmail.ts",
"dev:authtoken": "yarn nodemon ./src/auth/scripts/generateToken.ts",
"dev:emails": "email dev --dir ./src/common/email-templates",
"lint": "yarn lint:prettier --check && yarn lint:eslint --max-warnings=0",
Expand Down
38 changes: 38 additions & 0 deletions packages/server/src/notifier/scripts/mockEmail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { NotificationKind } from '@prisma/client'

import { createEmailProvider } from '@/common/utils'

import { createEmailNotifier } from '../model/email'

const sendEmail = async () => {
const emailAddress = process.argv[2]
if (!emailAddress) {
process.stderr.write('Usage: mockEmail emailAddress [notificationKind]')
return
}
const emailProvider = createEmailProvider()
const emailKind = (process.argv[3] as NotificationKind) || 'FORUM_POST_MENTION'

const commonNotificationFields = {
id: 1,
entityId: '1',
eventId: '1',
member: {
id: 1,
name: 'test',
email: emailAddress,
},
memberId: 1,
isRead: false,
isSent: false,
}

const notification = {
...commonNotificationFields,
kind: emailKind,
}
const notifyViaEmail = createEmailNotifier(emailProvider)
await notifyViaEmail(notification)
}

sendEmail()

0 comments on commit 78af048

Please sign in to comment.