moved private information, test fixes

This commit is contained in:
jackiettran
2025-11-06 17:56:12 -05:00
parent 2ee4b5c389
commit 066ad4a3fe
6 changed files with 263 additions and 165 deletions

View File

@@ -21,6 +21,39 @@ jest.mock('../../../middleware/auth', () => ({
req.user = { id: 1 };
next();
}),
requireVerifiedEmail: jest.fn((req, res, next) => next()),
}));
jest.mock('../../../utils/rentalDurationCalculator', () => ({
calculateRentalCost: jest.fn(() => 100),
}));
jest.mock('../../../services/emailService', () => ({
sendRentalRequestEmail: jest.fn(),
sendRentalApprovalEmail: jest.fn(),
sendRentalDeclinedEmail: jest.fn(),
sendRentalCompletedEmail: jest.fn(),
sendRentalCancelledEmail: jest.fn(),
sendDamageReportEmail: jest.fn(),
sendLateReturnNotificationEmail: jest.fn(),
}));
jest.mock('../../../utils/logger', () => ({
withRequestId: jest.fn(() => ({
error: jest.fn(),
warn: jest.fn(),
info: jest.fn(),
})),
}));
jest.mock('../../../services/lateReturnService', () => ({
calculateLateFee: jest.fn(),
processLateReturn: jest.fn(),
}));
jest.mock('../../../services/damageAssessmentService', () => ({
assessDamage: jest.fn(),
processDamageFee: jest.fn(),
}));
jest.mock('../../../utils/feeCalculator', () => ({
@@ -47,6 +80,7 @@ jest.mock('../../../services/stripeService', () => ({
const { Rental, Item, User } = require('../../../models');
const FeeCalculator = require('../../../utils/feeCalculator');
const RentalDurationCalculator = require('../../../utils/rentalDurationCalculator');
const RefundService = require('../../../services/refundService');
const StripeService = require('../../../services/stripeService');
@@ -267,6 +301,8 @@ describe('Rentals Routes', () => {
});
it('should create a new rental with hourly pricing', async () => {
RentalDurationCalculator.calculateRentalCost.mockReturnValue(80); // 8 hours * 10/hour
const response = await request(app)
.post('/rentals')
.send(rentalData);
@@ -277,6 +313,8 @@ describe('Rentals Routes', () => {
});
it('should create a new rental with daily pricing', async () => {
RentalDurationCalculator.calculateRentalCost.mockReturnValue(150); // 3 days * 50/day
const dailyRentalData = {
...rentalData,
endDateTime: '2024-01-17T18:00:00.000Z', // 3 days
@@ -324,6 +362,8 @@ describe('Rentals Routes', () => {
});
it('should return 400 when payment method is missing for paid rentals', async () => {
RentalDurationCalculator.calculateRentalCost.mockReturnValue(100); // Paid rental
const dataWithoutPayment = { ...rentalData };
delete dataWithoutPayment.stripePaymentMethodId;
@@ -336,6 +376,8 @@ describe('Rentals Routes', () => {
});
it('should create a free rental without payment method', async () => {
RentalDurationCalculator.calculateRentalCost.mockReturnValue(0); // Free rental
// Set up a free item (both prices are 0)
Item.findByPk.mockResolvedValue({
id: 1,
@@ -433,6 +475,11 @@ describe('Rentals Routes', () => {
StripeService.chargePaymentMethod.mockResolvedValue({
paymentIntentId: 'pi_test123',
paymentMethod: {
brand: 'visa',
last4: '4242'
},
chargedAt: new Date('2024-01-15T10:00:00.000Z')
});
const updatedRental = {
@@ -461,6 +508,9 @@ describe('Rentals Routes', () => {
status: 'confirmed',
paymentStatus: 'paid',
stripePaymentIntentId: 'pi_test123',
paymentMethodBrand: 'visa',
paymentMethodLast4: '4242',
chargedAt: new Date('2024-01-15T10:00:00.000Z'),
});
});