fixed tests

This commit is contained in:
jackiettran
2026-01-03 21:19:23 -05:00
parent 493921b723
commit e408880cae
3 changed files with 83 additions and 28 deletions

View File

@@ -268,6 +268,14 @@ describe('Rentals Routes', () => {
});
describe('POST /', () => {
// Helper to generate future dates for testing
const getFutureDate = (daysFromNow, hours = 10) => {
const date = new Date();
date.setDate(date.getDate() + daysFromNow);
date.setHours(hours, 0, 0, 0);
return date.toISOString();
};
const mockItem = {
id: 1,
name: 'Test Item',
@@ -295,10 +303,11 @@ describe('Rentals Routes', () => {
renter: { id: 1, username: 'renter1', firstName: 'Alice', lastName: 'Johnson' },
};
// Use dynamic future dates to avoid "Start date cannot be in the past" errors
const rentalData = {
itemId: 1,
startDateTime: '2024-01-15T10:00:00.000Z',
endDateTime: '2024-01-15T18:00:00.000Z',
startDateTime: getFutureDate(7, 10), // 7 days from now at 10:00
endDateTime: getFutureDate(7, 18), // 7 days from now at 18:00
deliveryMethod: 'pickup',
deliveryAddress: null,
stripePaymentMethodId: 'pm_test123',
@@ -328,7 +337,7 @@ describe('Rentals Routes', () => {
const dailyRentalData = {
...rentalData,
endDateTime: '2024-01-17T18:00:00.000Z', // 3 days
endDateTime: getFutureDate(10, 18), // 3 days from start (7 + 3 = 10 days from now)
};
const response = await request(app)