Skip to content

Commit

Permalink
revert: "fix: view team bookings (#14079)" (#14561)
Browse files Browse the repository at this point in the history
This reverts commit f86c448.
  • Loading branch information
keithwillcode committed Apr 13, 2024
1 parent becad5e commit fd193e6
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 818 deletions.
209 changes: 0 additions & 209 deletions apps/web/playwright/bookings-list.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import { expect } from "@playwright/test";

import { randomString } from "@calcom/lib/random";
import slugify from "@calcom/lib/slugify";
import prisma from "@calcom/prisma";
import { BookingStatus } from "@calcom/prisma/client";
import { SchedulingType } from "@calcom/prisma/enums";

import { createTeamEventType } from "./fixtures/users";
import type { Fixtures } from "./lib/fixtures";
import { test } from "./lib/fixtures";
import { assertBookingVisibleFor, bookTeamEvent, bookUserEvent } from "./lib/testUtils";

test.afterEach(({ users }) => users.deleteAll());

Expand Down Expand Up @@ -67,137 +61,6 @@ test.describe("Bookings", () => {
secondUpcomingBooking.locator(`text=${bookingWhereFirstUserIsOrganizer!.title}`)
).toBeVisible();
});
test("collective eventType booking should be visible to team admin", async ({ page, users }) => {
const { owner1, owner2, commonUser, team1_teammate1 } = await createTeams(users);

const { team: team1 } = await owner1.getFirstTeamMembership();
const scenario = {
schedulingType: SchedulingType.COLLECTIVE,
teamEventTitle: `collective-team-event`,
teamEventSlug: slugify(`collective-team-event-${randomString(5)}`),
};

const eventType = await createTeamEventType(owner1, team1, scenario);
const { id: eventId, slug: evnetSlug } = eventType;

await prisma.host.createMany({
data: [
{
userId: commonUser.id,
eventTypeId: eventId,
isFixed: true,
},
{
userId: team1_teammate1.id,
eventTypeId: eventId,
isFixed: true,
},
],
});

// to test if booking is visible to team admin/owner even if he is not part of the booking
await prisma.host.deleteMany({
where: {
userId: owner1.id,
eventTypeId: eventId,
},
});

await bookTeamEvent(page, team1, eventType);

// booking should be visible for the team host even though he is not part of the booking
await assertBookingVisibleFor(owner1, page, eventType, true);
// booking should not be visible for other team host
await assertBookingVisibleFor(owner2, page, eventType, false);
// booking should be visible for commonUser as he is part of the booking
await assertBookingVisibleFor(commonUser, page, eventType, true);
// booking should be visible for team1_teammate1 as he is part of the booking
await assertBookingVisibleFor(team1_teammate1, page, eventType, true);
});
test("round-robin eventType booking should be visible to team admin", async ({ page, users }) => {
const { owner1, owner2, commonUser, team1_teammate1 } = await createTeams(users);

const { team: team1 } = await owner1.getFirstTeamMembership();
const scenario = {
schedulingType: SchedulingType.ROUND_ROBIN,
teamEventTitle: `round-robin-team-event`,
teamEventSlug: slugify(`round-robin-team-event-${randomString(5)}`),
};

const eventType = await createTeamEventType(owner1, team1, scenario);
const { id: eventId } = eventType;

await prisma.host.createMany({
data: [
{
userId: commonUser.id,
eventTypeId: eventId,
},
{
userId: team1_teammate1.id,
eventTypeId: eventId,
},
],
});

await prisma.host.deleteMany({
where: {
userId: owner1.id,
eventTypeId: eventId,
},
});

await bookTeamEvent(page, team1, eventType);

// booking should be visible for the team host even though he is not part of the booking
await assertBookingVisibleFor(owner1, page, eventType, true);
// bookings should not be visible for other team host
await assertBookingVisibleFor(owner2, page, eventType, false);
});
test("managed eventType booking should be visible to team admin", async ({ page, users }) => {
const { owner1, owner2, commonUser, team1_teammate1 } = await createTeams(users);

const { team: team1 } = await owner1.getFirstTeamMembership();

await owner1.apiLogin();
await page.goto(`/event-types?dialog=new&eventPage=team%2F${team1.slug}&teamId=${team1.id}`);
await page.getByTestId("managed-event-type").click();
await page.getByTestId("event-type-quick-chat").click();
await page.getByTestId("event-type-quick-chat").fill("managed-event");
await page.getByRole("button", { name: "Continue" }).click();
await page.getByTestId("vertical-tab-assignment").click();

await page.getByRole("combobox", { name: "assignment-dropdown" }).fill("commonUser");
await page.getByRole("combobox", { name: "assignment-dropdown" }).press("Enter");
await page.getByRole("combobox", { name: "assignment-dropdown" }).fill("team1_teammate1");
await page.getByRole("combobox", { name: "assignment-dropdown" }).press("Enter");
await page.getByTestId("update-eventtype").click();

const eventType = await owner1.getFirstTeamEvent(team1.id);

await bookUserEvent(page, commonUser, eventType);

// booking should be visible for the team host even though he is not part of the booking
await assertBookingVisibleFor(owner1, page, eventType, true);
// booking should not be visible for other team host
await assertBookingVisibleFor(owner2, page, eventType, false);
// booking should be visible for commonUser as he is part of the booking
await assertBookingVisibleFor(commonUser, page, eventType, true);
// booking should not be visible for team1_teammate1 as we booked for commonUser
await assertBookingVisibleFor(team1_teammate1, page, eventType, false);
});
test("individual team members booking should not be visible to team admin", async ({ page, users }) => {
const { owner1, owner2, commonUser, team1_teammate1 } = await createTeams(users);

const eventType = await commonUser.getFirstEventAsOwner();
await bookUserEvent(page, commonUser, eventType);
// non-team bookings should not be visible for the team host
await assertBookingVisibleFor(owner1, page, eventType, false);
// non-team bookings should not be visible for other team host
await assertBookingVisibleFor(owner2, page, eventType, false);
// booking should be visible for commonUser as he is part of the booking
await assertBookingVisibleFor(commonUser, page, eventType, true);
});
});
});

