refactor: use BookingReference instead of DailyEventReference (#3667)
* refactor: use BookingReference instead of DailyEventReference * refactor: migrate DailyEventReference records to BookingReference * refactor: drop DailyEventReference table * fix linting * Daily Video API adapter fixes Co-authored-by: zomars <[email protected]>
This commit is contained in:
1 parent
14f0c30584
commit
6d79f80928
17 files changed
+426
-370
No files matched your search
@@ -1,4 +1,3 @@
|
||||
import { Person } from "ics";
|
||||
import short from "short-uuid";
|
||||
import { v5 as uuidv5 } from "uuid";
|
||||
|
||||
@@ -83,22 +82,25 @@ export const getDescription = (calEvent: CalendarEvent) => {
|
||||
`;
|
||||
};
|
||||
export const getLocation = (calEvent: CalendarEvent) => {
|
||||
let providerName = "";
|
||||
const meetingUrl = getVideoCallUrl(calEvent);
|
||||
if (meetingUrl) {
|
||||
return meetingUrl;
|
||||
}
|
||||
const providerName = getProviderName(calEvent);
|
||||
return providerName || calEvent.location || "";
|
||||
};
|
||||
|
||||
export const getProviderName = (calEvent: CalendarEvent): string => {
|
||||
// TODO: use getAppName from @calcom/app-store
|
||||
if (calEvent.location && calEvent.location.includes("integrations:")) {
|
||||
const location = calEvent.location.split(":")[1];
|
||||
providerName = location[0].toUpperCase() + location.slice(1);
|
||||
return location[0].toUpperCase() + location.slice(1);
|
||||
}
|
||||
|
||||
if (calEvent.videoCallData) {
|
||||
return calEvent.videoCallData.url;
|
||||
// If location its a url, probably we should be validating it with a custom library
|
||||
if (calEvent.location && /^https?:\/\//.test(calEvent.location)) {
|
||||
return calEvent.location;
|
||||
}
|
||||
|
||||
if (calEvent.additionalInformation?.hangoutLink) {
|
||||
return calEvent.additionalInformation.hangoutLink;
|
||||
}
|
||||
|
||||
return providerName || calEvent.location || "";
|
||||
return "";
|
||||
};
|
||||
|
||||
export const getManageLink = (calEvent: CalendarEvent) => {
|
||||
@@ -150,3 +152,28 @@ ${calEvent.organizer.language.translate("cancellation_reason")}:
|
||||
${calEvent.cancellationReason}
|
||||
`;
|
||||
};
|
||||
|
||||
export const isDailyVideoCall = (calEvent: CalendarEvent): boolean => {
|
||||
return calEvent?.videoCallData?.type === "daily_video";
|
||||
};
|
||||
|
||||
export const getPublicVideoCallUrl = (calEvent: CalendarEvent): string => {
|
||||
return WEBAPP_URL + "/video/" + getUid(calEvent);
|
||||
};
|
||||
|
||||
export const getVideoCallUrl = (calEvent: CalendarEvent): string => {
|
||||
if (calEvent.videoCallData) {
|
||||
if (isDailyVideoCall(calEvent)) {
|
||||
return getPublicVideoCallUrl(calEvent);
|
||||
}
|
||||
return calEvent.videoCallData.url;
|
||||
}
|
||||
if (calEvent.additionalInformation?.hangoutLink) {
|
||||
return calEvent.additionalInformation.hangoutLink;
|
||||
}
|
||||
return "";
|
||||
};
|
||||
|
||||
export const getVideoCallPassword = (calEvent: CalendarEvent): string => {
|
||||
return isDailyVideoCall(calEvent) ? "" : calEvent?.videoCallData?.password ?? "";
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
module.exports = {
|
||||
preset: "ts-jest",
|
||||
testEnvironment: "node",
|
||||
};
|
||||
@@ -5,13 +5,14 @@
|
||||
"types": "./index.ts",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "dotenv -e ./test/.env.test -- jest",
|
||||
"lint": "eslint . --ext .ts,.js,.tsx,.jsx",
|
||||
"lint:fix": "eslint . --ext .ts,.js,.tsx,.jsx --fix",
|
||||
"lint:report": "eslint . --format json --output-file ../../lint-results/app-store.json"
|
||||
},
|
||||
"dependencies": {
|
||||
"@calcom/dayjs": "*",
|
||||
"@calcom/config": "*",
|
||||
"@calcom/dayjs": "*",
|
||||
"@prisma/client": "^4.1.0",
|
||||
"bcryptjs": "^2.4.3",
|
||||
"ical.js": "^1.4.0",
|
||||
@@ -26,6 +27,9 @@
|
||||
"devDependencies": {
|
||||
"@calcom/tsconfig": "*",
|
||||
"@calcom/types": "*",
|
||||
"@faker-js/faker": "^7.3.0",
|
||||
"jest": "^26.0.0",
|
||||
"ts-jest": "^26.0.0",
|
||||
"typescript": "^4.6.4"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
NEXT_PUBLIC_WEBAPP_URL=http://localhost:3000
|
||||
@@ -0,0 +1,63 @@
|
||||
import { faker } from "@faker-js/faker";
|
||||
|
||||
import { getPublicVideoCallUrl, getLocation, getVideoCallPassword, getVideoCallUrl } from "../CalEventParser";
|
||||
import { buildCalendarEvent, buildVideoCallData } from "./builder";
|
||||
|
||||
describe("getLocation", () => {
|
||||
it("should return a meetingUrl for video call meetings", () => {
|
||||
const calEvent = buildCalendarEvent({
|
||||
videoCallData: buildVideoCallData({
|
||||
type: "daily_video",
|
||||
}),
|
||||
});
|
||||
|
||||
expect(getLocation(calEvent)).toEqual(getVideoCallUrl(calEvent));
|
||||
});
|
||||
it("should return an integration provider name from event", () => {
|
||||
const provideName = "Cal.com";
|
||||
const calEvent = buildCalendarEvent({
|
||||
videoCallData: undefined,
|
||||
location: `integrations:${provideName}`,
|
||||
});
|
||||
|
||||
expect(getLocation(calEvent)).toEqual(provideName);
|
||||
});
|
||||
it("should return a real-world location from event", () => {
|
||||
const calEvent = buildCalendarEvent({
|
||||
videoCallData: undefined,
|
||||
location: faker.address.streetAddress(true),
|
||||
});
|
||||
|
||||
expect(getLocation(calEvent)).toEqual(calEvent.location);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getVideoCallUrl", () => {
|
||||
it("should return an app public url instead of meeting url for daily call meetings", () => {
|
||||
const calEvent = buildCalendarEvent({
|
||||
videoCallData: buildVideoCallData({
|
||||
type: "daily_video",
|
||||
}),
|
||||
});
|
||||
|
||||
expect(getVideoCallUrl(calEvent)).toEqual(getPublicVideoCallUrl(calEvent));
|
||||
});
|
||||
});
|
||||
|
||||
describe("getVideoCallPassword", () => {
|
||||
it("should return an empty password for daily call meetings", () => {
|
||||
const calEvent = buildCalendarEvent({
|
||||
videoCallData: buildVideoCallData({
|
||||
type: "daily_video",
|
||||
}),
|
||||
});
|
||||
|
||||
expect(getVideoCallPassword(calEvent)).toEqual("");
|
||||
});
|
||||
it("should return original password for other video call meetings", () => {
|
||||
const calEvent = buildCalendarEvent();
|
||||
|
||||
expect(calEvent?.videoCallData?.type).not.toBe("daily_video");
|
||||
expect(getVideoCallPassword(calEvent)).toEqual(calEvent?.videoCallData.password);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,46 @@
|
||||
import { faker } from "@faker-js/faker";
|
||||
|
||||
import { CalendarEvent, Person, VideoCallData } from "@calcom/types/Calendar";
|
||||
|
||||
export const buildVideoCallData = (callData?: Partial<VideoCallData>): VideoCallData => {
|
||||
return {
|
||||
type: faker.helpers.arrayElement(["zoom_video", "stream_video"]),
|
||||
id: faker.datatype.uuid(),
|
||||
password: faker.internet.password(),
|
||||
url: faker.internet.url(),
|
||||
...callData,
|
||||
};
|
||||
};
|
||||
|
||||
export const buildPerson = (person?: Partial<Person>): Person => {
|
||||
return {
|
||||
name: faker.name.firstName(),
|
||||
email: faker.internet.email(),
|
||||
timeZone: faker.address.timeZone(),
|
||||
username: faker.internet.userName(),
|
||||
id: faker.datatype.uuid(),
|
||||
language: {
|
||||
locale: faker.random.locale(),
|
||||
translate: (key: string) => key,
|
||||
},
|
||||
...person,
|
||||
};
|
||||
};
|
||||
|
||||
export const buildCalendarEvent = (event?: Partial<CalendarEvent>): CalendarEvent => {
|
||||
return {
|
||||
uid: faker.datatype.uuid(),
|
||||
type: faker.helpers.arrayElement(["event", "meeting"]),
|
||||
title: faker.lorem.sentence(),
|
||||
startTime: faker.date.future().toISOString(),
|
||||
endTime: faker.date.future().toISOString(),
|
||||
location: faker.address.city(),
|
||||
description: faker.lorem.paragraph(),
|
||||
attendees: [],
|
||||
customInputs: {},
|
||||
additionalNotes: faker.lorem.paragraph(),
|
||||
organizer: buildPerson(),
|
||||
videoCallData: buildVideoCallData(),
|
||||
...event,
|
||||
};
|
||||
};
|
||||
Reference in new issue
Block a user