The Hotel Booking Web Application is designed to facilitate the process of finding and booking hotels. This platform allows users to search for available hotels, view details, and make reservations. Administrators can manage hotel listings, bookings, and user accounts to ensure a smooth operation.
- User Authentication: Secure login for users and admins.
- Hotel Management: Admins can add, update, and delete hotel listings.
- Booking System: Users can search, book, and manage reservations.
- Payment Integration: (Optional) Integration with payment gateways for online transactions.
- Search Functionality: Users can search hotels by location, price, and availability.
- Responsive Design: Optimized for both desktop and mobile devices.
- Frontend: HTML5, CSS3, JavaScript (React.js)
- Backend: Node.js, Express.js
- Database: MongoDB
- Authentication: JSON Web Tokens (JWT)
- Deployment: Docker, Heroku (or any preferred platform)
- Testing: Jest, Supertest
- Version Control: Git and GitHub
- Node.js (v14.x or later)
- Yarn (Package Manager)
- MongoDB (or a MongoDB Atlas account for cloud storage)
-
Clone the repository:
git clone https://github.com/abdurleone/alx-fullstack_project.git cd alx-fullstack_project
-
Install dependencies:
yarn install
-
Set up environment variables: Create a
.env
file in the root directory and add the following:http://localhost:2704/api http://localhost:3000/client http://localhost:3001/admin MONGO_URI= MONGO = mongodb+srv://abdurleone:[email protected]/ JWT_SECRET=your_jwt_secret
-
Start the application:
yarn start
The application will be available at
http://localhost:3000
.
-
Accessing the Application:
- Open a web browser and go to
http://localhost:3000
.
- Open a web browser and go to
-
User Registration and Login:
- Users can register for an account or log in if they already have one.
-
Searching for Hotels:
- Use the search functionality to find hotels by location, date, and price.
-
Booking a Room:
- Users can select a hotel, choose available rooms, and complete the booking process.
-
Admin Management:
- Admins can log in to manage hotel listings, bookings, and user accounts.
We use Jest for unit testing and Supertest for testing our API endpoints.
-
Install Jest and Supertest:
If you haven’t installed these libraries already, run:
yarn add jest supertest --dev
-
Add a
test
script to yourpackage.json
:{ "scripts": { "test": "jest" } }
-
Write Unit Tests:
Create a folder named
tests
in your project root and write unit test files for your backend API.Example of a test for the authentication route (
tests/auth.test.js
):const request = require('supertest'); const app = require('../app'); // Your Express app describe('POST /api/auth/login', () => { it('should return a JWT token when login is successful', async () => { const res = await request(app) .post('/api/auth/login') .send({ email: '[email protected]', password: 'password123', }); expect(res.statusCode).toEqual(200); expect(res.body).toHaveProperty('token'); }); it('should return 400 if login details are incorrect', async () => { const res = await request(app) .post('/api/auth/login') .send({ email: '[email protected]', password: 'wrongpassword', }); expect(res.statusCode).toEqual(400); }); });
-
Run the Tests:
Run the following command to execute your tests:
yarn test
The output of the tests will show whether your routes, models, and logic work correctly:
PASS tests/auth.test.js
POST /api/auth/login
✓ should return a JWT token when login is successful (44 ms)
✓ should return 400 if login details are incorrect (32 ms)
Test Suites: 1 passed, 1 total
Tests: 2 passed, 2 total
Snapshots: 0 total
Time: 1.784 s
Ran all test suites.
The API is built using RESTful principles. Here are some key endpoints:
- POST /api/auth/register: Register a new user.
- POST /api/auth/login: Log in and receive a JWT for authentication.
- GET /api/hotels: Retrieve all hotel listings.
- POST /api/hotels: Create a new hotel listing (admin only).
- GET /api/hotels/:id: Retrieve a specific hotel by ID.
- PUT /api/hotels/:id: Update a specific hotel listing (admin only).
- DELETE /api/hotels/:id: Delete a specific hotel listing (admin only).
- POST /api/bookings: Create a new booking.
- GET /api/bookings/:id: Retrieve a specific booking by ID.
Here’s an example of how to create a new hotel listing using curl
:
curl -X POST http://localhost:3000/api/hotels \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-H "Content-Type: application/json" \
-d '{"name": "Grand Hotel", "location": "Paris", "rooms": 100, "pricePerNight": 150}'
We welcome contributions! To contribute to this project, please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature/YourFeature
). - Make your changes and commit them (
git commit -m "Add some feature"
). - Push to the branch (
git push origin feature/YourFeature
). - Open a Pull Request.
This project is licensed under the MIT License. See the LICENSE file for details.
- Added Testing section in the README with provisions for Jest and Supertest.
- Included instructions on how to install testing libraries, write unit tests, and run them using yarn.
- Provided an example of unit tests for an authentication route.