mirror of
https://github.com/hanzoai/calendar.git
synced 2026-10-30 14:46:43 +00:00
* add eslint config * migrate autoLock to features * migrate teamService to features * migrate userCreationService * migrate insights services to features * migrate ProfileRepository * update imports * migrate filter segmen tests * migrate filter segment repository * migrate getBusyTimes * migrate getLocaleFromRequest * refactor csvUtils * make filename clearer * migrate getLuckyUser integration test * migrate autoLock test to features * wip * refactors * migrate useBookerUrl * migrate more * wip * Migrate eventTypeRepository * membership repository * update imports * update imports * migrate * move organization repository * update imports * update imports * wip * wip * wip * wip * wip * wip * wip * wip * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix tests * fix type checks * fix * fix * migrate * update imports * fix tests * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix
257 lines
8.2 KiB
TypeScript
257 lines
8.2 KiB
TypeScript
import prismaMock from "../../../../tests/libs/__mocks__/prisma";
|
|
|
|
import { describe, it, expect, beforeEach, vi } from "vitest";
|
|
|
|
import { BookingStatus, RRTimestampBasis } from "@calcom/prisma/enums";
|
|
|
|
import { BookingRepository } from "./BookingRepository";
|
|
|
|
const createAttendeeNoShowTestBookings = async () => {
|
|
await Promise.all([
|
|
prismaMock.booking.create({
|
|
data: {
|
|
userId: 1,
|
|
uid: "123",
|
|
eventTypeId: 1,
|
|
status: BookingStatus.ACCEPTED,
|
|
attendees: {
|
|
create: {
|
|
email: "[email protected]",
|
|
noShow: false,
|
|
name: "Test 1",
|
|
timeZone: "America/Toronto",
|
|
},
|
|
},
|
|
startTime: new Date("2025-05-01T00:00:00.000Z"),
|
|
endTime: new Date("2025-05-01T01:00:00.000Z"),
|
|
title: "Test Event",
|
|
},
|
|
}),
|
|
prismaMock.booking.create({
|
|
data: {
|
|
userId: 1,
|
|
uid: "123",
|
|
eventTypeId: 1,
|
|
status: BookingStatus.ACCEPTED,
|
|
attendees: {
|
|
create: {
|
|
email: "[email protected]",
|
|
noShow: true,
|
|
name: "Test 1",
|
|
timeZone: "America/Toronto",
|
|
},
|
|
},
|
|
startTime: new Date("2025-05-01T00:00:00.000Z"),
|
|
endTime: new Date("2025-05-01T01:00:00.000Z"),
|
|
title: "Test Event",
|
|
},
|
|
}),
|
|
]);
|
|
};
|
|
|
|
const createHostNoShowTestBookings = async () => {
|
|
await Promise.all([
|
|
prismaMock.booking.create({
|
|
data: {
|
|
userId: 1,
|
|
uid: "123",
|
|
eventTypeId: 1,
|
|
status: BookingStatus.ACCEPTED,
|
|
attendees: {
|
|
create: {
|
|
email: "[email protected]",
|
|
noShow: false,
|
|
name: "Test 1",
|
|
timeZone: "America/Toronto",
|
|
},
|
|
},
|
|
startTime: new Date("2025-05-01T00:00:00.000Z"),
|
|
endTime: new Date("2025-05-01T01:00:00.000Z"),
|
|
title: "Test Event",
|
|
noShowHost: false,
|
|
},
|
|
}),
|
|
prismaMock.booking.create({
|
|
data: {
|
|
userId: 1,
|
|
uid: "123",
|
|
eventTypeId: 1,
|
|
status: BookingStatus.ACCEPTED,
|
|
attendees: {
|
|
create: {
|
|
email: "[email protected]",
|
|
noShow: false,
|
|
name: "Test 1",
|
|
timeZone: "America/Toronto",
|
|
},
|
|
},
|
|
startTime: new Date("2025-05-01T00:00:00.000Z"),
|
|
endTime: new Date("2025-05-01T01:00:00.000Z"),
|
|
title: "Test Event",
|
|
noShowHost: true,
|
|
},
|
|
}),
|
|
]);
|
|
};
|
|
|
|
describe("BookingRepository", () => {
|
|
beforeEach(() => {
|
|
vi.setSystemTime(new Date("2025-05-01T00:00:00.000Z"));
|
|
vi.resetAllMocks();
|
|
});
|
|
describe("getAllBookingsForRoundRobin", () => {
|
|
describe("includeNoShowInRRCalculation", () => {
|
|
it("it should not include bookings where the attendee is a no show", async () => {
|
|
await createAttendeeNoShowTestBookings();
|
|
|
|
const bookingRepo = new BookingRepository(prismaMock);
|
|
const bookings = await bookingRepo.getAllBookingsForRoundRobin({
|
|
users: [{ id: 1, email: "[email protected]" }],
|
|
eventTypeId: 1,
|
|
startDate: new Date(),
|
|
endDate: new Date(),
|
|
includeNoShowInRRCalculation: false,
|
|
virtualQueuesData: null,
|
|
});
|
|
|
|
expect(bookings).toHaveLength(1);
|
|
});
|
|
it("it should include bookings where the attendee is a no show", async () => {
|
|
await createAttendeeNoShowTestBookings();
|
|
|
|
const bookingRepo = new BookingRepository(prismaMock);
|
|
const bookings = await bookingRepo.getAllBookingsForRoundRobin({
|
|
users: [{ id: 1, email: "[email protected]" }],
|
|
eventTypeId: 1,
|
|
startDate: new Date(),
|
|
endDate: new Date(),
|
|
includeNoShowInRRCalculation: true,
|
|
virtualQueuesData: null,
|
|
});
|
|
|
|
expect(bookings).toHaveLength(2);
|
|
});
|
|
it("it should not include bookings where the host is a no show", async () => {
|
|
await createHostNoShowTestBookings();
|
|
|
|
const bookingRepo = new BookingRepository(prismaMock);
|
|
const bookings = await bookingRepo.getAllBookingsForRoundRobin({
|
|
users: [{ id: 1, email: "[email protected]" }],
|
|
eventTypeId: 1,
|
|
startDate: new Date(),
|
|
endDate: new Date(),
|
|
includeNoShowInRRCalculation: false,
|
|
virtualQueuesData: null,
|
|
});
|
|
|
|
expect(bookings).toHaveLength(1);
|
|
});
|
|
it("it should include bookings where the host is a no show", async () => {
|
|
await createHostNoShowTestBookings();
|
|
|
|
const bookingRepo = new BookingRepository(prismaMock);
|
|
const bookings = await bookingRepo.getAllBookingsForRoundRobin({
|
|
users: [{ id: 1, email: "[email protected]" }],
|
|
eventTypeId: 1,
|
|
startDate: new Date(),
|
|
endDate: new Date(),
|
|
includeNoShowInRRCalculation: true,
|
|
virtualQueuesData: null,
|
|
});
|
|
|
|
expect(bookings).toHaveLength(2);
|
|
});
|
|
it("it should not include bookings where the host or an attendee is a no show", async () => {
|
|
await createHostNoShowTestBookings();
|
|
await createAttendeeNoShowTestBookings();
|
|
|
|
const bookingRepo = new BookingRepository(prismaMock);
|
|
const bookings = await bookingRepo.getAllBookingsForRoundRobin({
|
|
users: [{ id: 1, email: "[email protected]" }],
|
|
eventTypeId: 1,
|
|
startDate: new Date(),
|
|
endDate: new Date(),
|
|
includeNoShowInRRCalculation: false,
|
|
virtualQueuesData: null,
|
|
});
|
|
|
|
expect(bookings).toHaveLength(2);
|
|
});
|
|
it("it should include bookings where the host or an attendee is a no show", async () => {
|
|
await createHostNoShowTestBookings();
|
|
await createAttendeeNoShowTestBookings();
|
|
|
|
const bookingRepo = new BookingRepository(prismaMock);
|
|
const bookings = await bookingRepo.getAllBookingsForRoundRobin({
|
|
users: [{ id: 1, email: "[email protected]" }],
|
|
eventTypeId: 1,
|
|
startDate: new Date(),
|
|
endDate: new Date(),
|
|
includeNoShowInRRCalculation: true,
|
|
virtualQueuesData: null,
|
|
});
|
|
|
|
expect(bookings).toHaveLength(4);
|
|
});
|
|
});
|
|
it("should use start time as timestamp basis for the booking count", async () => {
|
|
await Promise.all([
|
|
prismaMock.booking.create({
|
|
data: {
|
|
userId: 1,
|
|
uid: "booking_may",
|
|
eventTypeId: 1,
|
|
status: BookingStatus.ACCEPTED,
|
|
attendees: {
|
|
create: {
|
|
email: "[email protected]",
|
|
noShow: false,
|
|
name: "Test 1",
|
|
timeZone: "America/Toronto",
|
|
},
|
|
},
|
|
startTime: new Date("2025-05-26T00:00:00.000Z"),
|
|
endTime: new Date("2025-05-26T01:00:00.000Z"),
|
|
createdAt: new Date("2025-05-03T00:00:00.000Z"),
|
|
title: "Test Event",
|
|
},
|
|
}),
|
|
prismaMock.booking.create({
|
|
data: {
|
|
userId: 1,
|
|
uid: "booking_june",
|
|
eventTypeId: 1,
|
|
status: BookingStatus.ACCEPTED,
|
|
attendees: {
|
|
create: {
|
|
email: "[email protected]",
|
|
noShow: true,
|
|
name: "Test 1",
|
|
timeZone: "America/Toronto",
|
|
},
|
|
},
|
|
startTime: new Date("2025-06-26T00:00:00.000Z"),
|
|
endTime: new Date("2025-06-26T01:00:00.000Z"),
|
|
createdAt: new Date("2025-05-03T00:00:00.000Z"),
|
|
title: "Test Event",
|
|
},
|
|
}),
|
|
]);
|
|
|
|
const bookingRepo = new BookingRepository(prismaMock);
|
|
const bookings = await bookingRepo.getAllBookingsForRoundRobin({
|
|
users: [{ id: 1, email: "[email protected]" }],
|
|
eventTypeId: 1,
|
|
startDate: new Date("2025-06-01T00:00:00.000Z"),
|
|
endDate: new Date("2025-06-30T23:59:00.000Z"),
|
|
includeNoShowInRRCalculation: true,
|
|
virtualQueuesData: null,
|
|
rrTimestampBasis: RRTimestampBasis.START_TIME,
|
|
});
|
|
|
|
expect(bookings).toHaveLength(1);
|
|
expect(bookings[0].startTime.toISOString()).toBe(new Date("2025-06-26T00:00:00.000Z").toISOString());
|
|
});
|
|
});
|
|
});
|