This is a technical test project created as part of the application process for a Software engineer position. This project is built with typescript and has the following simple features:
- Create User
- Update User
- Delete User
- Cronjob every hour
- Queue to send emails according to timezone
- Node.js version 20 and above.
- MySQL
- Redis
Clone or download this project
git clone https://github.com/muhaliusman/typescript-sdt-assessment
Enter to the project directory
cd typescript-sdt-assessment
Install dependency
npm install
copy .env.example and rename it to .env for development
cp .env.example .env
create a database and change environment variables and adjust them to your own
# sample
APP_PORT=3000
DB_HOST=localhost
DB_USER=user
DB_PASSWORD=password
DB_NAME=db_name
DB_PORT=3306
REDIS_HOST=localhost
REDIS_PORT=6379
EMAIL_ENDPOINT=https://fake-endpoint/send-email
run migration to set initial tables
npm run migration:run:dev
Run the application
npm run dev #for hot reload
or
npm run start
after running the application you can check the API documentation via http://localhost:3000 there are only 3 endpoint
- POST: /api/users : to create new user
- PUT: /api/users/{id} : to update user
- Delete: /api/users/{id} : to delete user
{
firstName!: string
lastName!: string
location!: string # Iana timezone,
birthday!: date # YYYY-MM-DD
email!: string
}
location us IANA timezone name for example Asia/Jakarta please refer to this wikipedia
in this project i use cron that runs every hour and fetches data from database based on user location. then the data will be sent to queue to handle sending email (fake) to users. Flow:
- cron runs every hour and fetches user data in whose area it is 9 am
- Cron will send the data to bullmq.
- The worker will take the queue and send it to the user's email
- If the delivery fails, the queue will be retried 3 times using the exponential backoff method
- If after the retry it still fails, the data will be kept in the database and will be tried to be sent again the next day
- This process will repeat for 3 days, and if it still fails, it will be sent next year
For more details, please see this diagram:
NOTE : it is necessary to run the worker so that the queue can be consumed.
npm run worker:dev # in development env
npm run worket # in production
There are 2 tests in this project.
- Unit test
npm t
- End to End Testing For this test you need to setup database and also redis. You can change it in .env.test after that just run
npm run test:e2e