This repository contains the News Portal API, a backend application built with Node.js, Express, and Sequelize for managing news articles and categories, complete with JWT-based authentication.
This API provides endpoints for managing news articles, categories, and user authentication. The application uses Sequelize as the ORM to manage MySQL databases.
- Table Dependencies in Tests: Resolved dependency issues between
Category
andNews
tables by adding cascading deletion (onDelete: 'CASCADE'
). - Test Environment Configuration: Added a
config.js
to manage separate configurations fordevelopment
andtest
environments. - Automated Database Reset: The test suite begins by dropping all tables using
sequelize.drop()
. - Error Handling for Authentication: Updated the authentication controller to return specific error messages for invalid credentials.
Make sure you have the following installed:
- Node.js v18.8.0
- MySQL
- Sequelize CLI
Clone the repository and install dependencies:
git clone <repository-url>
cd <repository-folder>
npm install
Create the MySQL databases for development and testing as specified in config/config.js
. Set up your environment variables accordingly.
To run migrations and seed data:
npx sequelize-cli db:migrate
npx sequelize-cli db:seed:all
The test suite is built with Jest and Supertest.
To run the tests, ensure the test database is set up in config/config.js
, then run:
npm test
Create a .env
file with the following variables:
NODE_ENV=production
DB_HOST=<your-database-host>
DB_NAME=<your-database-name>
DB_USER=<your-database-username>
DB_PASS=<your-database-password>
JWT_SECRET=<your-jwt-secret>
PORT=3000
To deploy locally or on a server:
NODE_ENV=production node app.js
This project is open-source and available under the MIT License.