Skip to content
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

add type input #13

Merged
merged 5 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,27 @@ jobs:
- run: npm run lint
- run: npm run format:check
- run: npm test
deploy_staging:
runs-on: ubuntu-latest
needs: test
if: github.ref != 'refs/heads/main'
environment:
name: staging
url: https://staging.cinotify.cc/api/notify
steps:
- uses: actions/checkout@v4
- name: Deploy
run: npx wrangler deploy -e staging
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
deploy:
runs-on: ubuntu-latest
needs: test
if: github.ref == 'refs/heads/main'
environment: production
environment:
name: production
url: https://www.cinotify.cc/api/notify
steps:
- uses: actions/checkout@v4
- name: Deploy
Expand Down
4 changes: 2 additions & 2 deletions src/mail.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export const payload = ({ subject, to, body, attachments }) => ({
export const payload = ({ subject, to, type, body, attachments }) => ({
// https://docs.sendgrid.com/api-reference/mail-send/mail-send#body
attachments,
content: [
{
type: 'text/plain',
type: type ?? 'text/plain',
value: body ?? ' ',
},
],
Expand Down
8 changes: 7 additions & 1 deletion src/mail.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const fixture = {
attachments: input.attachments,
content: [
{
type: 'text/plain',
type: 'text/html',
value: input.body,
},
],
Expand Down Expand Up @@ -48,6 +48,12 @@ describe('mail', () => {
});

describe('payload', () => {
it('supports a type', () => {
input.type = 'text/html';
expect(payload(input).content[0].type).toBe('text/html');
input.type = 'text/plain';
expect(payload(input).content[0].type).toBe('text/plain');
});
it('supports multiple recipients', () => {
expect(
payload({ to: '[email protected],[email protected]' }).personalizations[0].to,
Expand Down
5 changes: 3 additions & 2 deletions src/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ export const input = {
filename: 'hello.txt',
},
],
body: 'this is the body',
body: '<h1>an html body</h1>',
subject: 'hello',
to: '[email protected]',
type: 'text/html',
};

export const inputUrlEncoded = `to=${input.to}&subject=${input.subject}&body=${input.body}&attachments[][type]=text/plain&attachments[][content]=aGVsbG8sIHdvcmxkIQ==&attachments[][filename]=hello.txt`;
export const inputUrlEncoded = `to=${input.to}&subject=${input.subject}&body=${input.body}&attachments[][type]=text/plain&attachments[][content]=aGVsbG8sIHdvcmxkIQ==&attachments[][filename]=hello.txt&type=text/html`;
5 changes: 5 additions & 0 deletions wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ compatibility_date = "2024-03-04"
compatibility_flags = ["nodejs_compat"]
routes = [
{ pattern = "www.cinotify.cc/api/*", zone_id = "8b83258726802e1e77310bd3b08dfefa" }
]

[env.staging]
routes = [
{ pattern = "staging.cinotify.cc/api/*", zone_id = "8b83258726802e1e77310bd3b08dfefa" }
]
Loading