-
Notifications
You must be signed in to change notification settings - Fork 27
feat: implement email notification templates builder #1804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
exAdmos
wants to merge
14
commits into
staging
Choose a base branch
from
gw_feat_lms_1719_email_notification_templates
base: staging
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f1be59c
feat: implement email notification templates builder
5e91d32
feat applay feedback
26502a4
test: address email template PR check failures
28972e0
test: add licensing exceptions
4eaa58d
test: expande coverage
131c8ea
make empty button url show warning
f58718d
style: align templates list with admin courses page
223b4ad
fix: adress revier's feedback
4f981fc
style: make in default template button centred
55a4fea
fix: address feedback
558e4d4
test: merge and add FR to def templates
ba6617f
fix: add French language to generated API types for email templates
f4a3b50
fix: render breadcrumb separators outside list items
83c0b63
chore: merge staging and resolve conflicts
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
apps/api/src/common/emails/__tests__/emails.service.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import { TENANT_LOGO_CID, TENANT_LOGO_CID_SRC } from "@repo/shared"; | ||
|
|
||
| import { EmailService } from "../emails.service"; | ||
|
|
||
| const TENANT_ID = "22222222-2222-2222-2222-222222222222"; | ||
| const BORDER_CIRCLE_CID = "border-circle"; | ||
|
|
||
| const makeService = (adapter: "mailhog" | "smtp" | "ses" = "mailhog") => { | ||
| const emailAdapter = { | ||
| sendMail: jest.fn(), | ||
| }; | ||
| const settingsService = { | ||
| getPlatformLogoBuffer: jest.fn().mockResolvedValue(Buffer.from("logo")), | ||
| getEmailBorderCircleBuffer: jest.fn().mockResolvedValue(Buffer.from("border")), | ||
| }; | ||
| const tenantRunner = { | ||
| runWithTenant: jest.fn((_tenantId: string, fn: () => Promise<unknown>) => fn()), | ||
| }; | ||
| const configService = { | ||
| get: jest.fn((key: string) => { | ||
| if (key === "email.SMTP_EMAIL_FROM") return "noreply@example.com"; | ||
| if (key === "email.EMAIL_ADAPTER") return adapter; | ||
| return undefined; | ||
| }), | ||
| }; | ||
|
|
||
| const service = new EmailService( | ||
| {} as never, | ||
| emailAdapter as never, | ||
| settingsService as never, | ||
| tenantRunner as never, | ||
| configService as never, | ||
| ); | ||
|
|
||
| return { service, emailAdapter, tenantRunner }; | ||
| }; | ||
|
|
||
| describe("EmailService", () => { | ||
| it("adds inline content ids for Mailhog mailbox rendering", async () => { | ||
| const { service, emailAdapter, tenantRunner } = makeService(); | ||
|
|
||
| await service.sendEmailWithLogo( | ||
| { | ||
| to: "learner@example.com", | ||
| subject: "Subject", | ||
| html: `<img src="${TENANT_LOGO_CID_SRC}" alt="logo" />`, | ||
| }, | ||
| { tenantId: TENANT_ID }, | ||
| ); | ||
|
|
||
| expect(tenantRunner.runWithTenant).toHaveBeenCalledWith(TENANT_ID, expect.any(Function)); | ||
| expect(emailAdapter.sendMail).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| from: "noreply@example.com", | ||
| attachments: [ | ||
| expect.objectContaining({ | ||
| filename: "logo.png", | ||
| cid: TENANT_LOGO_CID, | ||
| contentType: "image/png", | ||
| }), | ||
| expect.objectContaining({ | ||
| filename: "border-circle.png", | ||
| cid: BORDER_CIRCLE_CID, | ||
| contentType: "image/png", | ||
| }), | ||
| ], | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| it.each(["smtp", "ses"] as const)("adds inline content ids for %s", async (adapter) => { | ||
| const { service, emailAdapter } = makeService(adapter); | ||
|
|
||
| await service.sendEmailWithLogo( | ||
| { | ||
| to: "learner@example.com", | ||
| subject: "Subject", | ||
| html: `<img src="${TENANT_LOGO_CID_SRC}" alt="logo" />`, | ||
| }, | ||
| { tenantId: TENANT_ID }, | ||
| ); | ||
|
|
||
| const payload = emailAdapter.sendMail.mock.calls[0][0]; | ||
| expect(payload.attachments).toEqual([ | ||
| expect.objectContaining({ | ||
| filename: "logo.png", | ||
| cid: TENANT_LOGO_CID, | ||
| contentType: "image/png", | ||
| }), | ||
| expect.objectContaining({ | ||
| filename: "border-circle.png", | ||
| cid: BORDER_CIRCLE_CID, | ||
| contentType: "image/png", | ||
| }), | ||
| ]); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| const PG_UNIQUE_VIOLATION = "23505"; | ||
|
|
||
| type PostgresErrorLike = { | ||
| code?: string; | ||
| constraint_name?: string; | ||
| constraint?: string; | ||
| }; | ||
|
|
||
| export function isPostgresUniqueViolation(err: unknown, constraintName: string): boolean { | ||
| if (!err || typeof err !== "object") return false; | ||
|
|
||
| const { code, constraint_name, constraint } = err as PostgresErrorLike; | ||
|
|
||
| return ( | ||
| code === PG_UNIQUE_VIOLATION && | ||
| (constraint_name === constraintName || constraint === constraintName) | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.