* Add email domain array * Create numbered email domain object * Check email domain * Rename function * Add tests * Frontend enable skip ownership check if free email domain * Backend ignore adding ownership to return records if free email domain check is enabled * feat: Only require confirmation for free email domains (#17917) * Add requiresConfirmationForFreeEmail to db * Add option to event type settings * Get requiresConfirmationForFreeEmail for event type page * Include requiresConfirmationForFreeEmail in fetching event type * Pass bookerEmail to `getRequiresConfirmationFlags` * Add free email domain check to `determineRequiresConfirmation` * Add `requiresConfirmationForFreeEmail` to types * Add severity to Watchlist table * Add migration for watchlist severity * Add `getEmailDomainInWatchlist` method to watchlist repository * Use watchlist repository to check for free email domain * Mock watchlist repository in test * Update test * Rename method * Add severity to blocked list * Move check free email domain to async * Type checks * Adjust for promise returned * Fix tests * Fix * Fix tests
92 lines
2.2 KiB
TypeScript
92 lines
2.2 KiB
TypeScript
import prismock from "../../../../../../tests/libs/__mocks__/prisma";
|
|
|
|
import { describe, expect, it, beforeEach } from "vitest";
|
|
|
|
import { WatchlistSeverity } from "@calcom/prisma/enums";
|
|
|
|
import { isLockedOrBlocked } from "../../../lib/utils/isLockedOrBlocked";
|
|
|
|
describe("isLockedOrBlocked", () => {
|
|
beforeEach(async () => {
|
|
await prismock.watchlist.createMany({
|
|
data: [
|
|
{
|
|
type: "DOMAIN",
|
|
value: "spam.com",
|
|
createdById: 1,
|
|
},
|
|
{
|
|
type: "DOMAIN",
|
|
value: "blocked.com",
|
|
severity: WatchlistSeverity.CRITICAL,
|
|
createdById: 1,
|
|
},
|
|
],
|
|
});
|
|
});
|
|
|
|
it("should return false if no user in request", async () => {
|
|
const req = { userId: null, user: null } as any;
|
|
const result = await isLockedOrBlocked(req);
|
|
expect(result).toBe(false);
|
|
});
|
|
|
|
it("should return false if user has no email", async () => {
|
|
const req = { userId: 123, user: { email: null } } as any;
|
|
const result = await isLockedOrBlocked(req);
|
|
expect(result).toBe(false);
|
|
});
|
|
|
|
it("should return true if user is locked", async () => {
|
|
const req = {
|
|
userId: 123,
|
|
user: {
|
|
locked: true,
|
|
email: "test@example.com",
|
|
},
|
|
} as any;
|
|
|
|
const result = await isLockedOrBlocked(req);
|
|
expect(result).toBe(true);
|
|
});
|
|
|
|
it("should return true if user email domain is watchlisted", async () => {
|
|
const req = {
|
|
userId: 123,
|
|
user: {
|
|
locked: false,
|
|
email: "test@blocked.com",
|
|
},
|
|
} as any;
|
|
|
|
const result = await isLockedOrBlocked(req);
|
|
expect(result).toBe(true);
|
|
});
|
|
|
|
it("should return false if user is not locked and email domain is not watchlisted", async () => {
|
|
const req = {
|
|
userId: 123,
|
|
user: {
|
|
locked: false,
|
|
email: "test@example.com",
|
|
},
|
|
} as any;
|
|
|
|
const result = await isLockedOrBlocked(req);
|
|
expect(result).toBe(false);
|
|
});
|
|
|
|
it("should handle email domains case-insensitively", async () => {
|
|
const req = {
|
|
userId: 123,
|
|
user: {
|
|
locked: false,
|
|
email: "test@BLOCKED.COM",
|
|
},
|
|
} as any;
|
|
|
|
const result = await isLockedOrBlocked(req);
|
|
expect(result).toBe(true);
|
|
});
|
|
});
|