Merge remote-tracking branch 'origin/main' into fix/less-recurring-bookings-failure
commit
a3632df93f
|
@ -283,8 +283,8 @@ const ProfileView = () => {
|
|||
/>
|
||||
|
||||
<div className="border-subtle mt-6 rounded-lg rounded-b-none border border-b-0 p-6">
|
||||
<Label className="text-base font-semibold text-red-700">{t("danger_zone")}</Label>
|
||||
<p className="text-subtle">{t("account_deletion_cannot_be_undone")}</p>
|
||||
<Label className="mb-0 text-base font-semibold text-red-700">{t("danger_zone")}</Label>
|
||||
<p className="text-subtle text-sm">{t("account_deletion_cannot_be_undone")}</p>
|
||||
</div>
|
||||
{/* Delete account Dialog */}
|
||||
<Dialog open={deleteAccountOpen} onOpenChange={setDeleteAccountOpen}>
|
||||
|
|
|
@ -605,7 +605,7 @@
|
|||
"hide_book_a_team_member": "Hide Book a Team Member Button",
|
||||
"hide_book_a_team_member_description": "Hide Book a Team Member Button from your public pages.",
|
||||
"danger_zone": "Danger zone",
|
||||
"account_deletion_cannot_be_undone":"Careful. Account deletion cannot be undone.",
|
||||
"account_deletion_cannot_be_undone":"Be Careful. Account deletion cannot be undone.",
|
||||
"back": "Back",
|
||||
"cancel": "Cancel",
|
||||
"cancel_all_remaining": "Cancel all remaining",
|
||||
|
|
|
@ -66,6 +66,7 @@ type InputUser = Omit<typeof TestData.users.example, "defaultScheduleId"> & {
|
|||
id: number;
|
||||
defaultScheduleId?: number | null;
|
||||
credentials?: InputCredential[];
|
||||
organizationId?: number | null;
|
||||
selectedCalendars?: InputSelectedCalendar[];
|
||||
schedules: {
|
||||
// Allows giving id in the input directly so that it can be referenced somewhere else as well
|
||||
|
@ -419,6 +420,7 @@ async function addUsers(users: InputUser[]) {
|
|||
},
|
||||
};
|
||||
}
|
||||
|
||||
return newUser;
|
||||
});
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
|
@ -459,6 +461,16 @@ export async function createBookingScenario(data: ScenarioData) {
|
|||
};
|
||||
}
|
||||
|
||||
export async function createOrganization(orgData: { name: string; slug: string }) {
|
||||
const org = await prismock.team.create({
|
||||
data: {
|
||||
name: orgData.name,
|
||||
slug: orgData.slug,
|
||||
},
|
||||
});
|
||||
return org;
|
||||
}
|
||||
|
||||
// async function addPaymentsToDb(payments: Prisma.PaymentCreateInput[]) {
|
||||
// await prismaMock.payment.createMany({
|
||||
// data: payments,
|
||||
|
@ -735,6 +747,7 @@ export function getOrganizer({
|
|||
}) {
|
||||
return {
|
||||
...TestData.users.example,
|
||||
organizationId: null as null | number,
|
||||
name,
|
||||
email,
|
||||
id,
|
||||
|
@ -746,24 +759,33 @@ export function getOrganizer({
|
|||
};
|
||||
}
|
||||
|
||||
export function getScenarioData({
|
||||
organizer,
|
||||
eventTypes,
|
||||
usersApartFromOrganizer = [],
|
||||
apps = [],
|
||||
webhooks,
|
||||
bookings,
|
||||
}: // hosts = [],
|
||||
{
|
||||
organizer: ReturnType<typeof getOrganizer>;
|
||||
eventTypes: ScenarioData["eventTypes"];
|
||||
apps?: ScenarioData["apps"];
|
||||
usersApartFromOrganizer?: ScenarioData["users"];
|
||||
webhooks?: ScenarioData["webhooks"];
|
||||
bookings?: ScenarioData["bookings"];
|
||||
// hosts?: ScenarioData["hosts"];
|
||||
}) {
|
||||
export function getScenarioData(
|
||||
{
|
||||
organizer,
|
||||
eventTypes,
|
||||
usersApartFromOrganizer = [],
|
||||
apps = [],
|
||||
webhooks,
|
||||
bookings,
|
||||
}: // hosts = [],
|
||||
{
|
||||
organizer: ReturnType<typeof getOrganizer>;
|
||||
eventTypes: ScenarioData["eventTypes"];
|
||||
apps?: ScenarioData["apps"];
|
||||
usersApartFromOrganizer?: ScenarioData["users"];
|
||||
webhooks?: ScenarioData["webhooks"];
|
||||
bookings?: ScenarioData["bookings"];
|
||||
// hosts?: ScenarioData["hosts"];
|
||||
},
|
||||
org?: { id: number | null } | undefined | null
|
||||
) {
|
||||
const users = [organizer, ...usersApartFromOrganizer];
|
||||
if (org) {
|
||||
users.forEach((user) => {
|
||||
user.organizationId = org.id;
|
||||
});
|
||||
}
|
||||
|
||||
eventTypes.forEach((eventType) => {
|
||||
if (
|
||||
eventType.users?.filter((eventTypeUser) => {
|
||||
|
|
|
@ -53,24 +53,26 @@ import {
|
|||
import { createMockNextJsRequest } from "./lib/createMockNextJsRequest";
|
||||
import { getMockRequestDataForBooking } from "./lib/getMockRequestDataForBooking";
|
||||
import { setupAndTeardown } from "./lib/setupAndTeardown";
|
||||
import { testWithAndWithoutOrg } from "./lib/test";
|
||||
|
||||
export type CustomNextApiRequest = NextApiRequest & Request;
|
||||
|
||||
export type CustomNextApiResponse = NextApiResponse & Response;
|
||||
// Local test runs sometime gets too slow
|
||||
const timeout = process.env.CI ? 5000 : 20000;
|
||||
|
||||
describe("handleNewBooking", () => {
|
||||
setupAndTeardown();
|
||||
|
||||
describe("Fresh/New Booking:", () => {
|
||||
test(
|
||||
testWithAndWithoutOrg(
|
||||
`should create a successful booking with Cal Video(Daily Video) if no explicit location is provided
|
||||
1. Should create a booking in the database
|
||||
2. Should send emails to the booker as well as organizer
|
||||
3. Should create a booking in the event's destination calendar
|
||||
3. Should trigger BOOKING_CREATED webhook
|
||||
`,
|
||||
async ({ emails }) => {
|
||||
async ({ emails, org }) => {
|
||||
const handleNewBooking = (await import("@calcom/features/bookings/lib/handleNewBooking")).default;
|
||||
const booker = getBooker({
|
||||
email: "booker@example.com",
|
||||
|
@ -89,37 +91,41 @@ describe("handleNewBooking", () => {
|
|||
externalId: "organizer@google-calendar.com",
|
||||
},
|
||||
});
|
||||
|
||||
await createBookingScenario(
|
||||
getScenarioData({
|
||||
webhooks: [
|
||||
{
|
||||
userId: organizer.id,
|
||||
eventTriggers: ["BOOKING_CREATED"],
|
||||
subscriberUrl: "http://my-webhook.example.com",
|
||||
active: true,
|
||||
eventTypeId: 1,
|
||||
appId: null,
|
||||
},
|
||||
],
|
||||
eventTypes: [
|
||||
{
|
||||
id: 1,
|
||||
slotInterval: 45,
|
||||
length: 45,
|
||||
users: [
|
||||
{
|
||||
id: 101,
|
||||
},
|
||||
],
|
||||
destinationCalendar: {
|
||||
integration: "google_calendar",
|
||||
externalId: "event-type-1@google-calendar.com",
|
||||
getScenarioData(
|
||||
{
|
||||
webhooks: [
|
||||
{
|
||||
userId: organizer.id,
|
||||
eventTriggers: ["BOOKING_CREATED"],
|
||||
subscriberUrl: "http://my-webhook.example.com",
|
||||
active: true,
|
||||
eventTypeId: 1,
|
||||
appId: null,
|
||||
},
|
||||
},
|
||||
],
|
||||
organizer,
|
||||
apps: [TestData.apps["google-calendar"], TestData.apps["daily-video"]],
|
||||
})
|
||||
],
|
||||
eventTypes: [
|
||||
{
|
||||
id: 1,
|
||||
slotInterval: 45,
|
||||
length: 45,
|
||||
users: [
|
||||
{
|
||||
id: 101,
|
||||
},
|
||||
],
|
||||
destinationCalendar: {
|
||||
integration: "google_calendar",
|
||||
externalId: "event-type-1@google-calendar.com",
|
||||
},
|
||||
},
|
||||
],
|
||||
organizer,
|
||||
apps: [TestData.apps["google-calendar"], TestData.apps["daily-video"]],
|
||||
},
|
||||
org?.organization
|
||||
)
|
||||
);
|
||||
|
||||
mockSuccessfulVideoMeetingCreation({
|
||||
|
@ -197,6 +203,7 @@ describe("handleNewBooking", () => {
|
|||
expectSuccessfulBookingCreationEmails({
|
||||
booking: {
|
||||
uid: createdBooking.uid!,
|
||||
urlOrigin: org ? org.urlOrigin : WEBAPP_URL,
|
||||
},
|
||||
booker,
|
||||
organizer,
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
import type { TestFunction } from "vitest";
|
||||
|
||||
import { test } from "@calcom/web/test/fixtures/fixtures";
|
||||
import type { Fixtures } from "@calcom/web/test/fixtures/fixtures";
|
||||
import { createOrganization } from "@calcom/web/test/utils/bookingScenario/bookingScenario";
|
||||
|
||||
const _testWithAndWithoutOrg = (
|
||||
description: Parameters<typeof testWithAndWithoutOrg>[0],
|
||||
fn: Parameters<typeof testWithAndWithoutOrg>[1],
|
||||
timeout: Parameters<typeof testWithAndWithoutOrg>[2],
|
||||
mode: "only" | "skip" | "run" = "run"
|
||||
) => {
|
||||
const t = mode === "only" ? test.only : mode === "skip" ? test.skip : test;
|
||||
t(
|
||||
`${description} - With org`,
|
||||
async ({ emails, meta, task, onTestFailed, expect, skip }) => {
|
||||
const org = await createOrganization({
|
||||
name: "Test Org",
|
||||
slug: "testorg",
|
||||
});
|
||||
|
||||
await fn({
|
||||
meta,
|
||||
task,
|
||||
onTestFailed,
|
||||
expect,
|
||||
emails,
|
||||
skip,
|
||||
org: {
|
||||
organization: org,
|
||||
urlOrigin: `http://${org.slug}.cal.local:3000`,
|
||||
},
|
||||
});
|
||||
},
|
||||
timeout
|
||||
);
|
||||
|
||||
t(
|
||||
`${description}`,
|
||||
async ({ emails, meta, task, onTestFailed, expect, skip }) => {
|
||||
await fn({
|
||||
emails,
|
||||
meta,
|
||||
task,
|
||||
onTestFailed,
|
||||
expect,
|
||||
skip,
|
||||
org: null,
|
||||
});
|
||||
},
|
||||
timeout
|
||||
);
|
||||
};
|
||||
|
||||
export const testWithAndWithoutOrg = (
|
||||
description: string,
|
||||
fn: TestFunction<
|
||||
Fixtures & {
|
||||
org: {
|
||||
organization: { id: number | null };
|
||||
urlOrigin?: string;
|
||||
} | null;
|
||||
}
|
||||
>,
|
||||
timeout?: number
|
||||
) => {
|
||||
_testWithAndWithoutOrg(description, fn, timeout, "run");
|
||||
};
|
||||
|
||||
testWithAndWithoutOrg.only = ((description, fn) => {
|
||||
_testWithAndWithoutOrg(description, fn, "only");
|
||||
}) as typeof _testWithAndWithoutOrg;
|
||||
|
||||
testWithAndWithoutOrg.skip = ((description, fn) => {
|
||||
_testWithAndWithoutOrg(description, fn, "skip");
|
||||
}) as typeof _testWithAndWithoutOrg;
|
|
@ -96,7 +96,10 @@ export function subdomainSuffix() {
|
|||
|
||||
export function getOrgFullOrigin(slug: string, options: { protocol: boolean } = { protocol: true }) {
|
||||
if (!slug) return WEBAPP_URL;
|
||||
return `${options.protocol ? `${new URL(WEBAPP_URL).protocol}//` : ""}${slug}.${subdomainSuffix()}`;
|
||||
const orgFullOrigin = `${
|
||||
options.protocol ? `${new URL(WEBAPP_URL).protocol}//` : ""
|
||||
}${slug}.${subdomainSuffix()}`;
|
||||
return orgFullOrigin;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,7 +5,8 @@ import dayjs from "@calcom/dayjs";
|
|||
import { buildDateRanges, processDateOverride, processWorkingHours, subtract } from "./date-ranges";
|
||||
|
||||
describe("processWorkingHours", () => {
|
||||
it("should return the correct working hours given a specific availability, timezone, and date range", () => {
|
||||
// TEMPORAIRLY SKIPPING THIS TEST - Started failing after 29th Oct
|
||||
it.skip("should return the correct working hours given a specific availability, timezone, and date range", () => {
|
||||
const item = {
|
||||
days: [1, 2, 3, 4, 5], // Monday to Friday
|
||||
startTime: new Date(Date.UTC(2023, 5, 12, 8, 0)), // 8 AM
|
||||
|
@ -47,8 +48,8 @@ describe("processWorkingHours", () => {
|
|||
|
||||
expect(lastAvailableSlot.start.date()).toBe(31);
|
||||
});
|
||||
|
||||
it("should return the correct working hours in the month were DST ends", () => {
|
||||
// TEMPORAIRLY SKIPPING THIS TEST - Started failing after 29th Oct
|
||||
it.skip("should return the correct working hours in the month were DST ends", () => {
|
||||
const item = {
|
||||
days: [0, 1, 2, 3, 4, 5, 6], // Monday to Sunday
|
||||
startTime: new Date(Date.UTC(2023, 5, 12, 8, 0)), // 8 AM
|
||||
|
|
|
@ -22,6 +22,7 @@ import { TRPCError } from "@trpc/server";
|
|||
import { getDefaultScheduleId } from "../viewer/availability/util";
|
||||
import { updateUserMetadataAllowedKeys, type TUpdateProfileInputSchema } from "./updateProfile.schema";
|
||||
|
||||
const log = logger.getSubLogger({ prefix: ["updateProfile"] });
|
||||
type UpdateProfileOptions = {
|
||||
ctx: {
|
||||
user: NonNullable<TrpcSessionUser>;
|
||||
|
@ -35,6 +36,7 @@ export const updateProfileHandler = async ({ ctx, input }: UpdateProfileOptions)
|
|||
const userMetadata = handleUserMetadata({ ctx, input });
|
||||
const data: Prisma.UserUpdateInput = {
|
||||
...input,
|
||||
avatar: await getAvatarToSet(input.avatar),
|
||||
metadata: userMetadata,
|
||||
};
|
||||
|
||||
|
@ -61,12 +63,6 @@ export const updateProfileHandler = async ({ ctx, input }: UpdateProfileOptions)
|
|||
}
|
||||
}
|
||||
}
|
||||
if (input.avatar) {
|
||||
data.avatar = await resizeBase64Image(input.avatar);
|
||||
}
|
||||
if (input.avatar === null) {
|
||||
data.avatar = null;
|
||||
}
|
||||
|
||||
if (isPremiumUsername) {
|
||||
const stripeCustomerId = userMetadata?.stripeCustomerId;
|
||||
|
@ -234,3 +230,17 @@ const handleUserMetadata = ({ ctx, input }: UpdateProfileOptions) => {
|
|||
// Required so we don't override and delete saved values
|
||||
return { ...userMetadata, ...cleanMetadata };
|
||||
};
|
||||
|
||||
async function getAvatarToSet(avatar: string | null | undefined) {
|
||||
if (avatar === null || avatar === undefined) {
|
||||
return avatar;
|
||||
}
|
||||
|
||||
if (!avatar.startsWith("data:image")) {
|
||||
// Non Base64 avatar currently could only be the dynamic avatar URL(i.e. /{USER}/avatar.png). If we allow setting that URL, we would get infinite redirects on /user/avatar.ts endpoint
|
||||
log.warn("Non Base64 avatar, ignored it", { avatar });
|
||||
// `undefined` would not ignore the avatar, but `null` would remove it. So, we return `undefined` here.
|
||||
return undefined;
|
||||
}
|
||||
return await resizeBase64Image(avatar);
|
||||
}
|
||||
|
|
|
@ -2,9 +2,6 @@ import { defineConfig } from "vitest/config";
|
|||
|
||||
process.env.INTEGRATION_TEST_MODE = "true";
|
||||
|
||||
// We can't set it during tests because it is used as soon as _metadata.ts is imported which happens before tests start running
|
||||
process.env.DAILY_API_KEY = "MOCK_DAILY_API_KEY";
|
||||
|
||||
export default defineConfig({
|
||||
test: {
|
||||
coverage: {
|
||||
|
@ -13,3 +10,12 @@ export default defineConfig({
|
|||
testTimeout: 500000,
|
||||
},
|
||||
});
|
||||
|
||||
setEnvVariablesThatAreUsedBeforeSetup();
|
||||
|
||||
function setEnvVariablesThatAreUsedBeforeSetup() {
|
||||
// We can't set it during tests because it is used as soon as _metadata.ts is imported which happens before tests start running
|
||||
process.env.DAILY_API_KEY = "MOCK_DAILY_API_KEY";
|
||||
// With same env variable, we can test both non org and org booking scenarios
|
||||
process.env.NEXT_PUBLIC_WEBAPP_URL = "http://app.cal.local:3000";
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue