Fastify TypeScript MongoDB Jest Tutorial
What you'll learn:
- fastify typescript setup with jest for unit and integration tests
- establish a CI integration pipeline with GitHub actions
- discussion of how to integrate with a CD pipeline as well, but will not be implemented
- run a local instance of a mongodb replica set to develop against, using docker-compose
- run a mongodb replica set in your CI build, along with integration tests that use it for continuous integration testing
- build a robust API with fastify, along with swagger documentation
- establish good patterns for validating your data coming into your api
- understanding how access patterns to your API affect decisions about your data models
- using test driven development to build your features and be certain of the changes you're making
What you need:
- node.js 14-lts
- docker installed
Checkout this repo: https://github.com/wolfejw86/fastify-mongo-typescript-jest-tutorial
Each branch is a different stage of the tutorial, making it easy to pickup at any relevant part!
Segments
Getting Started
What we'll be building:
An API to create/read/update/delete notes! The data model is intentionally simple (notes) so that you can focus on learning the required technologies required to build an API to support a "notes" use case, using node.js, fastify, mongodb, swagger, and github actions.
We will be using fastify-cli to get started. You can create from scratch or just follow along.
Utilizing Our New Project Structure
Setting up our app's configuration
- .env
- appconfig
Setting up autogenerated swagger
- fastify-oas
Validating our inputs to our API routes
- jsonschema
Running our tests in a Github Action
- simple github actions file
Running our database locally
- intro local mongo replica in docker-compose repo
Running our database in the Github Action
- show how you can run mongo in gh action
Connect to mongo from fastify with mongoose
- establish connection in plugin
Ensuring our test runs in our CI environment against our database
- add test for it
- update actions file
- show test running in github action
Creating users for our app with fastify-passport and github login + tests
- configure passport + secure-session
- user schema + endpoint
- tests - show running in github action http://www.passportjs.org/packages/passport-github2/ https://github.com/cfsghost/passport-github/blob/master/examples/login/app.js https://www.youtube.com/watch?v=XRcQQWU0XOM