refactor: migrate verifyCodeUnAuthenticated from TRPC layer to features layer (#25639)
* rm * update test * verifyCodeUnAuthenticated * wip
This commit is contained in:
1 parent
584f5581fa
commit
becae27b45
7 files changed
+30
-15
No files matched your search
File renamed without changes.
@@ -1,8 +1,8 @@
|
||||
import { verifyCodeUnAuthenticated } from "@calcom/features/auth/lib/verifyCodeUnAuthenticated";
|
||||
import { ErrorCode } from "@calcom/lib/errorCodes";
|
||||
import { ErrorWithCode } from "@calcom/lib/errors";
|
||||
import { extractBaseEmail } from "@calcom/lib/extract-base-email";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { verifyCodeUnAuthenticated } from "@calcom/trpc/server/routers/viewer/auth/util";
|
||||
|
||||
export const checkIfBookerEmailIsBlocked = async ({
|
||||
bookerEmail,
|
||||
|
||||
@@ -24,7 +24,7 @@ import { test } from "@calcom/web/test/fixtures/fixtures";
|
||||
|
||||
import { getNewBookingHandler } from "./getNewBookingHandler";
|
||||
|
||||
vi.mock("@calcom/trpc/server/routers/viewer/auth/util", () => ({
|
||||
vi.mock("@calcom/features/auth/lib/verifyCodeUnAuthenticated", () => ({
|
||||
verifyCodeUnAuthenticated: vi.fn(),
|
||||
}));
|
||||
|
||||
@@ -554,7 +554,9 @@ describe("Booking Validation Specifications", () => {
|
||||
|
||||
test("should create booking when main booker provides valid verification code", async () => {
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
const { verifyCodeUnAuthenticated } = await import("@calcom/trpc/server/routers/viewer/auth/util");
|
||||
const { verifyCodeUnAuthenticated } = await import(
|
||||
"@calcom/features/auth/lib/verifyCodeUnAuthenticated"
|
||||
);
|
||||
|
||||
vi.mocked(verifyCodeUnAuthenticated).mockResolvedValue(true);
|
||||
|
||||
@@ -1067,7 +1069,9 @@ describe("Booking Validation Specifications", () => {
|
||||
|
||||
test("should throw error when invalid verification code is provided", async () => {
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
const { verifyCodeUnAuthenticated } = await import("@calcom/trpc/server/routers/viewer/auth/util");
|
||||
const { verifyCodeUnAuthenticated } = await import(
|
||||
"@calcom/features/auth/lib/verifyCodeUnAuthenticated"
|
||||
);
|
||||
|
||||
vi.mocked(verifyCodeUnAuthenticated).mockResolvedValue(false);
|
||||
|
||||
|
||||
+19
-7
@@ -21,7 +21,7 @@ import { test } from "@calcom/web/test/fixtures/fixtures";
|
||||
|
||||
import { getNewBookingHandler } from "./getNewBookingHandler";
|
||||
|
||||
vi.mock("@calcom/trpc/server/routers/viewer/auth/util", () => ({
|
||||
vi.mock("@calcom/features/auth/lib/verifyCodeUnAuthenticated", () => ({
|
||||
verifyCodeUnAuthenticated: vi.fn(),
|
||||
}));
|
||||
|
||||
@@ -39,7 +39,9 @@ describe("handleNewBooking - Email Verification", () => {
|
||||
"should throw error when email verification is required but no verification code is provided",
|
||||
async () => {
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
const { verifyCodeUnAuthenticated } = await import("@calcom/trpc/server/routers/viewer/auth/util");
|
||||
const { verifyCodeUnAuthenticated } = await import(
|
||||
"@calcom/features/auth/lib/verifyCodeUnAuthenticated"
|
||||
);
|
||||
|
||||
const booker = getBooker({
|
||||
email: "booker@example.com",
|
||||
@@ -99,7 +101,9 @@ describe("handleNewBooking - Email Verification", () => {
|
||||
"should throw error when email verification is required and verification code is invalid",
|
||||
async () => {
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
const { verifyCodeUnAuthenticated } = await import("@calcom/trpc/server/routers/viewer/auth/util");
|
||||
const { verifyCodeUnAuthenticated } = await import(
|
||||
"@calcom/features/auth/lib/verifyCodeUnAuthenticated"
|
||||
);
|
||||
|
||||
vi.mocked(verifyCodeUnAuthenticated).mockRejectedValue(new Error("Invalid verification code"));
|
||||
|
||||
@@ -162,7 +166,9 @@ describe("handleNewBooking - Email Verification", () => {
|
||||
"should successfully create booking when email verification is required and valid verification code is provided",
|
||||
async () => {
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
const { verifyCodeUnAuthenticated } = await import("@calcom/trpc/server/routers/viewer/auth/util");
|
||||
const { verifyCodeUnAuthenticated } = await import(
|
||||
"@calcom/features/auth/lib/verifyCodeUnAuthenticated"
|
||||
);
|
||||
|
||||
vi.mocked(verifyCodeUnAuthenticated).mockResolvedValue(undefined);
|
||||
|
||||
@@ -223,7 +229,9 @@ describe("handleNewBooking - Email Verification", () => {
|
||||
"should handle rate limiting error from verification service",
|
||||
async () => {
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
const { verifyCodeUnAuthenticated } = await import("@calcom/trpc/server/routers/viewer/auth/util");
|
||||
const { verifyCodeUnAuthenticated } = await import(
|
||||
"@calcom/features/auth/lib/verifyCodeUnAuthenticated"
|
||||
);
|
||||
|
||||
const rateLimitError = new Error("Rate limit exceeded");
|
||||
rateLimitError.name = "RateLimitError";
|
||||
@@ -288,7 +296,9 @@ describe("handleNewBooking - Email Verification", () => {
|
||||
"should proceed normally when email verification is not required",
|
||||
async () => {
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
const { verifyCodeUnAuthenticated } = await import("@calcom/trpc/server/routers/viewer/auth/util");
|
||||
const { verifyCodeUnAuthenticated } = await import(
|
||||
"@calcom/features/auth/lib/verifyCodeUnAuthenticated"
|
||||
);
|
||||
|
||||
const booker = getBooker({
|
||||
email: "booker@example.com",
|
||||
@@ -346,7 +356,9 @@ describe("handleNewBooking - Email Verification", () => {
|
||||
"should allow rescheduling without email verification even when requiresBookerEmailVerification is true",
|
||||
async () => {
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
const { verifyCodeUnAuthenticated } = await import("@calcom/trpc/server/routers/viewer/auth/util");
|
||||
const { verifyCodeUnAuthenticated } = await import(
|
||||
"@calcom/features/auth/lib/verifyCodeUnAuthenticated"
|
||||
);
|
||||
|
||||
const booker = getBooker({
|
||||
email: "booker@example.com",
|
||||
|
||||
@@ -22,6 +22,7 @@ import dayjs from "@calcom/dayjs";
|
||||
import { scheduleMandatoryReminder } from "@calcom/ee/workflows/lib/reminders/scheduleMandatoryReminder";
|
||||
import getICalUID from "@calcom/emails/lib/getICalUID";
|
||||
import { CalendarEventBuilder } from "@calcom/features/CalendarEventBuilder";
|
||||
import { verifyCodeUnAuthenticated } from "@calcom/features/auth/lib/verifyCodeUnAuthenticated";
|
||||
import EventManager, { placeholderCreatedEvent } from "@calcom/features/bookings/lib/EventManager";
|
||||
import type { BookingDataSchemaGetter } from "@calcom/features/bookings/lib/dto/types";
|
||||
import type {
|
||||
@@ -85,7 +86,6 @@ import {
|
||||
CreationSource,
|
||||
} from "@calcom/prisma/enums";
|
||||
import { userMetadata as userMetadataSchema } from "@calcom/prisma/zod-utils";
|
||||
import { verifyCodeUnAuthenticated } from "@calcom/trpc/server/routers/viewer/auth/util";
|
||||
import { getAllWorkflowsFromEventType } from "@calcom/trpc/server/routers/viewer/workflows/util";
|
||||
import type {
|
||||
AdditionalInformation,
|
||||
|
||||
@@ -119,7 +119,7 @@ export { checkAdminOrOwner } from "@calcom/features/auth/lib/checkAdminOrOwner";
|
||||
|
||||
export { verifyPhoneNumber, sendVerificationCode };
|
||||
|
||||
export { verifyCodeUnAuthenticated } from "@calcom/trpc/server/routers/viewer/auth/util";
|
||||
export { verifyCodeUnAuthenticated } from "@calcom/features/auth/lib/verifyCodeUnAuthenticated";
|
||||
|
||||
export { verifyCode as verifyCodeAuthenticated } from "@calcom/trpc/server/routers/viewer/organizations/verifyCode.handler";
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { verifyCodeUnAuthenticated } from "@calcom/features/auth/lib/verifyCodeUnAuthenticated";
|
||||
import type { ZVerifyCodeInputSchema } from "@calcom/prisma/zod-utils";
|
||||
|
||||
import { TRPCError } from "@trpc/server";
|
||||
|
||||
import { verifyCodeUnAuthenticated } from "./util";
|
||||
|
||||
type VerifyTokenOptions = {
|
||||
input: ZVerifyCodeInputSchema;
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user