Skip to content

Latest commit

 

History

History
111 lines (84 loc) · 2.86 KB

README.md

File metadata and controls

111 lines (84 loc) · 2.86 KB

Blog App

A basic eCommerce application developed with Node.js, focusing on CRUD operations and showcasing automated testing using Jest. The application integrates a MongoDB database and demonstrates robust testing practices to ensure functionality.

Table of Contents

Features

  • Basic eCommerce functionality: -Create, read, update, and delete (CRUD) operations for products.
  • MongoDB Integration:
    • Stores and retrieves product data efficiently.
  • Testing with Jest:
    • Comprehensive testing for routes and database operations.
  • Environment-Specific Configurations:
    • Uses dotenv and cross-env for environment management.

Technologies Used

  • Node.js
  • Express.js
  • MongoDB (via mongoose)
  • Jest (testing framework)
  • Supertest (for HTTP assertions)
  • cross-env (for environment variable management)
  • dotenv (to manage environment variables)

Prerequisites

Ensure you have the following installed:

  • Node.js (v14 or higher)
  • MongoDB (local or hosted)
  • npm (comes with Node.js)

Installation

  1. Clone the repository:

    git clone /~https://github.com/kxng0109/test-app-using-jest.git
    cd test-app-using-jest
  2. Install dependencies:

    npm install
  3. Set up environment variables (see Environment Variables).

  4. Start the development server:

    npm run dev

Environment Variables

Create a .env file in the root directory with the following variables:

MONGODB_URI=<link_to_mongodb_database>
PORT=3000

Replace <link_to_mongodb_database> with the path to your mongoDB database Note: Never push your .env file to version control.

Usage

  1. Start the server:
npm start
  1. Use tools like Postman or curl to test API endpoints, or use the integrated Jest tests to validate functionality.

  2. Access the application via:

http://localhost:PORT

Note: "PORT" is set to 3000 by default.

  1. Use tools like Postman to test API endpoints.

Testing

The primary focus of this application is its testing capabilities. Testing is implemented using Jest and Supertest.

  1. To run all tests:
npm test
  1. Test scripts:
  • Unit tests: Validate individual functions and components.
  • Integration tests: Verify API endpoints and database interactions.

Test command

The test script sets the environment to test and executes Jest:

cross-env NODE_ENV=test jest --testTimeout=5000

License

This project is licensed under the MIT License - see the LICENSE file for details.