Skip to content

Commit

Permalink
feat: add send test email button in email page
Browse files Browse the repository at this point in the history
  • Loading branch information
multivoltage committed Aug 10, 2023
1 parent ccc4c90 commit 77d0672
Show file tree
Hide file tree
Showing 14 changed files with 1,588 additions and 20 deletions.
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ Under the hood a default configuration will be loaded but a file `marilena.confi
| mjmlParsingOptions | | options passed to mjml render. See: [mjml options](https://www.npmjs.com/package/mjml) |
| htmlVersion | | function of type `(emailName: string, locale: string) => string`. If set, this function allow to customize the output html filename. The function must return file name `es: ${emailName}-${locale}.html` | index.html |
| textVersion | | function of type `(emailName: string, locale: string) => string`. If set, this function allow to generate text version of email stripping all html. The function must return file name `es: ${emailName}-${locale}-text-version.txt` |
| sendTestOptions | | option in case you want to send the email to some account for testing. Setting this should add `send email` button during development: Read below for some use cases |

## About templateOptions

Expand Down Expand Up @@ -161,6 +162,28 @@ templateOptions: {

---

## About templateOptions

This option provides a fast way to test email sending an email to real account. For now this is possible using `aws-ses` provider. In this case you shoul have a valid Amazon SES account. Setting this options will add a small form in the email page development. Example:

```js
sendTestOptions: {
provider: "aws-ses", // only aws-ses is supported
to: "[email protected]", // this is only a default. During development you can set different address
from: "noreply@custom_domain.com", // only valid and registered alias are working with your associated Aws Ses accout
// this field must return an object of type aws.SES. Below is only a basic working example
ses: () =>
new aws.SES({
apiVersion: "2010-12-01", // should be the same
region: "us-east-1",
credentials: {
accessKeyId: "...",
secretAccessKey: "...",
},
}),
},
```

## Use css

If you want to add a css file import in `mj-include` tag. Path start from root directory of the project (like package json):
Expand All @@ -186,12 +209,13 @@ If you want to add a css file import in `mj-include` tag. Path start from root d
- [x] load varibles from yaml/json format
- [x] load common variables
- [x] pass option to MJML render
- [x] easy way to send a real email (AWS Ses)

## 🏗️ Roadmap (PRs are welcome 😀)

- [ ] liquid, ejs, nunjucks, mustache, dot
- [ ] config in typescript
- [ ] easy way to send a real email (AWS Ses/Nodemailer)
- [ ] extends send test email to custom provider
- [ ] fast-refresh on config change
- [ ] snaphost test for each email out of the box
- [ ] refactor to esm instead common js
36 changes: 36 additions & 0 deletions cypress/e2e/server.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,42 @@ describe("Email refresh - Playground", () => {
});
});

describe("Email Actions - Playground", () => {
it("email page with should sendOptions should send a test email and render result without error", () => {
cy.visit(`http://localhost:8080/${welcomeHrefUrl_it("en")}`);

cy.intercept("POST", /api\/postSendEmail/, {
fixture: "postSendEmail_aws_ses_ok",
statusCode: 200,
}).as("postSendEmail");

cy.get("#send-form__input").should(
"have.value",
"[email protected]",
);
cy.contains("SEND EMAIL TO").click();
cy.wait("@postSendEmail");
cy.get("#modal-send-email__result").should("be.visible");
});

it("email page with should sendOptions should send a test email and render result with error", () => {
cy.visit(`http://localhost:8080/${welcomeHrefUrl_it("en")}`);

cy.intercept("POST", /api\/postSendEmail/, {
fixture: "postSendEmail_aws_ses_ko",
statusCode: 400,
}).as("postSendEmail");

cy.get("#send-form__input").should(
"have.value",
"[email protected]",
);
cy.contains("SEND EMAIL TO").click();
cy.wait("@postSendEmail");
cy.get("#modal-send-email__result").should("be.visible");
});
});

// describe.only("delete", () => {
// before(() => {
// cy.wrap("asmdsdj").as("todo");
Expand Down
5 changes: 5 additions & 0 deletions cypress/fixtures/postSendEmail_aws_ses_ko.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"statusCode": 400,
"error": "Bad Request",
"message": "Email address is not verified. The following identities failed the check in region US-EAST-1: noreply@custom_domain.com"
}
15 changes: 15 additions & 0 deletions cypress/fixtures/postSendEmail_aws_ses_ok.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"envelope": {
"from": "noreply@custom_domain.com",
"to": [
"[email protected]"
]
},
"messageId": "<[email protected]>",
"response": "123456",
"raw": {
"type": "Buffer",
"data": [
]
}
}
Loading

0 comments on commit 77d0672

Please sign in to comment.