mirror of
https://github.com/hanzoai/calendar.git
synced 2026-09-24 22:42:24 +00:00
192 lines
5.8 KiB
TypeScript
192 lines
5.8 KiB
TypeScript
import prismock from "../../../../../tests/libs/__mocks__/prisma";
|
|
|
|
import {
|
|
createBookingScenario,
|
|
getScenarioData,
|
|
getGoogleCalendarCredential,
|
|
TestData,
|
|
getOrganizer,
|
|
mockSuccessfulVideoMeetingCreation,
|
|
mockCalendarToHaveNoBusySlots,
|
|
mockNoTranslations,
|
|
} from "@calcom/web/test/utils/bookingScenario/bookingScenario";
|
|
|
|
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
|
|
import type { CreateInstantBookingData } from "../dto/types";
|
|
import { getInstantBookingCreateService } from "../../di/InstantBookingCreateService.container";
|
|
import { BookingStatus } from "@calcom/prisma/enums";
|
|
|
|
vi.mock("@calcom/features/notifications/sendNotification", () => ({
|
|
sendNotification: vi.fn(),
|
|
}));
|
|
|
|
vi.mock("@calcom/features/conferencing/lib/videoClient", () => ({
|
|
createInstantMeetingWithCalVideo: vi.fn().mockResolvedValue({
|
|
type: "daily_video",
|
|
id: "MOCK_INSTANT_MEETING_ID",
|
|
password: "MOCK_INSTANT_PASS",
|
|
url: "http://mock-dailyvideo.example.com/instant-meeting-url",
|
|
}),
|
|
}));
|
|
|
|
describe("handleInstantMeeting", () => {
|
|
beforeEach(() => {
|
|
mockNoTranslations();
|
|
});
|
|
describe("team event instant meeting", () => {
|
|
it("should successfully create instant meeting for team event", async () => {
|
|
const instantBookingCreateService = getInstantBookingCreateService();
|
|
const organizer = getOrganizer({
|
|
name: "Organizer",
|
|
email: "[email protected]",
|
|
id: 101,
|
|
schedules: [TestData.schedules.IstWorkHours],
|
|
credentials: [getGoogleCalendarCredential()],
|
|
selectedCalendars: [TestData.selectedCalendars.google],
|
|
});
|
|
|
|
const { dateString: plus1DateString } = getDate({ dateIncrement: 1 });
|
|
|
|
await createBookingScenario(
|
|
getScenarioData({
|
|
eventTypes: [
|
|
{
|
|
id: 1,
|
|
slotInterval: 45,
|
|
length: 45,
|
|
users: [
|
|
{
|
|
id: 101,
|
|
},
|
|
],
|
|
team: {
|
|
id: 1,
|
|
},
|
|
instantMeetingExpiryTimeOffsetInSeconds: 90,
|
|
},
|
|
],
|
|
organizer,
|
|
apps: [TestData.apps["daily-video"], TestData.apps["google-calendar"]],
|
|
})
|
|
);
|
|
|
|
mockSuccessfulVideoMeetingCreation({
|
|
metadataLookupKey: "dailyvideo",
|
|
videoMeetingData: {
|
|
id: "MOCK_ID",
|
|
password: "MOCK_PASS",
|
|
url: `http://mock-dailyvideo.example.com/meeting-1`,
|
|
},
|
|
});
|
|
mockCalendarToHaveNoBusySlots("googlecalendar", {
|
|
create: {
|
|
uid: "MOCKED_GOOGLE_CALENDAR_EVENT_ID",
|
|
},
|
|
});
|
|
|
|
const mockBookingData: CreateInstantBookingData = {
|
|
eventTypeId: 1,
|
|
timeZone: "UTC",
|
|
language: "en",
|
|
start: `${plus1DateString}T04:00:00.000Z`,
|
|
end: `${plus1DateString}T04:45:00.000Z`,
|
|
responses: {
|
|
name: "Test User",
|
|
email: "[email protected]",
|
|
attendeePhoneNumber: "+918888888888",
|
|
},
|
|
metadata: {},
|
|
instant: true,
|
|
};
|
|
|
|
const result = await instantBookingCreateService.createBooking({
|
|
bookingData: mockBookingData,
|
|
});
|
|
|
|
expect(result.message).toBe("Success");
|
|
expect(result.bookingId).toBeDefined();
|
|
expect(result.bookingUid).toBeDefined();
|
|
expect(result.meetingTokenId).toBeDefined();
|
|
expect(result.expires).toBeInstanceOf(Date);
|
|
|
|
const booking = await prismock.booking.findUnique({
|
|
where: { id: result.bookingId },
|
|
select: { status: true, attendees: true, references: true },
|
|
});
|
|
|
|
expect(booking).toBeDefined();
|
|
expect(booking?.status).toBe(BookingStatus.AWAITING_HOST);
|
|
expect(booking?.attendees).toHaveLength(1);
|
|
expect(booking?.attendees[0].email).toBe("[email protected]");
|
|
expect(booking?.attendees[0].phoneNumber).toBe("+918888888888");
|
|
expect(booking?.references).toHaveLength(1);
|
|
expect(booking?.references[0].type).toBe("daily_video");
|
|
});
|
|
|
|
it("should throw error for non-team event types", async () => {
|
|
const instantBookingCreateService = getInstantBookingCreateService();
|
|
const organizer = getOrganizer({
|
|
name: "Organizer",
|
|
email: "[email protected]",
|
|
id: 101,
|
|
schedules: [TestData.schedules.IstWorkHours],
|
|
credentials: [getGoogleCalendarCredential()],
|
|
selectedCalendars: [TestData.selectedCalendars.google],
|
|
});
|
|
|
|
const { dateString: plus1DateString } = getDate({ dateIncrement: 1 });
|
|
|
|
await createBookingScenario(
|
|
getScenarioData({
|
|
eventTypes: [
|
|
{
|
|
id: 1,
|
|
slotInterval: 45,
|
|
length: 45,
|
|
users: [
|
|
{
|
|
id: 101,
|
|
},
|
|
],
|
|
},
|
|
],
|
|
organizer,
|
|
apps: [TestData.apps["daily-video"], TestData.apps["google-calendar"]],
|
|
})
|
|
);
|
|
|
|
const mockBookingData: CreateInstantBookingData = {
|
|
eventTypeId: 1,
|
|
timeZone: "UTC",
|
|
language: "en",
|
|
start: `${plus1DateString}T04:00:00.000Z`,
|
|
end: `${plus1DateString}T04:45:00.000Z`,
|
|
responses: {
|
|
name: "Test User",
|
|
email: "[email protected]",
|
|
attendeePhoneNumber: "+918888888888",
|
|
},
|
|
metadata: {},
|
|
instant: true,
|
|
};
|
|
|
|
await expect(
|
|
instantBookingCreateService.createBooking({
|
|
bookingData: mockBookingData,
|
|
})
|
|
).rejects.toThrow("Only Team Event Types are supported for Instant Meeting");
|
|
});
|
|
});
|
|
});
|
|
|
|
function getDate(param: { dateIncrement?: number } = {}) {
|
|
const { dateIncrement = 0 } = param;
|
|
const date = new Date();
|
|
date.setDate(date.getDate() + dateIncrement);
|
|
return {
|
|
date,
|
|
dateString: date.toISOString().split("T")[0],
|
|
};
|
|
}
|