Skip to content

Commit

Permalink
add type input (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
jshawl authored Mar 22, 2024
1 parent 96f4d81 commit e18328f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
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" }
]

0 comments on commit e18328f

Please sign in to comment.