fix: Dynamic Group Booking link for organization (#12825)

Co-authored-by: Erik <[email protected]>
Co-authored-by: Omar López <[email protected]>
This commit is contained in:
authored and GitHub committed 2023-12-19 17:42:40 +00:00
1 parent 31b88c5537
commit a8975f541f
11 files changed
+106 -33

No files matched your search

+1 -1
View File
@@ -185,7 +185,7 @@ async function getUserPageProps(context: GetServerSidePropsContext) {
const user = await prisma.user.findFirst({
where: {
username,
organization: userOrgQuery(context.req.headers.host ?? "", context.params?.orgSlug),
organization: userOrgQuery(context.req, context.params?.orgSlug),
},
select: {
away: true,
@@ -14,15 +14,15 @@ import TeamTypePage, { getServerSideProps as GSSTeamTypePage } from "../../../te
const paramsSchema = z.object({
orgSlug: z.string().transform((s) => slugify(s)),
user: z.string().transform((s) => slugify(s)),
user: z.string(),
type: z.string().transform((s) => slugify(s)),
});
export const getServerSideProps = async (ctx: GetServerSidePropsContext) => {
const { user: teamOrUserSlug, orgSlug, type } = paramsSchema.parse(ctx.params);
const { user: teamOrUserSlugOrDynamicGroup, orgSlug, type } = paramsSchema.parse(ctx.params);
const team = await prisma.team.findFirst({
where: {
slug: teamOrUserSlug,
slug: slugify(teamOrUserSlugOrDynamicGroup),
parentId: {
not: null,
},
@@ -34,7 +34,7 @@ export const getServerSideProps = async (ctx: GetServerSidePropsContext) => {
});
if (team) {
const params = { slug: teamOrUserSlug, type };
const params = { slug: teamOrUserSlugOrDynamicGroup, type };
return GSSTeamTypePage({
...ctx,
params: {
@@ -47,7 +47,7 @@ export const getServerSideProps = async (ctx: GetServerSidePropsContext) => {
},
});
}
const params = { user: teamOrUserSlug, type };
const params = { user: teamOrUserSlugOrDynamicGroup, type };
return GSSUserTypePage({
...ctx,
params: {
@@ -1,8 +1,11 @@
import { expect } from "@playwright/test";
import { MembershipRole } from "@calcom/prisma/client";
import { test } from "./lib/fixtures";
import {
bookTimeSlot,
doOnOrgDomain,
selectFirstAvailableTimeSlotNextMonth,
selectSecondAvailableTimeSlotNextMonth,
} from "./lib/testUtils";
@@ -58,3 +61,46 @@ test("dynamic booking", async ({ page, users }) => {
await expect(cancelledHeadline).toBeVisible();
});
});
test.describe("Organization:", () => {
test.afterEach(({ orgs, users }) => {
orgs.deleteAll();
users.deleteAll();
});
test("Can book a time slot for an organization", async ({ page, users, orgs }) => {
const org = await orgs.create({
name: "TestOrg",
});
const user1 = await users.create({
organizationId: org.id,
name: "User 1",
roleInOrganization: MembershipRole.ADMIN,
});
const user2 = await users.create({
organizationId: org.id,
name: "User 2",
roleInOrganization: MembershipRole.ADMIN,
});
await doOnOrgDomain(
{
orgSlug: org.slug,
page,
},
async () => {
await page.goto(`/${user1.username}+${user2.username}`);
await selectFirstAvailableTimeSlotNextMonth(page);
await bookTimeSlot(page, {
title: "Test meeting",
});
await expect(page.getByTestId("success-page")).toBeVisible();
// All the teammates should be in the booking
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
await expect(page.getByText(user1.name!, { exact: true })).toBeVisible();
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
await expect(page.getByText(user2.name!, { exact: true })).toBeVisible();
}
);
});
});
+18 -1
View File
@@ -134,12 +134,16 @@ export async function bookFirstEvent(page: Page) {
await bookEventOnThisPage(page);
}
export const bookTimeSlot = async (page: Page, opts?: { name?: string; email?: string }) => {
export const bookTimeSlot = async (page: Page, opts?: { name?: string; email?: string; title?: string }) => {
// --- fill form
await page.fill('[name="name"]', opts?.name ?? testName);
await page.fill('[name="email"]', opts?.email ?? testEmail);
if (opts?.title) {
await page.fill('[name="title"]', opts.title);
}
await page.press('[name="email"]', "Enter");
};
// Provide an standalone localize utility not managed by next-i18n
export async function localize(locale: string) {
const localeModule = `../../public/static/locales/${locale}/common.json`;
@@ -337,6 +341,19 @@ export async function fillStripeTestCheckout(page: Page) {
await page.click(".SubmitButton--complete-Shimmer");
}
export async function doOnOrgDomain(
{ orgSlug, page }: { orgSlug: string | null; page: Page },
callback: ({ page }: { page: Page }) => Promise<void>
) {
if (!orgSlug) {
throw new Error("orgSlug is not available");
}
page.setExtraHTTPHeaders({
"x-cal-force-slug": orgSlug,
});
await callback({ page });
}
// When App directory is there, this is the 404 page text. It is commented till it's disabled
// export const NotFoundPageText = "This page could not be found";
export const NotFoundPageText = "ERROR 404";
+1 -14
View File
@@ -1,4 +1,3 @@
import type { Page } from "@playwright/test";
import { expect } from "@playwright/test";
import { IS_TEAM_BILLING_ENABLED } from "@calcom/lib/constants";
@@ -9,6 +8,7 @@ import { test } from "./lib/fixtures";
import {
NotFoundPageText,
bookTimeSlot,
doOnOrgDomain,
fillStripeTestCheckout,
selectFirstAvailableTimeSlotNextMonth,
testName,
@@ -459,16 +459,3 @@ test.describe("Teams - Org", () => {
await page.waitForSelector("[data-testid=day]");
});
});
async function doOnOrgDomain(
{ orgSlug, page }: { orgSlug: string | null; page: Page },
callback: ({ page }: { page: Page }) => Promise<void>
) {
if (!orgSlug) {
throw new Error("orgSlug is not available");
}
page.setExtraHTTPHeaders({
"x-cal-force-slug": orgSlug,
});
await callback({ page });
}