|
| 1 | +import { expect } from "@playwright/test"; |
| 2 | + |
| 3 | +import { BookingStatus } from "@calcom/prisma/client"; |
| 4 | + |
| 5 | +import type { Fixtures } from "./lib/fixtures"; |
| 6 | +import { test } from "./lib/fixtures"; |
| 7 | + |
| 8 | +test.afterEach(({ users }) => users.deleteAll()); |
| 9 | + |
| 10 | +test.describe("Bookings", () => { |
| 11 | + test.describe("Upcoming bookings", () => { |
| 12 | + test("show attendee bookings and organizer bookings in asc order by startDate", async ({ |
| 13 | + page, |
| 14 | + users, |
| 15 | + bookings, |
| 16 | + }) => { |
| 17 | + const firstUser = await users.create(); |
| 18 | + const secondUser = await users.create(); |
| 19 | + |
| 20 | + const bookingWhereFirstUserIsOrganizerFixture = await createBooking({ |
| 21 | + title: "Booking as organizer", |
| 22 | + bookingsFixture: bookings, |
| 23 | + // Create a booking 3 days from today |
| 24 | + relativeDate: 3, |
| 25 | + organizer: firstUser, |
| 26 | + organizerEventType: firstUser.eventTypes[0], |
| 27 | + attendees: [ |
| 28 | + { name: "First", email: "first@cal.com", timeZone: "Europe/Berlin" }, |
| 29 | + { name: "Second", email: "second@cal.com", timeZone: "Europe/Berlin" }, |
| 30 | + { name: "Third", email: "third@cal.com", timeZone: "Europe/Berlin" }, |
| 31 | + ], |
| 32 | + }); |
| 33 | + const bookingWhereFirstUserIsOrganizer = await bookingWhereFirstUserIsOrganizerFixture.self(); |
| 34 | + |
| 35 | + const bookingWhereFirstUserIsAttendeeFixture = await createBooking({ |
| 36 | + title: "Booking as attendee", |
| 37 | + bookingsFixture: bookings, |
| 38 | + organizer: secondUser, |
| 39 | + // Booking created 2 days from today |
| 40 | + relativeDate: 2, |
| 41 | + organizerEventType: secondUser.eventTypes[0], |
| 42 | + attendees: [ |
| 43 | + { name: "OrganizerAsBooker", email: firstUser.email, timeZone: "Europe/Berlin" }, |
| 44 | + { name: "Second", email: "second@cal.com", timeZone: "Europe/Berlin" }, |
| 45 | + { name: "Third", email: "third@cal.com", timeZone: "Europe/Berlin" }, |
| 46 | + ], |
| 47 | + }); |
| 48 | + const bookingWhereFirstUserIsAttendee = await bookingWhereFirstUserIsAttendeeFixture.self(); |
| 49 | + |
| 50 | + await firstUser.apiLogin(); |
| 51 | + await page.goto(`/bookings/upcoming`); |
| 52 | + const upcomingBookings = page.locator('[data-testid="upcoming-bookings"]'); |
| 53 | + const firstUpcomingBooking = upcomingBookings.locator('[data-testid="booking-item"]').nth(0); |
| 54 | + const secondUpcomingBooking = upcomingBookings.locator('[data-testid="booking-item"]').nth(1); |
| 55 | + await expect( |
| 56 | + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion |
| 57 | + firstUpcomingBooking.locator(`text=${bookingWhereFirstUserIsAttendee!.title}`) |
| 58 | + ).toBeVisible(); |
| 59 | + await expect( |
| 60 | + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion |
| 61 | + secondUpcomingBooking.locator(`text=${bookingWhereFirstUserIsOrganizer!.title}`) |
| 62 | + ).toBeVisible(); |
| 63 | + }); |
| 64 | + }); |
| 65 | +}); |
| 66 | + |
| 67 | +async function createBooking({ |
| 68 | + bookingsFixture, |
| 69 | + organizer, |
| 70 | + organizerEventType, |
| 71 | + attendees, |
| 72 | + /** |
| 73 | + * Relative date from today |
| 74 | + * 0 means today |
| 75 | + * 1 means tomorrow |
| 76 | + */ |
| 77 | + relativeDate = 0, |
| 78 | + durationMins = 30, |
| 79 | + title, |
| 80 | +}: { |
| 81 | + bookingsFixture: Fixtures["bookings"]; |
| 82 | + organizer: { |
| 83 | + id: number; |
| 84 | + username: string | null; |
| 85 | + }; |
| 86 | + organizerEventType: { |
| 87 | + id: number; |
| 88 | + }; |
| 89 | + attendees: { |
| 90 | + name: string; |
| 91 | + email: string; |
| 92 | + timeZone: string; |
| 93 | + }[]; |
| 94 | + relativeDate?: number; |
| 95 | + durationMins?: number; |
| 96 | + title: string; |
| 97 | +}) { |
| 98 | + const DAY_MS = 24 * 60 * 60 * 1000; |
| 99 | + const bookingDurationMs = durationMins * 60 * 1000; |
| 100 | + const startTime = new Date(Date.now() + relativeDate * DAY_MS); |
| 101 | + const endTime = new Date(Date.now() + relativeDate * DAY_MS + bookingDurationMs); |
| 102 | + return await bookingsFixture.create(organizer.id, organizer.username, organizerEventType.id, { |
| 103 | + title, |
| 104 | + status: BookingStatus.ACCEPTED, |
| 105 | + startTime, |
| 106 | + endTime, |
| 107 | + attendees: { |
| 108 | + createMany: { |
| 109 | + data: [...attendees], |
| 110 | + }, |
| 111 | + }, |
| 112 | + }); |
| 113 | +} |
0 commit comments