chore: Watchlist schema update (#24246)
* watchlist schema update * changes addressed * no backfill audit * fix type * fix flow of migration * fix err * type err fix * add if exists check in migration
This commit is contained in:
1 parent
654a865007
commit
7cd8dbf7d8
6 files changed
+200
-77
No files matched your search
@@ -59,7 +59,7 @@ import { createWatchlistEntry } from "@calcom/features/watchlist/lib/testUtils";
|
||||
import { WEBSITE_URL, WEBAPP_URL } from "@calcom/lib/constants";
|
||||
import { ErrorCode } from "@calcom/lib/errorCodes";
|
||||
import { resetTestEmails } from "@calcom/lib/testEmails";
|
||||
import { CreationSource, WatchlistSeverity, WatchlistType } from "@calcom/prisma/enums";
|
||||
import { CreationSource, WatchlistType } from "@calcom/prisma/enums";
|
||||
import { BookingStatus, SchedulingType } from "@calcom/prisma/enums";
|
||||
import { test } from "@calcom/web/test/fixtures/fixtures";
|
||||
|
||||
@@ -199,7 +199,7 @@ describe("handleNewBooking", () => {
|
||||
|
||||
await expectBookingToBeInDatabase({
|
||||
description: "",
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
|
||||
uid: createdBooking.uid!,
|
||||
eventTypeId: mockBookingData.eventTypeId,
|
||||
status: BookingStatus.ACCEPTED,
|
||||
@@ -263,6 +263,7 @@ describe("handleNewBooking", () => {
|
||||
3. Should fallback to creating the booking in the first connected Calendar when neither event nor organizer has a destination calendar - This doesn't practically happen because organizer is always required to have a schedule set
|
||||
3. Should trigger BOOKING_CREATED webhook
|
||||
`,
|
||||
|
||||
async ({ emails }) => {
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
const booker = getBooker({
|
||||
@@ -363,7 +364,7 @@ describe("handleNewBooking", () => {
|
||||
|
||||
await expectBookingToBeInDatabase({
|
||||
description: "",
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
|
||||
uid: createdBooking.uid!,
|
||||
eventTypeId: mockBookingData.eventTypeId,
|
||||
status: BookingStatus.ACCEPTED,
|
||||
@@ -423,6 +424,7 @@ describe("handleNewBooking", () => {
|
||||
3. Should fallback to create a booking in the Organizer Calendar if event doesn't have destination calendar
|
||||
3. Should trigger BOOKING_CREATED webhook
|
||||
`,
|
||||
|
||||
async ({ emails }) => {
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
const booker = getBooker({
|
||||
@@ -525,7 +527,7 @@ describe("handleNewBooking", () => {
|
||||
|
||||
await expectBookingToBeInDatabase({
|
||||
description: "",
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
|
||||
uid: createdBooking.uid!,
|
||||
eventTypeId: mockBookingData.eventTypeId,
|
||||
status: BookingStatus.ACCEPTED,
|
||||
@@ -578,6 +580,7 @@ describe("handleNewBooking", () => {
|
||||
|
||||
test(
|
||||
`an error in creating a calendar event should not stop the booking creation - Current behaviour is wrong as the booking is created but no-one is notified of it`,
|
||||
|
||||
async ({ emails }) => {
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
const booker = getBooker({
|
||||
@@ -666,7 +669,7 @@ describe("handleNewBooking", () => {
|
||||
|
||||
await expectBookingToBeInDatabase({
|
||||
description: "",
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
|
||||
uid: createdBooking.uid!,
|
||||
eventTypeId: mockBookingData.eventTypeId,
|
||||
status: BookingStatus.ACCEPTED,
|
||||
@@ -699,6 +702,7 @@ describe("handleNewBooking", () => {
|
||||
|
||||
test(
|
||||
"If destination calendar has no credential ID due to some reason, it should create the event in first connected calendar instead",
|
||||
|
||||
async ({ emails }) => {
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
const booker = getBooker({
|
||||
@@ -811,7 +815,7 @@ describe("handleNewBooking", () => {
|
||||
|
||||
await expectBookingToBeInDatabase({
|
||||
description: "",
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
|
||||
uid: createdBooking.uid!,
|
||||
eventTypeId: mockBookingData.eventTypeId,
|
||||
status: BookingStatus.ACCEPTED,
|
||||
@@ -865,6 +869,7 @@ describe("handleNewBooking", () => {
|
||||
|
||||
test(
|
||||
"If destination calendar is there for Google Calendar but there are no Google Calendar credentials but there is an Apple Calendar credential connected, it should create the event in Apple Calendar",
|
||||
|
||||
async ({ emails }) => {
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
const booker = getBooker({
|
||||
@@ -970,7 +975,7 @@ describe("handleNewBooking", () => {
|
||||
|
||||
await expectBookingToBeInDatabase({
|
||||
description: "",
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
|
||||
uid: createdBooking.uid!,
|
||||
eventTypeId: mockBookingData.eventTypeId,
|
||||
status: BookingStatus.ACCEPTED,
|
||||
@@ -1022,6 +1027,7 @@ describe("handleNewBooking", () => {
|
||||
describe("Event's first location should be used when location is unspecied", () => {
|
||||
test(
|
||||
`should create a successful booking with right location app when event has location option as video client`,
|
||||
|
||||
async ({ emails }) => {
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
const booker = getBooker({
|
||||
@@ -1115,6 +1121,7 @@ describe("handleNewBooking", () => {
|
||||
`should create a successful booking with right location when event's location is not a conferencing app
|
||||
`,
|
||||
//test with inPerson event type
|
||||
|
||||
async ({ emails }) => {
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
const booker = getBooker({
|
||||
@@ -1198,6 +1205,7 @@ describe("handleNewBooking", () => {
|
||||
);
|
||||
test(
|
||||
`should create a successful booking with organizer default conferencing app when event's location is not set`,
|
||||
|
||||
async ({ emails }) => {
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
const booker = getBooker({
|
||||
@@ -1292,6 +1300,7 @@ describe("handleNewBooking", () => {
|
||||
describe("Video Meeting Creation", () => {
|
||||
test(
|
||||
`should create a successful booking with Zoom if used`,
|
||||
|
||||
async ({ emails }) => {
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
const subscriberUrl = "http://my-webhook.example.com";
|
||||
@@ -1380,6 +1389,7 @@ describe("handleNewBooking", () => {
|
||||
|
||||
test(
|
||||
`Booking should still be created using calvideo, if error occurs with zoom`,
|
||||
|
||||
async ({ emails }) => {
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
const subscriberUrl = "http://my-webhook.example.com";
|
||||
@@ -1534,6 +1544,7 @@ describe("handleNewBooking", () => {
|
||||
describe("UTM tracking tests", () => {
|
||||
test(
|
||||
"should create a booking with UTM tracking",
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
async ({ emails }) => {
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
const booker = getBooker({
|
||||
@@ -1609,7 +1620,6 @@ describe("handleNewBooking", () => {
|
||||
bookingData: mockedBookingData,
|
||||
});
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
expectBookingTrackingToBeInDatabase(tracking, createdBooking.uid!);
|
||||
},
|
||||
timeout
|
||||
@@ -1619,6 +1629,7 @@ describe("handleNewBooking", () => {
|
||||
describe("Creation source tests", () => {
|
||||
test(
|
||||
`should create a booking with creation source as WEBAPP`,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
async ({ emails }) => {
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
const booker = getBooker({
|
||||
@@ -1700,7 +1711,7 @@ describe("handleNewBooking", () => {
|
||||
() => {
|
||||
test(
|
||||
`should fail a booking if there is already a Cal.com booking overlapping the time`,
|
||||
async ({}) => {
|
||||
async () => {
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
|
||||
const booker = getBooker({
|
||||
@@ -1929,7 +1940,7 @@ describe("handleNewBooking", () => {
|
||||
});
|
||||
expectBookingToBeInDatabase({
|
||||
description: "",
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
|
||||
uid: createdBooking.uid!,
|
||||
eventTypeId: mockBookingData.eventTypeId,
|
||||
status: BookingStatus.ACCEPTED,
|
||||
@@ -2098,7 +2109,7 @@ describe("handleNewBooking", () => {
|
||||
});
|
||||
expectBookingToBeInDatabase({
|
||||
description: "",
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
|
||||
uid: createdBooking.uid!,
|
||||
eventTypeId: mockBookingData.eventTypeId,
|
||||
status: BookingStatus.ACCEPTED,
|
||||
@@ -2119,6 +2130,7 @@ describe("handleNewBooking", () => {
|
||||
3. Should trigger BOOKING_REQUESTED webhook
|
||||
4. Should trigger BOOKING_REQUESTED workflow
|
||||
`,
|
||||
|
||||
async ({ emails }) => {
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
const subscriberUrl = "http://my-webhook.example.com";
|
||||
@@ -2220,7 +2232,7 @@ describe("handleNewBooking", () => {
|
||||
|
||||
await expectBookingToBeInDatabase({
|
||||
description: "",
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
|
||||
uid: createdBooking.uid!,
|
||||
eventTypeId: mockBookingData.eventTypeId,
|
||||
status: BookingStatus.PENDING,
|
||||
@@ -2256,6 +2268,7 @@ describe("handleNewBooking", () => {
|
||||
3. Should trigger BOOKING_REQUESTED webhook
|
||||
4. Should trigger BOOKING_REQUESTED workflow
|
||||
`,
|
||||
|
||||
async ({ emails }) => {
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
const subscriberUrl = "http://my-webhook.example.com";
|
||||
@@ -2345,7 +2358,7 @@ describe("handleNewBooking", () => {
|
||||
|
||||
await expectBookingToBeInDatabase({
|
||||
description: "",
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
|
||||
uid: createdBooking.uid!,
|
||||
eventTypeId: mockBookingData.eventTypeId,
|
||||
status: BookingStatus.PENDING,
|
||||
@@ -2382,6 +2395,7 @@ describe("handleNewBooking", () => {
|
||||
2. Should send emails to the booker as well as organizer
|
||||
3. Should trigger BOOKING_CREATED webhook
|
||||
`,
|
||||
|
||||
async ({ emails }) => {
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
const booker = getBooker({
|
||||
@@ -2479,7 +2493,7 @@ describe("handleNewBooking", () => {
|
||||
|
||||
await expectBookingToBeInDatabase({
|
||||
description: "",
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
|
||||
uid: createdBooking.uid!,
|
||||
eventTypeId: mockBookingData.eventTypeId,
|
||||
status: BookingStatus.ACCEPTED,
|
||||
@@ -2518,6 +2532,7 @@ describe("handleNewBooking", () => {
|
||||
3. Should trigger BOOKING_REQUESTED webhook
|
||||
4. Should trigger BOOKING_REQUESTED workflows
|
||||
`,
|
||||
|
||||
async ({ emails }) => {
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
const subscriberUrl = "http://my-webhook.example.com";
|
||||
@@ -2621,7 +2636,7 @@ describe("handleNewBooking", () => {
|
||||
|
||||
await expectBookingToBeInDatabase({
|
||||
description: "",
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
|
||||
uid: createdBooking.uid!,
|
||||
eventTypeId: mockBookingData.eventTypeId,
|
||||
status: BookingStatus.PENDING,
|
||||
@@ -2648,7 +2663,7 @@ describe("handleNewBooking", () => {
|
||||
// FIXME: We shouldn't throw error here, the behaviour should be fixed.
|
||||
test(
|
||||
`if booking with Cal Video(Daily Video) fails, booking creation fails with uncaught error`,
|
||||
async ({}) => {
|
||||
async () => {
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
const booker = getBooker({
|
||||
email: "[email protected]",
|
||||
@@ -2716,6 +2731,7 @@ describe("handleNewBooking", () => {
|
||||
2. Should send emails to the booker as well as organizer
|
||||
3. Should trigger BOOKING_CREATED webhook
|
||||
`,
|
||||
|
||||
async ({ emails }) => {
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
const booker = getBooker({
|
||||
@@ -2801,7 +2817,7 @@ describe("handleNewBooking", () => {
|
||||
|
||||
await expectBookingToBeInDatabase({
|
||||
description: "",
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
|
||||
uid: createdBooking.uid!,
|
||||
eventTypeId: mockBookingData.eventTypeId,
|
||||
status: BookingStatus.ACCEPTED,
|
||||
@@ -2842,6 +2858,7 @@ describe("handleNewBooking", () => {
|
||||
6. Workflow should not trigger before payment is made
|
||||
7. Workflow triggers once payment is successful
|
||||
`,
|
||||
|
||||
async ({ emails }) => {
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
const booker = getBooker({
|
||||
@@ -2963,7 +2980,7 @@ describe("handleNewBooking", () => {
|
||||
await expectBookingToBeInDatabase({
|
||||
description: "",
|
||||
location: BookingLocations.CalVideo,
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
|
||||
uid: createdBooking.uid!,
|
||||
eventTypeId: mockBookingData.eventTypeId,
|
||||
status: BookingStatus.PENDING,
|
||||
@@ -2984,7 +3001,7 @@ describe("handleNewBooking", () => {
|
||||
organizer,
|
||||
location: BookingLocations.CalVideo,
|
||||
subscriberUrl: "http://my-webhook.example.com",
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
|
||||
paymentId: createdBooking.paymentId!,
|
||||
});
|
||||
|
||||
@@ -2993,7 +3010,7 @@ describe("handleNewBooking", () => {
|
||||
expect(webhookResponse?.statusCode).toBe(200);
|
||||
await expectBookingToBeInDatabase({
|
||||
description: "",
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
|
||||
uid: createdBooking.uid!,
|
||||
eventTypeId: mockBookingData.eventTypeId,
|
||||
status: BookingStatus.ACCEPTED,
|
||||
@@ -3024,6 +3041,7 @@ describe("handleNewBooking", () => {
|
||||
6. Should trigger BOOKING_REQUESTED workflow
|
||||
7. Booking should still stay in pending state
|
||||
`,
|
||||
|
||||
async ({ emails }) => {
|
||||
const bookingInitiatedEmail = "[email protected]";
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
@@ -3145,7 +3163,7 @@ describe("handleNewBooking", () => {
|
||||
);
|
||||
await expectBookingToBeInDatabase({
|
||||
description: "",
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
|
||||
uid: createdBooking.uid!,
|
||||
eventTypeId: mockBookingData.eventTypeId,
|
||||
status: BookingStatus.PENDING,
|
||||
@@ -3165,7 +3183,7 @@ describe("handleNewBooking", () => {
|
||||
organizer,
|
||||
location: BookingLocations.CalVideo,
|
||||
subscriberUrl: "http://my-webhook.example.com",
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
|
||||
paymentId: createdBooking.paymentId!,
|
||||
});
|
||||
expectWorkflowToBeTriggered({ emailsToReceive: [bookingInitiatedEmail], emails });
|
||||
@@ -3178,7 +3196,7 @@ describe("handleNewBooking", () => {
|
||||
expect(webhookResponse?.statusCode).toBe(200);
|
||||
await expectBookingToBeInDatabase({
|
||||
description: "",
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
|
||||
uid: createdBooking.uid!,
|
||||
eventTypeId: mockBookingData.eventTypeId,
|
||||
status: BookingStatus.PENDING,
|
||||
@@ -3203,6 +3221,7 @@ describe("handleNewBooking", () => {
|
||||
);
|
||||
test(
|
||||
`cannot book same slot multiple times `,
|
||||
|
||||
async ({ emails }) => {
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
const booker = getBooker({
|
||||
@@ -3298,7 +3317,7 @@ describe("handleNewBooking", () => {
|
||||
|
||||
await expectBookingToBeInDatabase({
|
||||
description: "",
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
|
||||
uid: createdBooking.uid!,
|
||||
eventTypeId: mockBookingData.eventTypeId,
|
||||
status: BookingStatus.ACCEPTED,
|
||||
@@ -3351,6 +3370,7 @@ describe("handleNewBooking", () => {
|
||||
|
||||
test(
|
||||
`Payment retry scenario - should return existing payment UID and prevent duplicate bookings when retrying canceled payment`,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
async ({ emails }) => {
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
const booker = getBooker({
|
||||
@@ -3400,7 +3420,7 @@ describe("handleNewBooking", () => {
|
||||
mockSuccessfulVideoMeetingCreation({
|
||||
metadataLookupKey: "dailyvideo",
|
||||
});
|
||||
const { paymentUid } = mockPaymentApp({
|
||||
const { paymentUid: _paymentUid } = mockPaymentApp({
|
||||
metadataLookupKey: "stripe",
|
||||
appStoreLookupKey: "stripepayment",
|
||||
});
|
||||
@@ -3693,7 +3713,6 @@ describe("handleNewBooking", () => {
|
||||
|
||||
await createWatchlistEntry({
|
||||
type: WatchlistType.USERNAME,
|
||||
severity: WatchlistSeverity.CRITICAL,
|
||||
value: organizer.username,
|
||||
});
|
||||
|
||||
@@ -3755,7 +3774,6 @@ describe("handleNewBooking", () => {
|
||||
|
||||
await createWatchlistEntry({
|
||||
type: WatchlistType.DOMAIN,
|
||||
severity: WatchlistSeverity.CRITICAL,
|
||||
value: "spammer.com",
|
||||
});
|
||||
|
||||
@@ -3817,7 +3835,6 @@ describe("handleNewBooking", () => {
|
||||
|
||||
await createWatchlistEntry({
|
||||
type: WatchlistType.EMAIL,
|
||||
severity: WatchlistSeverity.CRITICAL,
|
||||
value: "[email protected]",
|
||||
});
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import prismock from "../../../../tests/libs/__mocks__/prisma";
|
||||
|
||||
import type { WatchlistSeverity, WatchlistType } from "@calcom/prisma/enums";
|
||||
import type { WatchlistType } from "@calcom/prisma/enums";
|
||||
|
||||
interface WatchlistInput {
|
||||
severity: WatchlistSeverity;
|
||||
type: WatchlistType;
|
||||
value: string;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { captureException } from "@sentry/nextjs";
|
||||
|
||||
import db from "@calcom/prisma";
|
||||
import { WatchlistType, WatchlistSeverity } from "@calcom/prisma/enums";
|
||||
import { WatchlistType } from "@calcom/prisma/enums";
|
||||
|
||||
import type { IWatchlistRepository } from "./watchlist.repository.interface";
|
||||
|
||||
@@ -11,7 +11,6 @@ export class WatchlistRepository implements IWatchlistRepository {
|
||||
try {
|
||||
const emailInWatchlist = await db.watchlist.findFirst({
|
||||
where: {
|
||||
severity: WatchlistSeverity.CRITICAL,
|
||||
OR: [
|
||||
{ type: WatchlistType.EMAIL, value: email },
|
||||
{ type: WatchlistType.DOMAIN, value: domain },
|
||||
@@ -53,7 +52,6 @@ export class WatchlistRepository implements IWatchlistRepository {
|
||||
try {
|
||||
const blockedRecords = await db.watchlist.findMany({
|
||||
where: {
|
||||
severity: WatchlistSeverity.CRITICAL,
|
||||
OR: [
|
||||
...(usernames.length > 0
|
||||
? [
|
||||
|
||||
Reference in new issue
Block a user