Expand Down Expand Up @@ -248,75 +111,3 @@ async function createBooking({
},
});
}

const createTeams = async (userFixture: Fixtures["users"]) => {
const owner1 = await userFixture.create({ name: "team-owner-1" });
const owner2 = await userFixture.create({ name: "team-owner-2" });
const commonUser = await userFixture.create({ name: "commonUser" });
const team1_teammate1 = await userFixture.create({ name: "team1_teammate1" });
const team2_teammate1 = await userFixture.create({ name: "team2_teammate1" });
const teamOne = await prisma.team.create({
data: {
name: "bookings-test-team-1",
slug: slugify(`bookings-test-team-2-${randomString(5)}`),
},
});

const teamTwo = await prisma.team.create({
data: {
name: "bookings-test-team-2",
slug: slugify(`bookings-test-team-2-${randomString(5)}`),
},
});

// create memberships
await prisma.membership.createMany({
data: [
{
userId: owner1.id,
teamId: teamOne.id,
accepted: true,
role: "OWNER",
},
{
userId: commonUser.id,
teamId: teamOne.id,
accepted: true,
role: "MEMBER",
},
{
userId: team1_teammate1.id,
teamId: teamOne.id,
accepted: true,
role: "MEMBER",
},
{
userId: owner2.id,
teamId: teamTwo.id,
accepted: true,
role: "OWNER",
},
{
userId: commonUser.id,
teamId: teamTwo.id,
accepted: true,
role: "MEMBER",
},
{
userId: team2_teammate1.id,
teamId: teamTwo.id,
accepted: true,
role: "MEMBER",
},
],
});
return {
owner1,
owner2,
commonUser,
team1_teammate1,
team2_teammate1,
teamOne,
teamTwo,
};
};
2 changes: 1 addition & 1 deletion apps/web/playwright/fixtures/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const createTeamWorkflow = async (user: { id: number }, team: { id: number }) =>
});
};

export const createTeamEventType = async (
const createTeamEventType = async (
user: { id: number },
team: { id: number },
scenario?: {
Expand Down
51 changes: 0 additions & 51 deletions apps/web/playwright/lib/testUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Frame, Page } from "@playwright/test";
import type { APIResponse } from "@playwright/test";
import { expect } from "@playwright/test";
import { createHash } from "crypto";
import EventEmitter from "events";
Expand Down Expand Up @@ -372,53 +371,3 @@ export async function doOnOrgDomain(
// When App directory is there, this is the 404 page text. We should work on fixing the 404 page as it changed due to app directory.
export const NotFoundPageTextAppDir = "This page does not exist.";
// export const NotFoundPageText = "ERROR 404";

export type Team = {
id: number;
slug: string | null;
name: string;
};

export type EventType = {
id: number;
title: string;
slug: string;
};
export type User = {
id: number;
name: string | null;
username: string | null;
};

export async function bookTeamEvent(page: Page, team: Team, eventType: EventType) {
await page.goto(`/team/${team.slug}/${eventType.slug}/`);
await bookEventOnThisPage(page);
const bookingTitle = `${eventType.title} between ${team.name} and ${testName}`;
await assertBookingIsCorrect(page, bookingTitle);
}
export async function bookUserEvent(page: Page, user: User, eventType: EventType) {
await page.goto(`/${user.username}/${eventType.slug}/`);
await bookEventOnThisPage(page);
const bookingTitle = `${eventType.title} between ${user.name} and ${testName}`;
await assertBookingIsCorrect(page, bookingTitle);
}

export async function assertBookingIsCorrect(page: Page, bookingTitle: string) {
await expect(page.locator("[data-testid=booking-title]")).toHaveText(bookingTitle);
// The booker should be in the attendee list
await expect(page.locator(`[data-testid="attendee-name-${testName}"]`)).toHaveText(testName);
}

export const assertBookingVisibleFor = async (
user: { apiLogin: () => Promise<APIResponse> },
pageFixture: Fixtures["page"],
eventType: EventType,
shouldBeVisible: boolean
) => {
await user.apiLogin();
await pageFixture.goto(`/bookings/upcoming`);
const upcomingBookingList = pageFixture.locator('[data-testid="booking-item"]');
shouldBeVisible
? await expect(upcomingBookingList.locator(`text=${eventType.title}`)).toBeVisible()
: await expect(upcomingBookingList.locator(`text=${eventType.title}`)).toBeHidden();
};

0 comments on commit fd193e6

Please sign in to comment.