Skip to content

Commit

Permalink
Merge pull request #52 from w3bdesign/backend
Browse files Browse the repository at this point in the history
Increase test coverage
  • Loading branch information
w3bdesign authored Nov 22, 2024
2 parents 36ee51b + 8c03ba8 commit d4d3496
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions backend/src/bookings/bookings.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe('BookingsService', () => {
save: jest.fn(),
findOne: jest.fn(),
find: jest.fn(),
count: jest.fn(),
};

const mockUsersService = {
Expand Down Expand Up @@ -250,6 +251,24 @@ describe('BookingsService', () => {
order: { startTime: 'ASC' },
});
});

it('should handle case when no upcoming bookings are found', async () => {
// First find call returns empty array (no upcoming bookings)
mockBookingRepository.find.mockResolvedValueOnce([]);

// Second find call returns some sample bookings for debug logging
const sampleBookings = [
{ id: 'booking-1', startTime: new Date(), status: BookingStatus.CANCELLED },
{ id: 'booking-2', startTime: new Date(), status: BookingStatus.COMPLETED },
{ id: 'booking-3', startTime: new Date(), status: BookingStatus.PENDING },
];
mockBookingRepository.find.mockResolvedValueOnce(sampleBookings);

const result = await service.findUpcoming();

expect(result).toEqual([]);
expect(mockBookingRepository.find).toHaveBeenCalledTimes(2);
});
});

describe('findOne', () => {
Expand All @@ -273,4 +292,29 @@ describe('BookingsService', () => {
);
});
});

describe('getUpcomingCount', () => {
it('should return count of upcoming bookings', async () => {
mockBookingRepository.count.mockResolvedValue(5);

const result = await service.getUpcomingCount();

expect(result).toBe(5);
expect(mockBookingRepository.count).toHaveBeenCalledWith({
where: {
startTime: expect.any(Object),
status: In([BookingStatus.PENDING, BookingStatus.CONFIRMED]),
},
});
});

it('should return 0 when no upcoming bookings exist', async () => {
mockBookingRepository.count.mockResolvedValue(0);

const result = await service.getUpcomingCount();

expect(result).toBe(0);
expect(mockBookingRepository.count).toHaveBeenCalled();
});
});
});

0 comments on commit d4d3496

Please sign in to comment.