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

Setup/template engine #7

Merged
merged 17 commits into from
Dec 22, 2020
Merged

Setup/template engine #7

merged 17 commits into from
Dec 22, 2020

Conversation

matthew-charles-chan
Copy link
Contributor

@matthew-charles-chan matthew-charles-chan commented Dec 21, 2020

Summary

  • install point-of-view
  • create createMessage function to create a email from a template with context
  • throw error if point-of-view is not registered
  • create test templates (ejs)

Notes

  • until PR for adding name to point-of-view is merged, registration of point-of-view is checked by testing for the .view fastify namespace.
  • once the PR, 'point-of-view' should be added to the polugin dependencies array, and the manual test should be removed.

Test Plan

  • install peer dependencies
$ npm i fastify-nodemailer point-of-view
  • in example.js, add mailguin api-key and domain
  • in index.js, add email recipient to createMessage function (line 15)
  • to verify createMessage created a messsage with inputed context and including fragments
    • in index.js after line 23, console.log the return value from create message
    console.log(message.html)
    
  • run example.js
$ npm run example -- -l info -w
  • Verify message is created with context

    • make GET request to /sendmail
    $ http localhost:3000/sendmail
    
    • verify message is sent without error
      • you should see response with message id
      {
      messageId: <messageId>
      }
      
    • verify message was created with context and including fragments
      • you should see the message.html logged:
      <!DOCTYPE html>
      <html lang="en">
        <head></head>
        <body>
          <header>            <-- verify header is included
            Sample header (ejs)
          </header>
          <br/>
          <p>Name: test</p>   <-- verify the name === inputed context ('test')
          <br/>
          <footer>            <-- verify footer is included
            Sample footer
          </footer>
        </body>
      </html>
      
  • verify plugin errors when point-of-view is not registered

    • in example.js comment out the popint-of-view registration (line 30)
    • run example.js
    $ npm run example -- -l info -w
    
    • you should see the following error:
    Error: The dependency "point-of-view" of plugin "fastify-mail" is not registered
    

index.js Outdated Show resolved Hide resolved
},
"devDependencies": {
"tap": "^14.0.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should start to think about adding tests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it. I created an issue for adding tests.

Co-authored-by: James Kirkpatrick <jkirkpat16@gmail.com>
@matthew-charles-chan matthew-charles-chan merged commit 5e2fed9 into main Dec 22, 2020
@matthew-charles-chan matthew-charles-chan linked an issue Dec 22, 2020 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Templating engine setup
2 participants