Skip to content

Commit becae27

Browse files
authored
refactor: migrate verifyCodeUnAuthenticated from TRPC layer to features layer (calcom#25639)
* rm * update test * verifyCodeUnAuthenticated * wip
1 parent 584f558 commit becae27

7 files changed

Lines changed: 30 additions & 15 deletions

File tree

File renamed without changes.

packages/features/bookings/lib/handleNewBooking/checkIfBookerEmailIsBlocked.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import { verifyCodeUnAuthenticated } from "@calcom/features/auth/lib/verifyCodeUnAuthenticated";
12
import { ErrorCode } from "@calcom/lib/errorCodes";
23
import { ErrorWithCode } from "@calcom/lib/errors";
34
import { extractBaseEmail } from "@calcom/lib/extract-base-email";
45
import prisma from "@calcom/prisma";
5-
import { verifyCodeUnAuthenticated } from "@calcom/trpc/server/routers/viewer/auth/util";
66

77
export const checkIfBookerEmailIsBlocked = async ({
88
bookerEmail,

packages/features/bookings/lib/handleNewBooking/test/booking-validations.test.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { test } from "@calcom/web/test/fixtures/fixtures";
2424

2525
import { getNewBookingHandler } from "./getNewBookingHandler";
2626

27-
vi.mock("@calcom/trpc/server/routers/viewer/auth/util", () => ({
27+
vi.mock("@calcom/features/auth/lib/verifyCodeUnAuthenticated", () => ({
2828
verifyCodeUnAuthenticated: vi.fn(),
2929
}));
3030

@@ -554,7 +554,9 @@ describe("Booking Validation Specifications", () => {
554554

555555
test("should create booking when main booker provides valid verification code", async () => {
556556
const handleNewBooking = getNewBookingHandler();
557-
const { verifyCodeUnAuthenticated } = await import("@calcom/trpc/server/routers/viewer/auth/util");
557+
const { verifyCodeUnAuthenticated } = await import(
558+
"@calcom/features/auth/lib/verifyCodeUnAuthenticated"
559+
);
558560

559561
vi.mocked(verifyCodeUnAuthenticated).mockResolvedValue(true);
560562

@@ -1067,7 +1069,9 @@ describe("Booking Validation Specifications", () => {
10671069

10681070
test("should throw error when invalid verification code is provided", async () => {
10691071
const handleNewBooking = getNewBookingHandler();
1070-
const { verifyCodeUnAuthenticated } = await import("@calcom/trpc/server/routers/viewer/auth/util");
1072+
const { verifyCodeUnAuthenticated } = await import(
1073+
"@calcom/features/auth/lib/verifyCodeUnAuthenticated"
1074+
);
10711075

10721076
vi.mocked(verifyCodeUnAuthenticated).mockResolvedValue(false);
10731077

packages/features/bookings/lib/handleNewBooking/test/email-verification-booking.test.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { test } from "@calcom/web/test/fixtures/fixtures";
2121

2222
import { getNewBookingHandler } from "./getNewBookingHandler";
2323

24-
vi.mock("@calcom/trpc/server/routers/viewer/auth/util", () => ({
24+
vi.mock("@calcom/features/auth/lib/verifyCodeUnAuthenticated", () => ({
2525
verifyCodeUnAuthenticated: vi.fn(),
2626
}));
2727

@@ -39,7 +39,9 @@ describe("handleNewBooking - Email Verification", () => {
3939
"should throw error when email verification is required but no verification code is provided",
4040
async () => {
4141
const handleNewBooking = getNewBookingHandler();
42-
const { verifyCodeUnAuthenticated } = await import("@calcom/trpc/server/routers/viewer/auth/util");
42+
const { verifyCodeUnAuthenticated } = await import(
43+
"@calcom/features/auth/lib/verifyCodeUnAuthenticated"
44+
);
4345

4446
const booker = getBooker({
4547
email: "booker@example.com",
@@ -99,7 +101,9 @@ describe("handleNewBooking - Email Verification", () => {
99101
"should throw error when email verification is required and verification code is invalid",
100102
async () => {
101103
const handleNewBooking = getNewBookingHandler();
102-
const { verifyCodeUnAuthenticated } = await import("@calcom/trpc/server/routers/viewer/auth/util");
104+
const { verifyCodeUnAuthenticated } = await import(
105+
"@calcom/features/auth/lib/verifyCodeUnAuthenticated"
106+
);
103107

104108
vi.mocked(verifyCodeUnAuthenticated).mockRejectedValue(new Error("Invalid verification code"));
105109

@@ -162,7 +166,9 @@ describe("handleNewBooking - Email Verification", () => {
162166
"should successfully create booking when email verification is required and valid verification code is provided",
163167
async () => {
164168
const handleNewBooking = getNewBookingHandler();
165-
const { verifyCodeUnAuthenticated } = await import("@calcom/trpc/server/routers/viewer/auth/util");
169+
const { verifyCodeUnAuthenticated } = await import(
170+
"@calcom/features/auth/lib/verifyCodeUnAuthenticated"
171+
);
166172

167173
vi.mocked(verifyCodeUnAuthenticated).mockResolvedValue(undefined);
168174

@@ -223,7 +229,9 @@ describe("handleNewBooking - Email Verification", () => {
223229
"should handle rate limiting error from verification service",
224230
async () => {
225231
const handleNewBooking = getNewBookingHandler();
226-
const { verifyCodeUnAuthenticated } = await import("@calcom/trpc/server/routers/viewer/auth/util");
232+
const { verifyCodeUnAuthenticated } = await import(
233+
"@calcom/features/auth/lib/verifyCodeUnAuthenticated"
234+
);
227235

228236
const rateLimitError = new Error("Rate limit exceeded");
229237
rateLimitError.name = "RateLimitError";
@@ -288,7 +296,9 @@ describe("handleNewBooking - Email Verification", () => {
288296
"should proceed normally when email verification is not required",
289297
async () => {
290298
const handleNewBooking = getNewBookingHandler();
291-
const { verifyCodeUnAuthenticated } = await import("@calcom/trpc/server/routers/viewer/auth/util");
299+
const { verifyCodeUnAuthenticated } = await import(
300+
"@calcom/features/auth/lib/verifyCodeUnAuthenticated"
301+
);
292302

293303
const booker = getBooker({
294304
email: "booker@example.com",
@@ -346,7 +356,9 @@ describe("handleNewBooking - Email Verification", () => {
346356
"should allow rescheduling without email verification even when requiresBookerEmailVerification is true",
347357
async () => {
348358
const handleNewBooking = getNewBookingHandler();
349-
const { verifyCodeUnAuthenticated } = await import("@calcom/trpc/server/routers/viewer/auth/util");
359+
const { verifyCodeUnAuthenticated } = await import(
360+
"@calcom/features/auth/lib/verifyCodeUnAuthenticated"
361+
);
350362

351363
const booker = getBooker({
352364
email: "booker@example.com",

packages/features/bookings/lib/service/RegularBookingService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import dayjs from "@calcom/dayjs";
2222
import { scheduleMandatoryReminder } from "@calcom/ee/workflows/lib/reminders/scheduleMandatoryReminder";
2323
import getICalUID from "@calcom/emails/lib/getICalUID";
2424
import { CalendarEventBuilder } from "@calcom/features/CalendarEventBuilder";
25+
import { verifyCodeUnAuthenticated } from "@calcom/features/auth/lib/verifyCodeUnAuthenticated";
2526
import EventManager, { placeholderCreatedEvent } from "@calcom/features/bookings/lib/EventManager";
2627
import type { BookingDataSchemaGetter } from "@calcom/features/bookings/lib/dto/types";
2728
import type {
@@ -85,7 +86,6 @@ import {
8586
CreationSource,
8687
} from "@calcom/prisma/enums";
8788
import { userMetadata as userMetadataSchema } from "@calcom/prisma/zod-utils";
88-
import { verifyCodeUnAuthenticated } from "@calcom/trpc/server/routers/viewer/auth/util";
8989
import { getAllWorkflowsFromEventType } from "@calcom/trpc/server/routers/viewer/workflows/util";
9090
import type {
9191
AdditionalInformation,

packages/platform/libraries/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export { checkAdminOrOwner } from "@calcom/features/auth/lib/checkAdminOrOwner";
119119

120120
export { verifyPhoneNumber, sendVerificationCode };
121121

122-
export { verifyCodeUnAuthenticated } from "@calcom/trpc/server/routers/viewer/auth/util";
122+
export { verifyCodeUnAuthenticated } from "@calcom/features/auth/lib/verifyCodeUnAuthenticated";
123123

124124
export { verifyCode as verifyCodeAuthenticated } from "@calcom/trpc/server/routers/viewer/organizations/verifyCode.handler";
125125

packages/trpc/server/routers/viewer/auth/verifyCodeUnAuthenticated.handler.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1+
import { verifyCodeUnAuthenticated } from "@calcom/features/auth/lib/verifyCodeUnAuthenticated";
12
import type { ZVerifyCodeInputSchema } from "@calcom/prisma/zod-utils";
23

34
import { TRPCError } from "@trpc/server";
45

5-
import { verifyCodeUnAuthenticated } from "./util";
6-
76
type VerifyTokenOptions = {
87
input: ZVerifyCodeInputSchema;
98
};

0 commit comments

Comments
 (0)