diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 0bf6435..9b9b429 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -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 diff --git a/src/mail.js b/src/mail.js index e84fd4a..d18f3f4 100644 --- a/src/mail.js +++ b/src/mail.js @@ -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 ?? ' ', }, ], diff --git a/src/mail.test.js b/src/mail.test.js index 3bf0290..4247d16 100644 --- a/src/mail.test.js +++ b/src/mail.test.js @@ -7,7 +7,7 @@ const fixture = { attachments: input.attachments, content: [ { - type: 'text/plain', + type: 'text/html', value: input.body, }, ], @@ -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: 'one@example.com,two@example.com' }).personalizations[0].to, diff --git a/src/test.js b/src/test.js index d1f2b02..3df2830 100644 --- a/src/test.js +++ b/src/test.js @@ -6,9 +6,10 @@ export const input = { filename: 'hello.txt', }, ], - body: 'this is the body', + body: '