The Tool Rental Application is a web-based system that allows users to rent various tools by selecting tool codes, specifying checkout and return dates, and applying discounts. The application provides real-time rental agreements and ensures accurate calculation of rental charges, considering holidays and weekends. It also features robust backend logic and comprehensive end-to-end testing using Cypress.
- Users can select from a list of available tools using specific tool codes.
- The application allows specifying checkout and return dates and applying discounts.
- Upon submitting the rental details, a comprehensive Rental Agreement is generated, detailing charges, discount amounts, and final costs.
- The application handles holidays and weekends to ensure accurate billing.
- Various backend routes are set up to handle data fetching and processing of rental agreements.
- JSON data responses provide information on tool details, rental charges, and completed rental agreements.
- Comprehensive Cypress tests validate that the application functions correctly under various scenarios.
- Tests ensure that the backend routes and frontend form submission produce the expected outcomes.
This folder contains component tests that verify the functionality of individual parts of the application, ensuring core logic and utility functions behave as expected.
- RentalAgreement.test.ts: Validates the calculation and generation of rental agreements.
- ToolRental.test.tsx: Checks the frontend form input handling and overall user flow.
- ToolRentalCharges.tests.ts: Confirms that rental charges are correctly calculated based on tool type, dates, and discounts.
- Tools.test.ts: Verifies the tool data structure and ensures tool information is returned correctly.
The cypress/e2e
directory contains end-to-end tests that check the entire application flow:
-
RentalAgreement-test.cy.ts:
-
ToolRentalCharges-test.cy.ts:
-
Tools-test.cy.ts:
This file contains core utility functions that handle the logic of the tool rental application:
- toolData: Contains details about each tool, such as type, brand, daily charge, weekend, and holiday handling.
- isHoliday: Helper function to check if a date is a holiday.
- calculateChargeableDays: Calculates the number of days a tool is chargeable, considering weekends and holidays.
- formatDate and formatCurrency: Format helper functions for displaying dates and currency values.
The backend logic is separated into various route files, ensuring clear and modular code:
-
/api/checkout/route.ts:
- Processes POST requests for creating rental agreements.
- Validates inputs and calculates charges based on the provided tool code, dates, and discounts.
-
/api/tools/route.ts:
- Handles GET requests to fetch tool data.
- Returns JSON data with tool type, code, and brand.
-
/api/tool-rental-charges/route.ts:
- Handles GET requests to return daily charges for each tool.
- Provides data in JSON format for easy consumption by the frontend or external integrations.
-
page.tsx:
- The main frontend file of the application, displaying the form to input rental details.
- Includes error handling and data validation for user input.
- Submits form data to the backend and displays the returned Rental Agreement.
-
layout.tsx:
- Defines the overall layout of the application.
- Ensures consistency across the application's interface.
npm install
Run the Development Server:
bash
Copy code
npm run dev
This will start the server at http://localhost:3000.
Run Tests:
Component Tests:
bash
Copy code
npm run test
Cypress E2E Tests:
bash
Copy code
npx cypress open
From the Cypress dashboard, you can run individual end-to-end tests.