From 78af0483fd52bc226c1110579ee810a9cbf10aed Mon Sep 17 00:00:00 2001 From: Klaudiusz Dembler Date: Thu, 31 Aug 2023 20:50:10 +0200 Subject: [PATCH] add script to send mock emails --- packages/server/README.md | 2 + packages/server/package.json | 1 + .../server/src/notifier/scripts/mockEmail.ts | 38 +++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 packages/server/src/notifier/scripts/mockEmail.ts diff --git a/packages/server/README.md b/packages/server/README.md index 8ee9b51b93..cf35866d6e 100644 --- a/packages/server/README.md +++ b/packages/server/README.md @@ -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. diff --git a/packages/server/package.json b/packages/server/package.json index 164e471444..41f70e7d71 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -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", diff --git a/packages/server/src/notifier/scripts/mockEmail.ts b/packages/server/src/notifier/scripts/mockEmail.ts new file mode 100644 index 0000000000..3018ea62d9 --- /dev/null +++ b/packages/server/src/notifier/scripts/mockEmail.ts @@ -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()