refactor: circular deps between app store and lib [3] (#23742)
* getEnabledAppsFromCredentials * wip * wip * mv more * fix: update test mocking for PrismockClient in processPaymentRefund.test.ts - Replace prismaMock with prismock for proper PrismockClient usage - Update mock data structure to include required fields (id, userId, teamId, etc.) - Create app and credential records separately to handle PrismockClient limitations - Replace 'as any' type casting with vi.mocked() for proper type safety - Adjust test expectations to match PrismockClient's actual return structure - Add proper cleanup in beforeEach hook for both credential and app records Fixes failing unit tests after migration from packages/lib to packages/features/bookings/lib/payment Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * publish platform libraries * fix import * bump version * fix apiv2 * publish platform-libraries --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
76bba1ca05
commit
3aab13b4da
42 files changed
+105
-79
No files matched your search
@@ -38,7 +38,7 @@
|
||||
"@axiomhq/winston": "^1.2.0",
|
||||
"@calcom/platform-constants": "*",
|
||||
"@calcom/platform-enums": "*",
|
||||
"@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.358",
|
||||
"@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.359",
|
||||
"@calcom/platform-types": "*",
|
||||
"@calcom/platform-utils": "*",
|
||||
"@calcom/prisma": "*",
|
||||
|
||||
@@ -79,13 +79,13 @@ export class AtomsVerificationController {
|
||||
@Version(VERSION_NEUTRAL)
|
||||
@HttpCode(HttpStatus.OK)
|
||||
async verifyEmailCode(@Body() body: VerifyEmailCodeInput): Promise<VerifyEmailCodeOutput> {
|
||||
const verified = await this.verificationService.verifyEmailCodeUnAuthenticated({
|
||||
await this.verificationService.verifyEmailCodeUnAuthenticated({
|
||||
email: body.email,
|
||||
code: body.code,
|
||||
});
|
||||
|
||||
return {
|
||||
data: { verified },
|
||||
data: { verified: true },
|
||||
status: SUCCESS_STATUS,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import dynamic from "next/dynamic";
|
||||
import type { FC } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
import { getPaymentAppData } from "@calcom/app-store/_utils/payments/getPaymentAppData";
|
||||
import { getSuccessPageLocationMessage } from "@calcom/app-store/locations";
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { sdkActionManager, useIsEmbed } from "@calcom/embed-core/embed-iframe";
|
||||
@@ -12,7 +13,6 @@ import { PayIcon } from "@calcom/features/bookings/components/event-meta/PayIcon
|
||||
import { Price } from "@calcom/features/bookings/components/event-meta/Price";
|
||||
import type { PaymentPageProps } from "@calcom/features/ee/payments/pages/payment";
|
||||
import { APP_NAME, WEBSITE_URL } from "@calcom/lib/constants";
|
||||
import { getPaymentAppData } from "@calcom/lib/getPaymentAppData";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import useTheme from "@calcom/lib/hooks/useTheme";
|
||||
import { getIs24hClockFromLocalStorage, isBrowserLocale24h } from "@calcom/lib/timeFormat";
|
||||
|
||||
@@ -2,6 +2,7 @@ import Link from "next/link";
|
||||
import { useState } from "react";
|
||||
import { Controller, useFieldArray, useForm } from "react-hook-form";
|
||||
|
||||
import { getPaymentAppData } from "@calcom/app-store/_utils/payments/getPaymentAppData";
|
||||
import type { getEventLocationValue } from "@calcom/app-store/locations";
|
||||
import { getSuccessPageLocationMessage, guessEventLocationType } from "@calcom/app-store/locations";
|
||||
import dayjs from "@calcom/dayjs";
|
||||
@@ -11,7 +12,6 @@ import { Dialog } from "@calcom/features/components/controlled-dialog";
|
||||
import { MeetingSessionDetailsDialog } from "@calcom/features/ee/video/MeetingSessionDetailsDialog";
|
||||
import ViewRecordingsDialog from "@calcom/features/ee/video/ViewRecordingsDialog";
|
||||
import { formatTime } from "@calcom/lib/dayjs";
|
||||
import { getPaymentAppData } from "@calcom/lib/getPaymentAppData";
|
||||
import { useCopy } from "@calcom/lib/hooks/useCopy";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { useGetTheme } from "@calcom/lib/hooks/useTheme";
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
import { useCallback, useState } from "react";
|
||||
|
||||
import { sdkActionManager } from "@calcom/embed-core/embed-iframe";
|
||||
import { shouldChargeNoShowCancellationFee } from "@calcom/features/bookings/lib/payment/shouldChargeNoShowCancellationFee";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { useRefreshData } from "@calcom/lib/hooks/useRefreshData";
|
||||
import { useTelemetry } from "@calcom/lib/hooks/useTelemetry";
|
||||
import { shouldChargeNoShowCancellationFee } from "@calcom/lib/payment/shouldChargeNoShowCancellationFee";
|
||||
import { collectPageParameters, telemetryEventTypes } from "@calcom/lib/telemetry";
|
||||
import type { RecurringEvent } from "@calcom/types/Calendar";
|
||||
import { Button } from "@calcom/ui/components/button";
|
||||
|
||||
@@ -2,7 +2,7 @@ import { render, screen } from "@testing-library/react";
|
||||
import * as React from "react";
|
||||
import { describe, expect, it, vi, beforeAll } from "vitest";
|
||||
|
||||
import * as shouldChargeModule from "@calcom/lib/payment/shouldChargeNoShowCancellationFee";
|
||||
import * as shouldChargeModule from "@calcom/features/bookings/lib/payment/shouldChargeNoShowCancellationFee";
|
||||
|
||||
import CancelBooking from "../CancelBooking";
|
||||
|
||||
@@ -76,7 +76,7 @@ vi.mock("next/router", () => ({
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("@calcom/lib/payment/shouldChargeNoShowCancellationFee", () => ({
|
||||
vi.mock("@calcom/features/bookings/lib/payment/shouldChargeNoShowCancellationFee", () => ({
|
||||
shouldChargeNoShowCancellationFee: vi.fn(),
|
||||
}));
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { checkAdminOrOwner } from "@calcom/features/auth/lib/checkAdminOrOwner";
|
||||
import getEnabledAppsFromCredentials from "@calcom/lib/apps/getEnabledAppsFromCredentials";
|
||||
import getInstallCountPerApp from "@calcom/lib/apps/getInstallCountPerApp";
|
||||
import { buildNonDelegationCredentials } from "@calcom/lib/delegationCredential/clientAndServer";
|
||||
import { getUsersCredentialsIncludeServiceAccountKey } from "@calcom/lib/server/getUsersCredentials";
|
||||
@@ -11,6 +10,7 @@ import type { TDependencyData } from "../_appRegistry";
|
||||
import { PaymentServiceMap } from "../payment.services.generated";
|
||||
import type { CredentialOwner } from "../types";
|
||||
import { getAppFromSlug } from "../utils";
|
||||
import getEnabledAppsFromCredentials from "./getEnabledAppsFromCredentials";
|
||||
|
||||
export type ConnectedApps = Awaited<ReturnType<typeof getConnectedApps>>;
|
||||
type InputSchema = {
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
import type { CredentialDataWithTeamName } from "@calcom/app-store/utils";
|
||||
import getApps from "@calcom/app-store/utils";
|
||||
import { isDelegationCredential } from "@calcom/lib/delegationCredential/clientAndServer";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
|
||||
import { isDelegationCredential } from "../delegationCredential/clientAndServer";
|
||||
import getApps from "../utils";
|
||||
|
||||
type EnabledApp = ReturnType<typeof getApps>[number] & { enabled: boolean };
|
||||
|
||||
+6
-5
@@ -1,13 +1,14 @@
|
||||
import type { z } from "zod";
|
||||
|
||||
import { getEventTypeAppData } from "@calcom/app-store/_utils/getEventTypeAppData";
|
||||
import type { appDataSchemas } from "@calcom/app-store/apps.schemas.generated";
|
||||
import type { appDataSchema, paymentOptionEnum } from "@calcom/app-store/stripepayment/zod";
|
||||
import type { EventTypeAppsList } from "@calcom/app-store/utils";
|
||||
import { eventTypeMetaDataSchemaWithTypedApps } from "@calcom/app-store/zod-utils";
|
||||
import type { BookerEvent } from "@calcom/features/bookings/types";
|
||||
import type { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
|
||||
|
||||
import type { appDataSchemas } from "../../apps.schemas.generated";
|
||||
import type { appDataSchema, paymentOptionEnum } from "../../stripepayment/zod";
|
||||
import type { EventTypeAppsList } from "../../utils";
|
||||
import { eventTypeMetaDataSchemaWithTypedApps } from "../../zod-utils";
|
||||
import { getEventTypeAppData } from "../getEventTypeAppData";
|
||||
|
||||
export function getPaymentAppData(
|
||||
_eventType: Pick<BookerEvent, "price" | "currency"> & {
|
||||
metadata: z.infer<typeof EventTypeMetaDataSchema>;
|
||||
@@ -4,12 +4,12 @@ import { doesBookingRequireConfirmation } from "@calcom/features/bookings/lib/do
|
||||
import { getAllCredentialsIncludeServiceAccountKey } from "@calcom/features/bookings/lib/getAllCredentialsForUsersOnEvent/getAllCredentials";
|
||||
import { handleBookingRequested } from "@calcom/features/bookings/lib/handleBookingRequested";
|
||||
import { handleConfirmation } from "@calcom/features/bookings/lib/handleConfirmation";
|
||||
import { getBooking } from "@calcom/features/bookings/lib/payment/getBooking";
|
||||
import { getPlatformParams } from "@calcom/features/platform-oauth-client/get-platform-params";
|
||||
import { PlatformOAuthClientRepository } from "@calcom/features/platform-oauth-client/platform-oauth-client.repository";
|
||||
import EventManager, { placeholderCreatedEvent } from "@calcom/lib/EventManager";
|
||||
import { HttpError as HttpCode } from "@calcom/lib/http-error";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { getBooking } from "@calcom/lib/payment/getBooking";
|
||||
import prisma from "@calcom/prisma";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
import { BookingStatus } from "@calcom/prisma/enums";
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import type { TFunction } from "i18next";
|
||||
|
||||
import { defaultVideoAppCategories } from "@calcom/app-store/utils";
|
||||
import getEnabledAppsFromCredentials from "@calcom/lib/apps/getEnabledAppsFromCredentials";
|
||||
import {
|
||||
buildNonDelegationCredentials,
|
||||
enrichUserWithDelegationConferencingCredentialsWithoutOrgId,
|
||||
@@ -11,6 +10,7 @@ import type { Prisma } from "@calcom/prisma/client";
|
||||
import { AppCategories } from "@calcom/prisma/enums";
|
||||
import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";
|
||||
|
||||
import getEnabledAppsFromCredentials from "./_utils/getEnabledAppsFromCredentials";
|
||||
import { defaultLocations } from "./locations";
|
||||
|
||||
export async function getLocationGroupedOptions(
|
||||
|
||||
@@ -3,13 +3,13 @@ import Link from "next/link";
|
||||
import { useMemo, useState } from "react";
|
||||
import type { FieldError } from "react-hook-form";
|
||||
|
||||
import { getPaymentAppData } from "@calcom/app-store/_utils/payments/getPaymentAppData";
|
||||
import { useIsPlatformBookerEmbed } from "@calcom/atoms/hooks/useIsPlatformBookerEmbed";
|
||||
import { useBookerStoreContext } from "@calcom/features/bookings/Booker/BookerStoreProvider";
|
||||
import type { BookerEvent } from "@calcom/features/bookings/types";
|
||||
import ServerTrans from "@calcom/lib/components/ServerTrans";
|
||||
import { WEBSITE_PRIVACY_POLICY_URL, WEBSITE_TERMS_URL } from "@calcom/lib/constants";
|
||||
import { ErrorCode } from "@calcom/lib/errorCodes";
|
||||
import { getPaymentAppData } from "@calcom/lib/getPaymentAppData";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import type { TimeFormat } from "@calcom/lib/timeFormat";
|
||||
import { Alert } from "@calcom/ui/components/alert";
|
||||
|
||||
@@ -3,6 +3,7 @@ import * as HoverCard from "@radix-ui/react-hover-card";
|
||||
import { AnimatePresence, m } from "framer-motion";
|
||||
import { useMemo } from "react";
|
||||
|
||||
import { getPaymentAppData } from "@calcom/app-store/_utils/payments/getPaymentAppData";
|
||||
import { useIsPlatform } from "@calcom/atoms/hooks/useIsPlatform";
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { useBookerStoreContext } from "@calcom/features/bookings/Booker/BookerStoreProvider";
|
||||
@@ -10,7 +11,6 @@ import { OutOfOfficeInSlots } from "@calcom/features/bookings/Booker/components/
|
||||
import type { IUseBookingLoadingStates } from "@calcom/features/bookings/Booker/components/hooks/useBookings";
|
||||
import type { BookerEvent } from "@calcom/features/bookings/types";
|
||||
import type { Slot } from "@calcom/features/schedules/lib/use-schedule/types";
|
||||
import { getPaymentAppData } from "@calcom/lib/getPaymentAppData";
|
||||
import type { IOutOfOfficeData } from "@calcom/lib/getUserAvailability";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { localStorage } from "@calcom/lib/webstorage";
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import React, { Fragment } from "react";
|
||||
|
||||
import { getPaymentAppData } from "@calcom/app-store/_utils/payments/getPaymentAppData";
|
||||
import { useBookerStore } from "@calcom/features/bookings/Booker/store";
|
||||
import { PriceIcon } from "@calcom/features/bookings/components/event-meta/PriceIcon";
|
||||
import type { BookerEvent } from "@calcom/features/bookings/types";
|
||||
import { getPaymentAppData } from "@calcom/lib/getPaymentAppData";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import classNames from "@calcom/ui/classNames";
|
||||
import { Icon } from "@calcom/ui/components/icon";
|
||||
|
||||
@@ -6,6 +6,8 @@ import { eventTypeMetaDataSchemaWithTypedApps } from "@calcom/app-store/zod-util
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { sendCancelledEmailsAndSMS } from "@calcom/emails";
|
||||
import { getCalEventResponses } from "@calcom/features/bookings/lib/getCalEventResponses";
|
||||
import { processNoShowFeeOnCancellation } from "@calcom/features/bookings/lib/payment/processNoShowFeeOnCancellation";
|
||||
import { processPaymentRefund } from "@calcom/features/bookings/lib/payment/processPaymentRefund";
|
||||
import { sendCancelledReminders } from "@calcom/features/ee/workflows/lib/reminders/reminderScheduler";
|
||||
import type { GetSubscriberOptions } from "@calcom/features/webhooks/lib/getWebhooks";
|
||||
import getWebhooks from "@calcom/features/webhooks/lib/getWebhooks";
|
||||
@@ -23,8 +25,6 @@ import { HttpError } from "@calcom/lib/http-error";
|
||||
import { isPrismaObjOrUndefined } from "@calcom/lib/isPrismaObj";
|
||||
import { parseRecurringEvent } from "@calcom/lib/isRecurringEvent";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { processNoShowFeeOnCancellation } from "@calcom/lib/payment/processNoShowFeeOnCancellation";
|
||||
import { processPaymentRefund } from "@calcom/lib/payment/processPaymentRefund";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import { getTranslation } from "@calcom/lib/server/i18n";
|
||||
import { WorkflowRepository } from "@calcom/lib/server/repository/workflow";
|
||||
|
||||
@@ -18,11 +18,11 @@ import { setupAndTeardown } from "@calcom/web/test/utils/bookingScenario/setupAn
|
||||
|
||||
import { describe, expect, vi } from "vitest";
|
||||
|
||||
import { processPaymentRefund } from "@calcom/lib/payment/processPaymentRefund";
|
||||
import { processPaymentRefund } from "@calcom/features/bookings/lib/payment/processPaymentRefund";
|
||||
import { BookingStatus } from "@calcom/prisma/enums";
|
||||
import { test } from "@calcom/web/test/fixtures/fixtures";
|
||||
|
||||
vi.mock("@calcom/lib/payment/processPaymentRefund", () => ({
|
||||
vi.mock("@calcom/features/bookings/lib/payment/processPaymentRefund", () => ({
|
||||
processPaymentRefund: vi.fn(),
|
||||
}));
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ import { getErrorFromUnknown } from "@calcom/lib/errors";
|
||||
import { extractBaseEmail } from "@calcom/lib/extract-base-email";
|
||||
import { getBookerBaseUrl } from "@calcom/lib/getBookerUrl/server";
|
||||
import getOrgIdFromMemberOrTeamId from "@calcom/lib/getOrgIdFromMemberOrTeamId";
|
||||
import { getPaymentAppData } from "@calcom/lib/getPaymentAppData";
|
||||
import { getPaymentAppData } from "@calcom/app-store/_utils/payments/getPaymentAppData";
|
||||
import { getTeamIdFromEventType } from "@calcom/lib/getTeamIdFromEventType";
|
||||
import { HttpError } from "@calcom/lib/http-error";
|
||||
import type { CheckBookingLimitsService } from "@calcom/lib/intervalLimits/server/checkBookingLimits";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { TFunction } from "i18next";
|
||||
|
||||
import type { PaymentAppData } from "@calcom/app-store/_utils/payments/getPaymentAppData";
|
||||
import type { EventTypeAppsList } from "@calcom/app-store/utils";
|
||||
import type { PaymentAppData } from "@calcom/lib/getPaymentAppData";
|
||||
import type { GetUserAvailabilityResult } from "@calcom/lib/getUserAvailability";
|
||||
import type { userSelect } from "@calcom/prisma";
|
||||
import type { App } from "@calcom/prisma/client";
|
||||
|
||||
File renamed without changes.
+2
-3
@@ -1,5 +1,7 @@
|
||||
import { workflowSelect } from "@calcom/ee/workflows/lib/getAllWorkflows";
|
||||
import { getCalEventResponses } from "@calcom/features/bookings/lib/getCalEventResponses";
|
||||
import { enrichUserWithDelegationCredentials } from "@calcom/lib/delegationCredential/server";
|
||||
import { getBookerBaseUrl } from "@calcom/lib/getBookerUrl/server";
|
||||
import { HttpError as HttpCode } from "@calcom/lib/http-error";
|
||||
import { isPrismaObjOrUndefined } from "@calcom/lib/isPrismaObj";
|
||||
import { parseRecurringEvent } from "@calcom/lib/isRecurringEvent";
|
||||
@@ -10,9 +12,6 @@ import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/crede
|
||||
import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
|
||||
import type { CalendarEvent } from "@calcom/types/Calendar";
|
||||
|
||||
import { enrichUserWithDelegationCredentials } from "../delegationCredential/server";
|
||||
import { getBookerBaseUrl } from "../getBookerUrl/server";
|
||||
|
||||
async function getEventType(id: number) {
|
||||
return prisma.eventType.findUnique({
|
||||
where: {
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+56
-29
@@ -1,22 +1,24 @@
|
||||
import prismaMock from "../../../tests/libs/__mocks__/prismaMock";
|
||||
import prismock from "../../../../../tests/libs/__mocks__/prisma";
|
||||
|
||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||
|
||||
import { getPaymentAppData } from "@calcom/app-store/_utils/payments/getPaymentAppData";
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { RefundPolicy } from "@calcom/lib/payment/types";
|
||||
|
||||
import { getPaymentAppData } from "../getPaymentAppData";
|
||||
import { handlePaymentRefund } from "./handlePaymentRefund";
|
||||
import { processPaymentRefund } from "./processPaymentRefund";
|
||||
import { RefundPolicy } from "./types";
|
||||
|
||||
vi.mock("@calcom/lib/getPaymentAppData", () => ({
|
||||
vi.mock("@calcom/app-store/_utils/payments/getPaymentAppData", () => ({
|
||||
getPaymentAppData: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("@calcom/lib/payment/handlePaymentRefund", () => ({
|
||||
vi.mock("./handlePaymentRefund", () => ({
|
||||
handlePaymentRefund: vi.fn(),
|
||||
}));
|
||||
|
||||
const mockedGetPaymentAppData = vi.mocked(getPaymentAppData);
|
||||
|
||||
describe("processPaymentRefund", () => {
|
||||
const mockStartTime = new Date("2025-01-01T10:00:00Z");
|
||||
|
||||
@@ -53,19 +55,29 @@ describe("processPaymentRefund", () => {
|
||||
refundDaysCount: 3,
|
||||
};
|
||||
|
||||
const mockPaymentAppCredentials = [
|
||||
{
|
||||
key: "key1",
|
||||
appId: "123",
|
||||
app: {
|
||||
categories: ["category1"],
|
||||
dirName: "app1",
|
||||
},
|
||||
},
|
||||
];
|
||||
const mockApp = {
|
||||
id: "123",
|
||||
slug: "stripe",
|
||||
dirName: "app1",
|
||||
categories: ["payment"],
|
||||
keys: {},
|
||||
enabled: true,
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
const mockCredential = {
|
||||
id: 1,
|
||||
key: "key1",
|
||||
appId: "123",
|
||||
userId: 1,
|
||||
teamId: null,
|
||||
type: "stripe_payment",
|
||||
invalid: false,
|
||||
};
|
||||
|
||||
beforeEach(async () => {
|
||||
vi.clearAllMocks();
|
||||
await prismock.credential.deleteMany();
|
||||
await prismock.app.deleteMany();
|
||||
});
|
||||
|
||||
it("should not process refund if no teamId or eventType owner", async () => {
|
||||
@@ -80,14 +92,15 @@ describe("processPaymentRefund", () => {
|
||||
});
|
||||
|
||||
it("should not process refund if refund policy is NEVER", async () => {
|
||||
(getPaymentAppData as any).mockReturnValueOnce({ ...mockAppData, refundPolicy: RefundPolicy.NEVER });
|
||||
mockedGetPaymentAppData.mockReturnValueOnce({ ...mockAppData, refundPolicy: RefundPolicy.NEVER });
|
||||
await processPaymentRefund({ booking: mockBooking, teamId: 1 });
|
||||
expect(handlePaymentRefund).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should process refund if refund policy is DAYS and within refund window", async () => {
|
||||
(getPaymentAppData as any).mockReturnValueOnce(mockAppData);
|
||||
prismaMock.credential.findMany.mockResolvedValueOnce(mockPaymentAppCredentials);
|
||||
mockedGetPaymentAppData.mockReturnValueOnce(mockAppData);
|
||||
await prismock.app.create({ data: mockApp });
|
||||
await prismock.credential.create({ data: mockCredential });
|
||||
|
||||
const mockNow = dayjs(mockStartTime).subtract(8, "days").toDate();
|
||||
vi.useFakeTimers();
|
||||
@@ -95,12 +108,19 @@ describe("processPaymentRefund", () => {
|
||||
|
||||
await processPaymentRefund({ booking: mockBooking, teamId: 1 });
|
||||
|
||||
expect(handlePaymentRefund).toHaveBeenCalledWith(1, mockPaymentAppCredentials[0]);
|
||||
expect(handlePaymentRefund).toHaveBeenCalledWith(
|
||||
1,
|
||||
expect.objectContaining({
|
||||
key: "key1",
|
||||
appId: "123",
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it("should not process refund if past the refund deadline", async () => {
|
||||
(getPaymentAppData as any).mockReturnValueOnce(mockAppData);
|
||||
prismaMock.credential.findMany.mockResolvedValueOnce(mockPaymentAppCredentials);
|
||||
mockedGetPaymentAppData.mockReturnValueOnce(mockAppData);
|
||||
await prismock.app.create({ data: mockApp });
|
||||
await prismock.credential.create({ data: mockCredential });
|
||||
|
||||
const mockNow = dayjs(mockStartTime).subtract(2, "days").toDate();
|
||||
|
||||
@@ -113,8 +133,9 @@ describe("processPaymentRefund", () => {
|
||||
});
|
||||
|
||||
it("should process refund if business days are considered and before deadline", async () => {
|
||||
(getPaymentAppData as any).mockReturnValueOnce({ ...mockAppData, refundCountCalendarDays: false });
|
||||
prismaMock.credential.findMany.mockResolvedValueOnce(mockPaymentAppCredentials);
|
||||
mockedGetPaymentAppData.mockReturnValueOnce({ ...mockAppData, refundCountCalendarDays: false });
|
||||
await prismock.app.create({ data: mockApp });
|
||||
await prismock.credential.create({ data: mockCredential });
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
//@ts-ignore
|
||||
@@ -125,12 +146,19 @@ describe("processPaymentRefund", () => {
|
||||
|
||||
await processPaymentRefund({ booking: mockBooking, teamId: 1 });
|
||||
|
||||
expect(handlePaymentRefund).toHaveBeenCalledWith(1, mockPaymentAppCredentials[0]);
|
||||
expect(handlePaymentRefund).toHaveBeenCalledWith(
|
||||
1,
|
||||
expect.objectContaining({
|
||||
key: "key1",
|
||||
appId: "123",
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it("should not process refund if business days are considered and after deadline", async () => {
|
||||
(getPaymentAppData as any).mockReturnValueOnce({ ...mockAppData, refundCountCalendarDays: false });
|
||||
prismaMock.credential.findMany.mockResolvedValueOnce(mockPaymentAppCredentials);
|
||||
mockedGetPaymentAppData.mockReturnValueOnce({ ...mockAppData, refundCountCalendarDays: false });
|
||||
await prismock.app.create({ data: mockApp });
|
||||
await prismock.credential.create({ data: mockCredential });
|
||||
|
||||
const mockNow = dayjs(mockStartTime).subtract(3, "days").toDate();
|
||||
|
||||
@@ -143,8 +171,7 @@ describe("processPaymentRefund", () => {
|
||||
});
|
||||
|
||||
it("should not process refund if paymentAppCredential is not found", async () => {
|
||||
(getPaymentAppData as any).mockReturnValueOnce(mockAppData);
|
||||
prismaMock.credential.findMany.mockResolvedValueOnce([]);
|
||||
mockedGetPaymentAppData.mockReturnValueOnce(mockAppData);
|
||||
|
||||
await processPaymentRefund({ booking: mockBooking, teamId: 1 });
|
||||
expect(handlePaymentRefund).not.toHaveBeenCalled();
|
||||
+3
-4
@@ -1,12 +1,11 @@
|
||||
import { getPaymentAppData } from "@calcom/app-store/_utils/payments/getPaymentAppData";
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { handlePaymentRefund } from "@calcom/features/bookings/lib/payment/handlePaymentRefund";
|
||||
import { RefundPolicy } from "@calcom/lib/payment/types";
|
||||
import prisma from "@calcom/prisma";
|
||||
import type { Payment, Prisma } from "@calcom/prisma/client";
|
||||
import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
|
||||
|
||||
import { getPaymentAppData } from "../getPaymentAppData";
|
||||
import { handlePaymentRefund } from "./handlePaymentRefund";
|
||||
import { RefundPolicy } from "./types";
|
||||
|
||||
export const processPaymentRefund = async ({
|
||||
booking,
|
||||
teamId,
|
||||
File renamed without changes.
File renamed without changes.
@@ -9,12 +9,12 @@ import {
|
||||
import { eventTypeMetaDataSchemaWithTypedApps } from "@calcom/app-store/zod-utils";
|
||||
import { sendCancelledEmailsAndSMS } from "@calcom/emails";
|
||||
import { getCalEventResponses } from "@calcom/features/bookings/lib/getCalEventResponses";
|
||||
import { deletePayment } from "@calcom/features/bookings/lib/payment/deletePayment";
|
||||
import { deleteWebhookScheduledTriggers } from "@calcom/features/webhooks/lib/scheduleTrigger";
|
||||
import { buildNonDelegationCredential } from "@calcom/lib/delegationCredential/server";
|
||||
import { isPrismaObjOrUndefined } from "@calcom/lib/isPrismaObj";
|
||||
import { parseRecurringEvent } from "@calcom/lib/isRecurringEvent";
|
||||
import { DailyLocationType } from "@calcom/lib/location";
|
||||
import { deletePayment } from "@calcom/lib/payment/deletePayment";
|
||||
import { getTranslation } from "@calcom/lib/server/i18n";
|
||||
import { bookingMinimalSelect, prisma } from "@calcom/prisma";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
|
||||
@@ -8,6 +8,7 @@ import { sendAttendeeRequestEmailAndSMS, sendOrganizerRequestEmail } from "@calc
|
||||
import { doesBookingRequireConfirmation } from "@calcom/features/bookings/lib/doesBookingRequireConfirmation";
|
||||
import { getAllCredentialsIncludeServiceAccountKey } from "@calcom/features/bookings/lib/getAllCredentialsForUsersOnEvent/getAllCredentials";
|
||||
import { handleConfirmation } from "@calcom/features/bookings/lib/handleConfirmation";
|
||||
import { getBooking } from "@calcom/features/bookings/lib/payment/getBooking";
|
||||
import stripe from "@calcom/features/ee/payments/server/stripe";
|
||||
import { getPlatformParams } from "@calcom/features/platform-oauth-client/get-platform-params";
|
||||
import { PlatformOAuthClientRepository } from "@calcom/features/platform-oauth-client/platform-oauth-client.repository";
|
||||
@@ -16,7 +17,6 @@ import { IS_PRODUCTION } from "@calcom/lib/constants";
|
||||
import { getErrorFromUnknown } from "@calcom/lib/errors";
|
||||
import { HttpError as HttpCode } from "@calcom/lib/http-error";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { getBooking } from "@calcom/lib/payment/getBooking";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { useMemo } from "react";
|
||||
|
||||
import { getPaymentAppData } from "@calcom/app-store/_utils/payments/getPaymentAppData";
|
||||
import { eventTypeMetaDataSchemaWithTypedApps } from "@calcom/app-store/zod-utils";
|
||||
import { Price } from "@calcom/features/bookings/components/event-meta/Price";
|
||||
import { PriceIcon } from "@calcom/features/bookings/components/event-meta/PriceIcon";
|
||||
import { getPaymentAppData } from "@calcom/lib/getPaymentAppData";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { parseRecurringEvent } from "@calcom/lib/isRecurringEvent";
|
||||
import { markdownToSafeHTML } from "@calcom/lib/markdownToSafeHTML";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { getPaymentAppData } from "@calcom/app-store/_utils/payments/getPaymentAppData";
|
||||
import { eventTypeMetaDataSchemaWithTypedApps } from "@calcom/app-store/zod-utils";
|
||||
import type { EventTypeSetupProps } from "@calcom/features/eventtypes/lib/types";
|
||||
import { getPaymentAppData } from "@calcom/lib/getPaymentAppData";
|
||||
|
||||
import InstantEventController from "./InstantEventController";
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { getPaymentAppData } from "@calcom/app-store/_utils/payments/getPaymentAppData";
|
||||
import { eventTypeMetaDataSchemaWithTypedApps } from "@calcom/app-store/zod-utils";
|
||||
import { getPaymentAppData } from "@calcom/lib/getPaymentAppData";
|
||||
|
||||
import type { RecurringEventControllerProps } from "./RecurringEventController";
|
||||
import RecurringEventController from "./RecurringEventController";
|
||||
|
||||
@@ -6,9 +6,9 @@ import type { TFunction } from "i18next";
|
||||
import { useMemo, useState, useEffect } from "react";
|
||||
import type { UseFormReturn } from "react-hook-form";
|
||||
|
||||
import { getPaymentAppData } from "@calcom/app-store/_utils/payments/getPaymentAppData";
|
||||
import useLockedFieldsManager from "@calcom/features/ee/managed-event-types/hooks/useLockedFieldsManager";
|
||||
import type { EventTypeSetupProps, FormValues } from "@calcom/features/eventtypes/lib/types";
|
||||
import { getPaymentAppData } from "@calcom/lib/getPaymentAppData";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import type { VerticalTabItemProps } from "@calcom/ui/components/navigation";
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import type { TFunction } from "i18next";
|
||||
import { useMemo } from "react";
|
||||
import type { UseFormReturn } from "react-hook-form";
|
||||
|
||||
import { getPaymentAppData } from "@calcom/app-store/_utils/payments/getPaymentAppData";
|
||||
import { eventTypeMetaDataSchemaWithTypedApps } from "@calcom/app-store/zod-utils";
|
||||
import useLockedFieldsManager from "@calcom/features/ee/managed-event-types/hooks/useLockedFieldsManager";
|
||||
import type { Workflow } from "@calcom/features/ee/workflows/lib/types";
|
||||
@@ -14,7 +15,6 @@ import type {
|
||||
FormValues,
|
||||
EventTypeApps,
|
||||
} from "@calcom/features/eventtypes/lib/types";
|
||||
import { getPaymentAppData } from "@calcom/lib/getPaymentAppData";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import type { VerticalTabItemProps } from "@calcom/ui/components/navigation";
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import React, { Suspense } from "react";
|
||||
|
||||
import { getPaymentAppData } from "@calcom/app-store/_utils/payments/getPaymentAppData";
|
||||
import { getSuccessPageLocationMessage } from "@calcom/app-store/locations";
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { PayIcon } from "@calcom/features/bookings/components/event-meta/PayIcon";
|
||||
import { Price } from "@calcom/features/bookings/components/event-meta/Price";
|
||||
import type { PaymentPageProps } from "@calcom/features/ee/payments/pages/payment";
|
||||
import { APP_NAME, WEBSITE_URL } from "@calcom/lib/constants";
|
||||
import { getPaymentAppData } from "@calcom/lib/getPaymentAppData";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { isBrowserLocale24h } from "@calcom/lib/timeFormat";
|
||||
import { CURRENT_TIMEZONE } from "@calcom/lib/timezoneConstants";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import getEnabledAppsFromCredentials from "@calcom/app-store/_utils/getEnabledAppsFromCredentials";
|
||||
import getApps from "@calcom/app-store/utils";
|
||||
import handleDeleteCredential from "@calcom/features/credentials/handleDeleteCredential";
|
||||
import getEnabledAppsFromCredentials from "@calcom/lib/apps/getEnabledAppsFromCredentials";
|
||||
import addDelegationCredential from "@calcom/trpc/server/routers/viewer/delegationCredential/add.handler";
|
||||
|
||||
export type { TDependencyData } from "@calcom/app-store/_appRegistry";
|
||||
|
||||
@@ -5,6 +5,7 @@ import { getAllCredentialsIncludeServiceAccountKey } from "@calcom/features/book
|
||||
import { getCalEventResponses } from "@calcom/features/bookings/lib/getCalEventResponses";
|
||||
import { handleConfirmation } from "@calcom/features/bookings/lib/handleConfirmation";
|
||||
import { handleWebhookTrigger } from "@calcom/features/bookings/lib/handleWebhookTrigger";
|
||||
import { processPaymentRefund } from "@calcom/features/bookings/lib/payment/processPaymentRefund";
|
||||
import { workflowSelect } from "@calcom/features/ee/workflows/lib/getAllWorkflows";
|
||||
import type { GetSubscriberOptions } from "@calcom/features/webhooks/lib/getWebhooks";
|
||||
import type { EventPayloadType, EventTypeInfo } from "@calcom/features/webhooks/lib/sendPayload";
|
||||
@@ -13,7 +14,6 @@ import getOrgIdFromMemberOrTeamId from "@calcom/lib/getOrgIdFromMemberOrTeamId";
|
||||
import { getTeamIdFromEventType } from "@calcom/lib/getTeamIdFromEventType";
|
||||
import { isPrismaObjOrUndefined } from "@calcom/lib/isPrismaObj";
|
||||
import { parseRecurringEvent } from "@calcom/lib/isRecurringEvent";
|
||||
import { processPaymentRefund } from "@calcom/lib/payment/processPaymentRefund";
|
||||
import { getUsersCredentialsIncludeServiceAccountKey } from "@calcom/lib/server/getUsersCredentials";
|
||||
import { getTranslation } from "@calcom/lib/server/i18n";
|
||||
import { WorkflowService } from "@calcom/lib/server/service/workflows";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { handleNoShowFee } from "@calcom/lib/payment/handleNoShowFee";
|
||||
import { handleNoShowFee } from "@calcom/features/bookings/lib/payment/handleNoShowFee";
|
||||
import { BookingRepository } from "@calcom/lib/server/repository/booking";
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
|
||||
|
||||
@@ -2715,7 +2715,7 @@ __metadata:
|
||||
"@axiomhq/winston": ^1.2.0
|
||||
"@calcom/platform-constants": "*"
|
||||
"@calcom/platform-enums": "*"
|
||||
"@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.358"
|
||||
"@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.359"
|
||||
"@calcom/platform-types": "*"
|
||||
"@calcom/platform-utils": "*"
|
||||
"@calcom/prisma": "*"
|
||||
@@ -3775,13 +3775,13 @@ __metadata:
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@calcom/platform-libraries@npm:@calcom/platform-libraries@0.0.358":
|
||||
version: 0.0.358
|
||||
resolution: "@calcom/platform-libraries@npm:0.0.358"
|
||||
"@calcom/platform-libraries@npm:@calcom/platform-libraries@0.0.359":
|
||||
version: 0.0.359
|
||||
resolution: "@calcom/platform-libraries@npm:0.0.359"
|
||||
dependencies:
|
||||
"@calcom/features": "*"
|
||||
"@calcom/lib": "*"
|
||||
checksum: 2a3436a24c62c38aa1299237cc2c650826a3cfc9cbffa5cc2f37244abed13dc0f55dbd314037e16af3168b9e7bfa4b62abf20aee00654e8aa24ab4bc7e76c642
|
||||
checksum: 265d73c95334e34d076406d943ba6e80cff0037b4cf4620ed86519d41ac8e24e643000b84773c1f17cece28c4f50bd1cd70a0306764908248a55af49b44f054f
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
|
||||
Reference in new issue
Block a user