fix: /bookings get handler (#19369)
* fix: sorting on /bookings * fix type erorr * add filters to logging * fix type error * filter with attendee emails * clean up filters * add test from #19376 * fix e2e tests * split ORs into smaller queries * add missing imports
This commit is contained in:
1 parent
4b2265c35d
commit
2d372746d3
3 files changed
+475
-290
No files matched your search
@@ -1,7 +1,10 @@
|
||||
import { expect } from "@playwright/test";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { BookingStatus } from "@calcom/prisma/client";
|
||||
import { MembershipRole } from "@calcom/prisma/enums";
|
||||
|
||||
import { createTeamEventType } from "./fixtures/users";
|
||||
import type { Fixtures } from "./lib/fixtures";
|
||||
import { test } from "./lib/fixtures";
|
||||
import { setupManagedEvent } from "./lib/testUtils";
|
||||
@@ -207,6 +210,129 @@ test.describe("Bookings", () => {
|
||||
webhookReceiver.close();
|
||||
});
|
||||
});
|
||||
|
||||
test("People filter includes bookings where filtered person is attendee", async ({
|
||||
page,
|
||||
users,
|
||||
bookings,
|
||||
}) => {
|
||||
const firstUser = await users.create(
|
||||
{ name: "First" },
|
||||
{
|
||||
hasTeam: true,
|
||||
teamRole: MembershipRole.ADMIN,
|
||||
}
|
||||
);
|
||||
const teamId = (await firstUser.getFirstTeamMembership()).teamId;
|
||||
const secondUser = await users.create({ name: "Second" });
|
||||
const thirdUser = await users.create({ name: "Third" });
|
||||
// Add teammates to the team
|
||||
await prisma.membership.createMany({
|
||||
data: [
|
||||
{
|
||||
teamId: teamId,
|
||||
userId: secondUser.id,
|
||||
role: MembershipRole.MEMBER,
|
||||
accepted: true,
|
||||
},
|
||||
{
|
||||
teamId: teamId,
|
||||
userId: thirdUser.id,
|
||||
role: MembershipRole.MEMBER,
|
||||
accepted: true,
|
||||
},
|
||||
],
|
||||
});
|
||||
const teamEvent = await createTeamEventType(
|
||||
{ id: firstUser.id },
|
||||
{ id: teamId },
|
||||
{ teamEventSlug: "team-event-slug" }
|
||||
);
|
||||
|
||||
//Create a TeamEventType booking where ThirdUser is attendee
|
||||
const thirdUserAttendeeTeamEventBookingFixture = await createBooking({
|
||||
title: "ThirdUser is Attendee for TeamEvent",
|
||||
bookingsFixture: bookings,
|
||||
relativeDate: 6,
|
||||
organizer: firstUser,
|
||||
organizerEventType: teamEvent,
|
||||
attendees: [{ name: "Third", email: thirdUser.email, timeZone: "Europe/Berlin" }],
|
||||
});
|
||||
const thirdUserAttendeeTeamEvent = await thirdUserAttendeeTeamEventBookingFixture.self();
|
||||
|
||||
//Create a IndividualEventType booking where ThirdUser,SecondUser are attendees and FirstUser is organizer
|
||||
const thirdUserAttendeeIndividualBookingFixture = await createBooking({
|
||||
title: "ThirdUser is Attendee and FirstUser is Organizer",
|
||||
bookingsFixture: bookings,
|
||||
relativeDate: 3,
|
||||
organizer: firstUser,
|
||||
organizerEventType: firstUser.eventTypes[0],
|
||||
attendees: [
|
||||
{ name: "Third", email: thirdUser.email, timeZone: "Europe/Berlin" },
|
||||
{ name: "Second", email: secondUser.email, timeZone: "Europe/Berlin" },
|
||||
],
|
||||
});
|
||||
const thirdUserAttendeeIndividualBooking = await thirdUserAttendeeIndividualBookingFixture.self();
|
||||
|
||||
//Create a IndividualEventType booking where ThirdUser is organizer and FirstUser,SecondUser are attendees
|
||||
const thirdUserOrganizerBookingFixture = await createBooking({
|
||||
title: "ThirdUser is Organizer and FirstUser is Attendee",
|
||||
bookingsFixture: bookings,
|
||||
organizer: thirdUser,
|
||||
relativeDate: 2,
|
||||
organizerEventType: thirdUser.eventTypes[0],
|
||||
attendees: [
|
||||
{ name: "First", email: firstUser.email, timeZone: "Europe/Berlin" },
|
||||
{ name: "Second", email: secondUser.email, timeZone: "Europe/Berlin" },
|
||||
],
|
||||
});
|
||||
const thirdUserOrganizerBooking = await thirdUserOrganizerBookingFixture.self();
|
||||
|
||||
//Create a booking where FirstUser is organizer and SecondUser is attendee
|
||||
await createBooking({
|
||||
title: "FirstUser is Organizer and SecondUser is Attendee",
|
||||
bookingsFixture: bookings,
|
||||
organizer: firstUser,
|
||||
relativeDate: 4,
|
||||
organizerEventType: firstUser.eventTypes[0],
|
||||
attendees: [{ name: "Second", email: secondUser.email, timeZone: "Europe/Berlin" }],
|
||||
});
|
||||
|
||||
//admin login
|
||||
//Select 'ThirdUser' in people filter
|
||||
await firstUser.apiLogin();
|
||||
await Promise.all([
|
||||
page.waitForResponse((response) => /\/api\/trpc\/bookings\/get.*/.test(response.url())),
|
||||
page.waitForResponse((response) => /\/api\/trpc\/bookings\/get.*/.test(response.url())),
|
||||
page.goto(`/bookings/upcoming?status=upcoming&userIds=${thirdUser.id}`),
|
||||
]);
|
||||
|
||||
//expect only 3 bookings (out of 4 total) to be shown in list.
|
||||
//where ThirdUser is either organizer or attendee
|
||||
const upcomingBookingsTable = page.locator('[data-testid="upcoming-bookings"]');
|
||||
const bookingListItems = upcomingBookingsTable.locator('[data-testid="booking-item"]');
|
||||
const bookingListCount = await bookingListItems.count();
|
||||
expect(bookingListCount).toBe(3);
|
||||
|
||||
//verify with the booking titles
|
||||
const firstUpcomingBooking = bookingListItems.nth(0);
|
||||
await expect(
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
firstUpcomingBooking.locator(`text=${thirdUserOrganizerBooking!.title}`)
|
||||
).toBeVisible();
|
||||
|
||||
const secondUpcomingBooking = bookingListItems.nth(1);
|
||||
await expect(
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
secondUpcomingBooking.locator(`text=${thirdUserAttendeeIndividualBooking!.title}`)
|
||||
).toBeVisible();
|
||||
|
||||
const thirdUpcomingBooking = bookingListItems.nth(2);
|
||||
await expect(
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
thirdUpcomingBooking.locator(`text=${thirdUserAttendeeTeamEvent!.title}`)
|
||||
).toBeVisible();
|
||||
});
|
||||
});
|
||||
|
||||
async function createBooking({
|
||||
|
||||
@@ -86,7 +86,7 @@ const createTeamWorkflow = async (user: { id: number }, team: { id: number }) =>
|
||||
});
|
||||
};
|
||||
|
||||
const createTeamEventType = async (
|
||||
export const createTeamEventType = async (
|
||||
user: { id: number },
|
||||
team: { id: number },
|
||||
scenario?: {
|
||||
|
||||
Reference in new issue
Block a user