2023-03-14 04:19:05 +00:00
import { expect } from "@playwright/test" ;
import type { Prisma } from "@prisma/client" ;
2023-06-10 03:47:50 +00:00
import { uuid } from "short-uuid" ;
2023-03-14 04:19:05 +00:00
import { v4 as uuidv4 } from "uuid" ;
import prisma from "@calcom/prisma" ;
2023-05-02 11:44:05 +00:00
import { BookingStatus } from "@calcom/prisma/enums" ;
2023-03-14 04:19:05 +00:00
import type { Fixtures } from "./lib/fixtures" ;
import { test } from "./lib/fixtures" ;
import {
bookTimeSlot ,
createNewSeatedEventType ,
selectFirstAvailableTimeSlotNextMonth ,
} from "./lib/testUtils" ;
2023-06-06 18:02:32 +00:00
test . describe . configure ( { mode : "parallel" } ) ;
2023-03-14 04:19:05 +00:00
test . afterEach ( ( { users } ) = > users . deleteAll ( ) ) ;
async function createUserWithSeatedEvent ( users : Fixtures [ "users" ] ) {
const slug = "seats" ;
const user = await users . create ( {
eventTypes : [
2023-06-10 03:47:50 +00:00
{
title : "Seated event" ,
slug ,
seatsPerTimeSlot : 10 ,
requiresConfirmation : true ,
length : 30 ,
disableGuests : true , // should always be true for seated events
} ,
2023-03-14 04:19:05 +00:00
] ,
} ) ;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const eventType = user . eventTypes . find ( ( e ) = > e . slug === slug ) ! ;
return { user , eventType } ;
}
async function createUserWithSeatedEventAndAttendees (
fixtures : Pick < Fixtures , " users " | " bookings " > ,
attendees : Prisma.AttendeeCreateManyBookingInput [ ]
) {
const { user , eventType } = await createUserWithSeatedEvent ( fixtures . users ) ;
const booking = await fixtures . bookings . create ( user . id , user . username , eventType . id , {
status : BookingStatus.ACCEPTED ,
// startTime with 1 day from now and endTime half hour after
startTime : new Date ( Date . now ( ) + 24 * 60 * 60 * 1000 ) ,
endTime : new Date ( Date . now ( ) + 24 * 60 * 60 * 1000 + 30 * 60 * 1000 ) ,
attendees : {
createMany : {
data : attendees ,
} ,
} ,
} ) ;
return { user , eventType , booking } ;
}
2023-07-11 11:31:55 +00:00
test . describe ( "Booking with Seats" , ( ) = > {
2023-03-14 04:19:05 +00:00
test ( "User can create a seated event (2 seats as example)" , async ( { users , page } ) = > {
const user = await users . create ( { name : "Seated event" } ) ;
2023-06-06 18:02:32 +00:00
await user . apiLogin ( ) ;
await page . goto ( "/event-types" ) ;
// We wait until loading is finished
await page . waitForSelector ( '[data-testid="event-types"]' ) ;
2023-03-14 04:19:05 +00:00
const eventTitle = "My 2-seated event" ;
await createNewSeatedEventType ( page , { eventTitle } ) ;
await expect ( page . locator ( ` text= ${ eventTitle } event type updated successfully ` ) ) . toBeVisible ( ) ;
} ) ;
2023-06-06 18:02:32 +00:00
2023-03-14 04:19:05 +00:00
test ( "Multiple Attendees can book a seated event time slot" , async ( { users , page } ) = > {
const slug = "my-2-seated-event" ;
const user = await users . create ( {
name : "Seated event user" ,
eventTypes : [
2023-06-06 18:02:32 +00:00
{
title : "My 2-seated event" ,
slug ,
length : 60 ,
seatsPerTimeSlot : 2 ,
seatsShowAttendees : true ,
} ,
2023-03-14 04:19:05 +00:00
] ,
} ) ;
await page . goto ( ` / ${ user . username } / ${ slug } ` ) ;
await selectFirstAvailableTimeSlotNextMonth ( page ) ;
New Booker Component (preparations for booker atom) (#6792)
* Wip on booker atom
* Wip on booker atom
* Added correct icon imports
* Fixed build
* Responsive improvements
* Removed package lock
* Responsive tweaks
* Animation improvements and cleanup
* Animation improvements and event meta layout improvements.
* Tweaked margins.
* Added more event meta blocks
* Layout tweaks
* Converted booker layout to css grid and implemented multiple layout options
* cleanup
* Fixed build
* Fixed build
* Added temporary api route to enable/disable new booker
* Added sticky behavior
* Reverted yarn.lock and reinstalled new packages to see if this fixes build on vercel.
* Ensure divider lines always have 100% height.
* Improved animation config + initial load
* Ensure to pass eventid to getschedule, otherwise custom availability schedule wont work and wont return any availability
* Fixed divider line heights in booker
* Fixed timezone select positioning
* Added ability to view multiple days of timeslots
* Added icons to booker toggle
* Always show timeslots in timeslots view, also if no date is selected yet. In that case we show upcoming 5 days.
* Fixed timeslots in small calendar view
* Show selected day in calendar
* Fixed booker timeslots view
* Wip in making booking form work
* Moved most of the booker atom stuff to features, since it belongs there. Atom should be a rather small wrapper.
* Added create event functionality to booker form.
* Added guests toggle to booker form and styled input addons in dark mode.
* Added dynamic weekstart to booker
* Added seats limit feature to timeslots.
* Removed todo
* Added correct event avatars
* Added correct event name and icons
* Added correct translation for minutes text in multi duration
* Add rescheduling functionality to new booker.
* Added selected booking time to booking meta in sidebar.
* Abstracted away timeformat to custom hook
* Added correct key props to all components in booker.
* Fix build
* Create some new custom hooks to have a lot less repitition in code.
* Moved bookerform component inside booker directory since it is tied to it.
* Added error messages to booker form, plus fixed bug in recurring events.
* Added some comments <3
* Fixed todos in booker form.
* Added loading state for timeslot selector, and added prefetching of next month, in case of multi day view showing 2 months at the same time.
* Fixed import paths
* Added away view
* Validate uniqueness of event attendees.
* Tweaked comment
* #5798 added correct date format and style for selected date in booker.
* UI improvements
* Enable possibility to add booking values via query params.
* Added functionality to update query params when user selects date/duration etc in booker
* First steps in adding e2e test.
* Fixes after merge with main, and added new form builder.
* Implemented new form types and validation to booker, confirming new form builder. Validation still throwing wrong error keys though.
* Added search to timezone dropdown
* Added e2e test for booker (copy of current booker tests, only enabling cookie), plus fixed reschedule view.
* Updated yarn.lock
* Added new booker for team pages.
* Fixed input addon (hover) styles.
* Added dynamic booking.
* Hide timeformat select for multi day view for now.
* Cleanup and ui tweaks
* removed log
* Mobile improvements
* Cleanup
* Small design tweaks after talking to ciaran.
* Text color and weight tweaks in booker
* Added rainbow gates to new booker.
* Added in default values which fixes form vallidation (???).
* Added empty defaults for name and email
* Added metadata
* Reset yarn.lock
* Fixed booker zod validation after change in main.
* Icon tweak
* Fixed timezone select styles after new classnames have been merged.
* Updated seat availability styles.
* Update yarn.lock
* Added explanation for alchemy key to .env.example
* Added tooltip to booker month/week/multiday toggle
* Fixed timezoneselect styles in booker after select updates.
* Updates bookingfields component by taking changes from current booker component
* Removed remaining booker todos
* Fix bookeventform
* Fix for recurring event meta
* Type fixes
* Typefixes
* Team event fixes
* Avoid hydration errors by only rendering date picker client side. Remove web3 gates since we dont offer them anymore. Prevent timeslot select from staying open when switching to a different month.
* Don't show calendar on mobile booker during booking.
* Always align booker buttons to bottom
* Don't show backend messages in error, rather show a helpful text like the current booker does as well.
* Do invisible next rewrite based on cookie from next.config.js (#7949)
* Do invisible next rewrite based on cookie from next.config.js
* Name embed link instead of bookerPath
* Rewrites only dynamic user pages
---------
Co-authored-by: zomars <zomars@me.com>
* Don't allow change of timezone when bookerform is visible
* Don't add duration to query param if the event is not a multi duration event.
* Update next.config.js
* Added correct timezone formatting to event meta when timeslot is selected.
* removed .env variable that isn't needed anymore.
* Update Gates.tsx
* Type fixes
* Allows to run all tests with the new booker
* Fixed timezone select styles after merge.
* Don't throw error when event doesn't have hosts, rather return no users, which will result in no availability in UI.
* Make booker errors of severity info instead of warning.
* Ensure team avatars are shown, as well as filter on uniqueness of avatars.
* Added all booked today message to timeslots.
* Added cal.com logo to booker.
* Fixed fragment classname error, minor mobile animation tweaks plus make all booked today text smaller for multi day layout.
* Improved timezone select styles, and updated arguments of getbooking function after updates in main.
* Prevent infinite loop in rewriting new booker.
* Prevent infinite loop in rewriting new booker.
* Moved new-booker pages to their own directory to prevent regexes confusing next and thus nut running getserversideprops after rewrite. Also adding clearing of old date in booker store, that could stick around when user immediately navigates back to the same page after booking.
* Fixed cal logo color in darkmode for new booker.
* Implemented new color tokens and theme variables. Also small design tweaks after merge with main.
* Minor style tweaks
* Show multiple locations in tooltip on booker #8222
* Radio button style tweaks
* Fixed build
* Updated calendar imports to new lucide names
* Removed resetting of selected times logic, because otherwise url params wouldnt be taken into account which is actually what we want. So old values sticking around when navigating back is actually the desired behavior.
* Updated tests to instead of always run the new booker in tests, have a utility to run both the new and old booker for specified tests.
* Added comment and eslint disable for if statement in booker test.
* Update packages/features/bookings/components/event-meta/Details.tsx
Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
* Fix badge types
* Lazy loaded timezone select to save 85kb in bundle size.
* Upgraded framer to latest. Als moved framer and react sticky deps to features instead of atoms.
* Added new pagewrapper logic
* Simplified rescheduling ssr fetches, this now also supports multi seat rescheduling.
* Unset selected time when user is rescheduling directly after a new booking, otherwise it would show the form instead of new time selection.
* Updated form builder logic as per form builder in current booker.
* Updated form builder prefill logic as per logic in current booker.
* Updated getbooking function to fetch correct details when a reschedule uid is used
* Fixed booking questions test by NOT waiting for /book page because the new booker doesnt have this.
* Added former meeting time to reschedule view.
* Fixed types
* Undo playwright config update by mistake.
* Fixed event types test by only waiting for /book page in old booker
* Set new booker cookie to one year in the future instead of 2050
* added reset mockdate to test
* Temporary disabled test to see if this solves the out of memory error.
* Deleted test to see if that fixes the memory error
* Select first day when switching months in booker
---------
Co-authored-by: zomars <zomars@me.com>
Co-authored-by: Alex van Andel <me@alexvanandel.com>
Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
Co-authored-by: Sean Brydon <sean@cal.com>
Co-authored-by: Peer Richelsen <peeroke@gmail.com>
2023-04-24 14:32:30 +00:00
2023-03-14 04:19:05 +00:00
const bookingUrl = page . url ( ) ;
await test . step ( "Attendee #1 can book a seated event time slot" , async ( ) = > {
await page . goto ( bookingUrl ) ;
await bookTimeSlot ( page ) ;
await expect ( page . locator ( "[data-testid=success-page]" ) ) . toBeVisible ( ) ;
} ) ;
await test . step ( "Attendee #2 can book the same seated event time slot" , async ( ) = > {
await page . goto ( bookingUrl ) ;
await bookTimeSlot ( page , { email : "jane.doe@example.com" , name : "Jane Doe" } ) ;
await expect ( page . locator ( "[data-testid=success-page]" ) ) . toBeVisible ( ) ;
} ) ;
await test . step ( "Attendee #3 cannot book the same seated event time slot" , async ( ) = > {
await page . goto ( bookingUrl ) ;
await bookTimeSlot ( page , { email : "rick@example.com" , name : "Rick" } ) ;
await expect ( page . locator ( "[data-testid=success-page]" ) ) . toBeHidden ( ) ;
} ) ;
} ) ;
2023-06-06 18:02:32 +00:00
2023-06-10 03:47:50 +00:00
test ( ` Attendees can cancel a seated event time slot ` , async ( { page , users , bookings } ) = > {
const { booking } = await createUserWithSeatedEventAndAttendees ( { users , bookings } , [
{ name : "John First" , email : "first+seats@cal.com" , timeZone : "Europe/Berlin" } ,
{ name : "Jane Second" , email : "second+seats@cal.com" , timeZone : "Europe/Berlin" } ,
{ name : "John Third" , email : "third+seats@cal.com" , timeZone : "Europe/Berlin" } ,
] ) ;
const bookingAttendees = await prisma . attendee . findMany ( {
where : { bookingId : booking.id } ,
select : {
id : true ,
} ,
} ) ;
const bookingSeats = [
{ bookingId : booking.id , attendeeId : bookingAttendees [ 0 ] . id , referenceUid : uuidv4 ( ) } ,
{ bookingId : booking.id , attendeeId : bookingAttendees [ 1 ] . id , referenceUid : uuidv4 ( ) } ,
{ bookingId : booking.id , attendeeId : bookingAttendees [ 2 ] . id , referenceUid : uuidv4 ( ) } ,
] ;
await prisma . bookingSeat . createMany ( {
data : bookingSeats ,
} ) ;
await test . step ( "Attendee #1 should be able to cancel their booking" , async ( ) = > {
await page . goto ( ` /booking/ ${ booking . uid } ?seatReferenceUid= ${ bookingSeats [ 0 ] . referenceUid } ` ) ;
await page . locator ( '[data-testid="cancel"]' ) . click ( ) ;
await page . fill ( '[data-testid="cancel_reason"]' , "Double booked!" ) ;
await page . locator ( '[data-testid="confirm_cancel"]' ) . click ( ) ;
await page . waitForLoadState ( "networkidle" ) ;
await expect ( page ) . toHaveURL ( /.*booking/ ) ;
const cancelledHeadline = page . locator ( '[data-testid="cancelled-headline"]' ) ;
await expect ( cancelledHeadline ) . toBeVisible ( ) ;
// Old booking should still exist, with one less attendee
const updatedBooking = await prisma . booking . findFirst ( {
where : { id : bookingSeats [ 0 ] . bookingId } ,
include : { attendees : true } ,
} ) ;
const attendeeIds = updatedBooking ? . attendees . map ( ( { id } ) = > id ) ;
expect ( attendeeIds ) . toHaveLength ( 2 ) ;
expect ( attendeeIds ) . not . toContain ( bookingAttendees [ 0 ] . id ) ;
} ) ;
await test . step ( "All attendees cancelling should delete the booking for the user" , async ( ) = > {
// The remaining 2 attendees cancel
for ( let i = 1 ; i < bookingSeats . length ; i ++ ) {
await page . goto ( ` /booking/ ${ booking . uid } ?seatReferenceUid= ${ bookingSeats [ i ] . referenceUid } ` ) ;
await page . locator ( '[data-testid="cancel"]' ) . click ( ) ;
await page . fill ( '[data-testid="cancel_reason"]' , "Double booked!" ) ;
await page . locator ( '[data-testid="confirm_cancel"]' ) . click ( ) ;
await page . waitForLoadState ( "networkidle" ) ;
await expect ( page ) . toHaveURL ( /.*booking/ ) ;
const cancelledHeadline = page . locator ( '[data-testid="cancelled-headline"]' ) ;
await expect ( cancelledHeadline ) . toBeVisible ( ) ;
}
// Should expect old booking to be cancelled
const updatedBooking = await prisma . booking . findFirst ( {
where : { id : bookingSeats [ 0 ] . bookingId } ,
} ) ;
expect ( updatedBooking ) . not . toBeNull ( ) ;
expect ( updatedBooking ? . status ) . toBe ( BookingStatus . CANCELLED ) ;
} ) ;
} ) ;
2023-05-30 13:52:07 +00:00
} ) ;
2023-03-14 04:19:05 +00:00
2023-07-11 11:31:55 +00:00
test . describe ( "Reschedule for booking with seats" , ( ) = > {
2023-05-30 13:52:07 +00:00
test ( "Should reschedule booking with seats" , async ( { page , users , bookings } ) = > {
const { booking } = await createUserWithSeatedEventAndAttendees ( { users , bookings } , [
2023-06-10 03:47:50 +00:00
{ name : "John First" , email : ` first+seats- ${ uuid ( ) } @cal.com ` , timeZone : "Europe/Berlin" } ,
{ name : "Jane Second" , email : ` second+seats- ${ uuid ( ) } @cal.com ` , timeZone : "Europe/Berlin" } ,
{ name : "John Third" , email : ` third+seats- ${ uuid ( ) } @cal.com ` , timeZone : "Europe/Berlin" } ,
2023-05-30 13:52:07 +00:00
] ) ;
const bookingAttendees = await prisma . attendee . findMany ( {
where : { bookingId : booking.id } ,
select : {
id : true ,
2023-06-10 03:47:50 +00:00
email : true ,
2023-05-30 13:52:07 +00:00
} ,
} ) ;
2023-03-14 04:19:05 +00:00
2023-05-30 13:52:07 +00:00
const bookingSeats = [
{ bookingId : booking.id , attendeeId : bookingAttendees [ 0 ] . id , referenceUid : uuidv4 ( ) } ,
{ bookingId : booking.id , attendeeId : bookingAttendees [ 1 ] . id , referenceUid : uuidv4 ( ) } ,
{ bookingId : booking.id , attendeeId : bookingAttendees [ 2 ] . id , referenceUid : uuidv4 ( ) } ,
] ;
2023-03-14 04:19:05 +00:00
2023-05-30 13:52:07 +00:00
await prisma . bookingSeat . createMany ( {
data : bookingSeats ,
} ) ;
2023-03-14 04:19:05 +00:00
2023-05-30 13:52:07 +00:00
const references = await prisma . bookingSeat . findMany ( {
where : { bookingId : booking.id } ,
} ) ;
2023-03-14 04:19:05 +00:00
2023-05-30 13:52:07 +00:00
await page . goto ( ` /reschedule/ ${ references [ 2 ] . referenceUid } ` ) ;
2023-03-14 04:19:05 +00:00
2023-05-30 13:52:07 +00:00
await selectFirstAvailableTimeSlotNextMonth ( page ) ;
2023-03-14 04:19:05 +00:00
2023-05-30 13:52:07 +00:00
// expect input to be filled with attendee number 3 data
const thirdAttendeeElement = await page . locator ( "input[name=name]" ) ;
const attendeeName = await thirdAttendeeElement . inputValue ( ) ;
expect ( attendeeName ) . toBe ( "John Third" ) ;
2023-03-14 04:19:05 +00:00
2023-05-30 13:52:07 +00:00
await page . locator ( '[data-testid="confirm-reschedule-button"]' ) . click ( ) ;
2023-03-14 04:19:05 +00:00
2023-05-30 13:52:07 +00:00
await page . waitForLoadState ( "networkidle" ) ;
2023-03-14 04:19:05 +00:00
2023-05-30 13:52:07 +00:00
await expect ( page ) . toHaveURL ( /.*booking/ ) ;
2023-03-14 04:19:05 +00:00
2023-06-10 03:47:50 +00:00
// Should expect new booking to be created for John Third
const newBooking = await prisma . booking . findFirst ( {
where : {
attendees : {
some : { email : bookingAttendees [ 2 ] . email } ,
} ,
} ,
include : { seatsReferences : true , attendees : true } ,
} ) ;
expect ( newBooking ? . status ) . toBe ( BookingStatus . PENDING ) ;
expect ( newBooking ? . attendees . length ) . toBe ( 1 ) ;
expect ( newBooking ? . attendees [ 0 ] . name ) . toBe ( "John Third" ) ;
expect ( newBooking ? . seatsReferences . length ) . toBe ( 1 ) ;
2023-05-30 13:52:07 +00:00
// Should expect old booking to be accepted with two attendees
const oldBooking = await prisma . booking . findFirst ( {
where : { uid : booking.uid } ,
include : { seatsReferences : true , attendees : true } ,
} ) ;
2023-03-14 04:19:05 +00:00
2023-05-30 13:52:07 +00:00
expect ( oldBooking ? . status ) . toBe ( BookingStatus . ACCEPTED ) ;
expect ( oldBooking ? . attendees . length ) . toBe ( 2 ) ;
expect ( oldBooking ? . seatsReferences . length ) . toBe ( 2 ) ;
} ) ;
test ( "Should reschedule booking with seats and if everyone rescheduled it should be deleted" , async ( {
page ,
users ,
bookings ,
} ) = > {
const { booking } = await createUserWithSeatedEventAndAttendees ( { users , bookings } , [
{ name : "John First" , email : "first+seats@cal.com" , timeZone : "Europe/Berlin" } ,
{ name : "Jane Second" , email : "second+seats@cal.com" , timeZone : "Europe/Berlin" } ,
] ) ;
const bookingAttendees = await prisma . attendee . findMany ( {
where : { bookingId : booking.id } ,
select : {
id : true ,
} ,
2023-03-14 04:19:05 +00:00
} ) ;
2023-05-30 13:52:07 +00:00
const bookingSeats = [
{ bookingId : booking.id , attendeeId : bookingAttendees [ 0 ] . id , referenceUid : uuidv4 ( ) } ,
{ bookingId : booking.id , attendeeId : bookingAttendees [ 1 ] . id , referenceUid : uuidv4 ( ) } ,
] ;
2023-05-30 03:12:07 +00:00
2023-05-30 13:52:07 +00:00
await prisma . bookingSeat . createMany ( {
data : bookingSeats ,
} ) ;
2023-03-14 04:19:05 +00:00
2023-05-30 13:52:07 +00:00
const references = await prisma . bookingSeat . findMany ( {
where : { bookingId : booking.id } ,
} ) ;
2023-03-14 04:19:05 +00:00
2023-05-30 13:52:07 +00:00
await page . goto ( ` /reschedule/ ${ references [ 0 ] . referenceUid } ` ) ;
2023-03-14 04:19:05 +00:00
2023-05-30 13:52:07 +00:00
await selectFirstAvailableTimeSlotNextMonth ( page ) ;
2023-03-14 04:19:05 +00:00
2023-05-30 13:52:07 +00:00
await page . locator ( '[data-testid="confirm-reschedule-button"]' ) . click ( ) ;
2023-03-14 04:19:05 +00:00
2023-05-30 13:52:07 +00:00
await page . waitForURL ( /.*booking/ ) ;
2023-03-14 04:19:05 +00:00
2023-05-30 13:52:07 +00:00
await page . goto ( ` /reschedule/ ${ references [ 1 ] . referenceUid } ` ) ;
2023-03-14 04:19:05 +00:00
2023-05-30 13:52:07 +00:00
await selectFirstAvailableTimeSlotNextMonth ( page ) ;
2023-03-14 04:19:05 +00:00
2023-05-30 13:52:07 +00:00
await page . locator ( '[data-testid="confirm-reschedule-button"]' ) . click ( ) ;
2023-03-14 04:19:05 +00:00
2023-05-30 13:52:07 +00:00
// Using waitForUrl here fails the assertion `expect(oldBooking?.status).toBe(BookingStatus.CANCELLED);` probably because waitForUrl is considered complete before waitForNavigation and till that time the booking is not cancelled
await page . waitForNavigation ( { url : /.*booking/ } ) ;
2023-03-14 04:19:05 +00:00
2023-05-30 13:52:07 +00:00
// Should expect old booking to be cancelled
const oldBooking = await prisma . booking . findFirst ( {
where : { uid : booking.uid } ,
include : {
seatsReferences : true ,
attendees : true ,
eventType : {
include : { users : true , hosts : true } ,
} ,
} ,
} ) ;
2023-03-14 04:19:05 +00:00
2023-05-30 13:52:07 +00:00
expect ( oldBooking ? . status ) . toBe ( BookingStatus . CANCELLED ) ;
} ) ;
2023-03-14 04:19:05 +00:00
2023-05-30 13:52:07 +00:00
test ( "Should cancel with seats and have no attendees and cancelled" , async ( { page , users , bookings } ) = > {
const { user , booking } = await createUserWithSeatedEventAndAttendees ( { users , bookings } , [
{ name : "John First" , email : "first+seats@cal.com" , timeZone : "Europe/Berlin" } ,
{ name : "Jane Second" , email : "second+seats@cal.com" , timeZone : "Europe/Berlin" } ,
] ) ;
2023-06-06 18:02:32 +00:00
await user . apiLogin ( ) ;
2023-03-14 04:19:05 +00:00
2023-05-30 13:52:07 +00:00
const oldBooking = await prisma . booking . findFirst ( {
where : { uid : booking.uid } ,
include : { seatsReferences : true , attendees : true } ,
} ) ;
2023-03-14 04:19:05 +00:00
2023-05-30 13:52:07 +00:00
const bookingAttendees = await prisma . attendee . findMany ( {
where : { bookingId : booking.id } ,
select : {
id : true ,
} ,
} ) ;
2023-03-14 04:19:05 +00:00
2023-05-30 13:52:07 +00:00
const bookingSeats = [
{ bookingId : booking.id , attendeeId : bookingAttendees [ 0 ] . id , referenceUid : uuidv4 ( ) } ,
{ bookingId : booking.id , attendeeId : bookingAttendees [ 1 ] . id , referenceUid : uuidv4 ( ) } ,
] ;
2023-03-14 04:19:05 +00:00
2023-05-30 13:52:07 +00:00
await prisma . bookingSeat . createMany ( {
data : bookingSeats ,
} ) ;
2023-03-14 04:19:05 +00:00
2023-05-30 13:52:07 +00:00
// Now we cancel the booking as the organizer
await page . goto ( ` /booking/ ${ booking . uid } ?cancel=true ` ) ;
2023-03-14 04:19:05 +00:00
2023-06-10 03:47:50 +00:00
await page . locator ( '[data-testid="confirm_cancel"]' ) . click ( ) ;
2023-03-14 04:19:05 +00:00
2023-05-30 13:52:07 +00:00
await page . waitForLoadState ( "networkidle" ) ;
2023-03-14 04:19:05 +00:00
2023-05-30 13:52:07 +00:00
await expect ( page ) . toHaveURL ( /.*booking/ ) ;
2023-03-14 04:19:05 +00:00
2023-05-30 13:52:07 +00:00
// Should expect old booking to be cancelled
const updatedBooking = await prisma . booking . findFirst ( {
where : { uid : booking.uid } ,
include : { seatsReferences : true , attendees : true } ,
} ) ;
2023-03-14 04:19:05 +00:00
2023-05-30 13:52:07 +00:00
expect ( oldBooking ? . startTime ) . not . toBe ( updatedBooking ? . startTime ) ;
} ) ;
2023-03-14 04:19:05 +00:00
2023-05-30 13:52:07 +00:00
test ( "If rescheduled/cancelled booking with seats it should display the correct number of seats" , async ( {
page ,
users ,
bookings ,
} ) = > {
const { booking } = await createUserWithSeatedEventAndAttendees ( { users , bookings } , [
{ name : "John First" , email : "first+seats@cal.com" , timeZone : "Europe/Berlin" } ,
{ name : "Jane Second" , email : "second+seats@cal.com" , timeZone : "Europe/Berlin" } ,
] ) ;
const bookingAttendees = await prisma . attendee . findMany ( {
where : { bookingId : booking.id } ,
select : {
id : true ,
} ,
2023-03-14 04:19:05 +00:00
} ) ;
2023-05-30 13:52:07 +00:00
const bookingSeats = [
{ bookingId : booking.id , attendeeId : bookingAttendees [ 0 ] . id , referenceUid : uuidv4 ( ) } ,
{ bookingId : booking.id , attendeeId : bookingAttendees [ 1 ] . id , referenceUid : uuidv4 ( ) } ,
] ;
2023-03-14 04:19:05 +00:00
2023-05-30 13:52:07 +00:00
await prisma . bookingSeat . createMany ( {
data : bookingSeats ,
} ) ;
2023-03-14 04:19:05 +00:00
2023-05-30 13:52:07 +00:00
const references = await prisma . bookingSeat . findMany ( {
where : { bookingId : booking.id } ,
} ) ;
2023-03-14 04:19:05 +00:00
2023-05-30 13:52:07 +00:00
await page . goto (
` /booking/ ${ references [ 0 ] . referenceUid } ?cancel=true&seatReferenceUid= ${ references [ 0 ] . referenceUid } `
) ;
2023-03-14 04:19:05 +00:00
2023-06-10 03:47:50 +00:00
await page . locator ( '[data-testid="confirm_cancel"]' ) . click ( ) ;
2023-03-14 04:19:05 +00:00
2023-05-30 13:52:07 +00:00
const oldBooking = await prisma . booking . findFirst ( {
where : { uid : booking.uid } ,
select : {
id : true ,
status : true ,
} ,
} ) ;
2023-03-14 04:19:05 +00:00
2023-05-30 13:52:07 +00:00
expect ( oldBooking ? . status ) . toBe ( BookingStatus . ACCEPTED ) ;
2023-03-14 04:19:05 +00:00
2023-05-30 13:52:07 +00:00
await page . goto ( ` /reschedule/ ${ references [ 1 ] . referenceUid } ` ) ;
2023-03-14 04:19:05 +00:00
2023-05-30 13:52:07 +00:00
await page . click ( '[data-testid="incrementMonth"]' ) ;
2023-03-14 04:19:05 +00:00
2023-05-30 13:52:07 +00:00
await page . locator ( '[data-testid="day"][data-disabled="false"]' ) . nth ( 1 ) . click ( ) ;
2023-03-14 04:19:05 +00:00
2023-05-30 13:52:07 +00:00
// Validate that the number of seats its 10
expect ( await page . locator ( "text=9 / 10 Seats available" ) . count ( ) ) . toEqual ( 0 ) ;
} ) ;
test ( "Should cancel with seats but event should be still accesible and with one less attendee/seat" , async ( {
page ,
users ,
bookings ,
} ) = > {
const { user , booking } = await createUserWithSeatedEventAndAttendees ( { users , bookings } , [
{ name : "John First" , email : "first+seats@cal.com" , timeZone : "Europe/Berlin" } ,
{ name : "Jane Second" , email : "second+seats@cal.com" , timeZone : "Europe/Berlin" } ,
] ) ;
2023-06-06 18:02:32 +00:00
await user . apiLogin ( ) ;
2023-03-14 04:19:05 +00:00
2023-05-30 13:52:07 +00:00
const bookingAttendees = await prisma . attendee . findMany ( {
where : { bookingId : booking.id } ,
select : {
id : true ,
} ,
2023-03-14 04:19:05 +00:00
} ) ;
2023-04-21 13:49:53 +00:00
2023-05-30 13:52:07 +00:00
const bookingSeats = [
{ bookingId : booking.id , attendeeId : bookingAttendees [ 0 ] . id , referenceUid : uuidv4 ( ) } ,
{ bookingId : booking.id , attendeeId : bookingAttendees [ 1 ] . id , referenceUid : uuidv4 ( ) } ,
] ;
2023-04-21 13:49:53 +00:00
2023-05-30 13:52:07 +00:00
await prisma . bookingSeat . createMany ( {
data : bookingSeats ,
} ) ;
2023-04-21 13:49:53 +00:00
2023-05-30 13:52:07 +00:00
// Now we cancel the booking as the first attendee
// booking/${bookingUid}?cancel=true&allRemainingBookings=false&seatReferenceUid={bookingSeat.referenceUid}
await page . goto (
` /booking/ ${ booking . uid } ?cancel=true&allRemainingBookings=false&seatReferenceUid= ${ bookingSeats [ 0 ] . referenceUid } `
) ;
2023-04-21 13:49:53 +00:00
2023-06-10 03:47:50 +00:00
await page . locator ( '[data-testid="confirm_cancel"]' ) . click ( ) ;
2023-04-21 13:49:53 +00:00
2023-05-30 13:52:07 +00:00
await page . waitForLoadState ( "networkidle" ) ;
2023-04-21 13:49:53 +00:00
2023-05-30 13:52:07 +00:00
await expect ( page ) . toHaveURL ( /.*booking/ ) ;
2023-04-21 13:49:53 +00:00
2023-05-30 13:52:07 +00:00
await page . goto (
` /booking/ ${ booking . uid } ?cancel=true&allRemainingBookings=false&seatReferenceUid= ${ bookingSeats [ 1 ] . referenceUid } `
) ;
2023-04-21 13:49:53 +00:00
2023-05-30 13:52:07 +00:00
// Page should not be 404
2023-06-10 03:47:50 +00:00
await page . locator ( '[data-testid="confirm_cancel"]' ) . click ( ) ;
2023-04-21 13:49:53 +00:00
2023-05-30 13:52:07 +00:00
await page . waitForLoadState ( "networkidle" ) ;
2023-04-21 13:49:53 +00:00
2023-05-30 13:52:07 +00:00
await expect ( page ) . toHaveURL ( /.*booking/ ) ;
} ) ;
2023-04-21 13:49:53 +00:00
2023-05-30 13:52:07 +00:00
test ( "Should book with seats and hide attendees info from showAttendees true" , async ( {
page ,
users ,
bookings ,
} ) = > {
const { user , booking } = await createUserWithSeatedEventAndAttendees ( { users , bookings } , [
{ name : "John First" , email : "first+seats@cal.com" , timeZone : "Europe/Berlin" } ,
{ name : "Jane Second" , email : "second+seats@cal.com" , timeZone : "Europe/Berlin" } ,
] ) ;
2023-06-06 18:02:32 +00:00
await user . apiLogin ( ) ;
2023-05-30 13:52:07 +00:00
const bookingWithEventType = await prisma . booking . findFirst ( {
where : { uid : booking.uid } ,
select : {
id : true ,
eventTypeId : true ,
} ,
2023-04-21 13:49:53 +00:00
} ) ;
2023-05-30 13:52:07 +00:00
await prisma . eventType . update ( {
data : {
seatsShowAttendees : false ,
} ,
where : {
id : bookingWithEventType?.eventTypeId || - 1 ,
} ,
} ) ;
2023-04-21 13:49:53 +00:00
2023-05-30 13:52:07 +00:00
const bookingAttendees = await prisma . attendee . findMany ( {
where : { bookingId : booking.id } ,
select : {
id : true ,
} ,
} ) ;
2023-04-21 13:49:53 +00:00
2023-05-30 13:52:07 +00:00
const bookingSeats = [
{ bookingId : booking.id , attendeeId : bookingAttendees [ 0 ] . id , referenceUid : uuidv4 ( ) } ,
{ bookingId : booking.id , attendeeId : bookingAttendees [ 1 ] . id , referenceUid : uuidv4 ( ) } ,
] ;
2023-04-21 13:49:53 +00:00
2023-05-30 13:52:07 +00:00
await prisma . bookingSeat . createMany ( {
data : bookingSeats ,
} ) ;
2023-04-21 13:49:53 +00:00
2023-05-30 13:52:07 +00:00
// Go to cancel page and see that attendees are listed and myself as I'm owner of the booking
await page . goto ( ` /booking/ ${ booking . uid } ?cancel=true&allRemainingBookings=false ` ) ;
2023-04-21 13:49:53 +00:00
2023-05-30 13:52:07 +00:00
const foundFirstAttendeeAsOwner = await page . locator (
'p[data-testid="attendee-email-first+seats@cal.com"]'
) ;
await expect ( foundFirstAttendeeAsOwner ) . toHaveCount ( 1 ) ;
const foundSecondAttendeeAsOwner = await page . locator (
'p[data-testid="attendee-email-second+seats@cal.com"]'
) ;
await expect ( foundSecondAttendeeAsOwner ) . toHaveCount ( 1 ) ;
await page . goto ( "auth/logout" ) ;
2023-04-21 13:49:53 +00:00
2023-05-30 13:52:07 +00:00
// Now we cancel the booking as the first attendee
// booking/${bookingUid}?cancel=true&allRemainingBookings=false&seatReferenceUid={bookingSeat.referenceUid}
await page . goto (
` /booking/ ${ booking . uid } ?cancel=true&allRemainingBookings=false&seatReferenceUid= ${ bookingSeats [ 0 ] . referenceUid } `
) ;
// No attendees should be displayed only the one that it's cancelling
const notFoundSecondAttendee = await page . locator ( 'p[data-testid="attendee-email-second+seats@cal.com"]' ) ;
2023-04-21 13:49:53 +00:00
2023-05-30 13:52:07 +00:00
await expect ( notFoundSecondAttendee ) . toHaveCount ( 0 ) ;
const foundFirstAttendee = await page . locator ( 'p[data-testid="attendee-email-first+seats@cal.com"]' ) ;
await expect ( foundFirstAttendee ) . toHaveCount ( 1 ) ;
2023-04-21 13:49:53 +00:00
2023-05-30 13:52:07 +00:00
await prisma . eventType . update ( {
data : {
seatsShowAttendees : true ,
} ,
where : {
id : bookingWithEventType?.eventTypeId || - 1 ,
} ,
2023-04-21 13:49:53 +00:00
} ) ;
2023-05-30 13:52:07 +00:00
await page . goto (
` /booking/ ${ booking . uid } ?cancel=true&allRemainingBookings=false&seatReferenceUid= ${ bookingSeats [ 1 ] . referenceUid } `
) ;
// Now attendees should be displayed
const foundSecondAttendee = await page . locator ( 'p[data-testid="attendee-email-second+seats@cal.com"]' ) ;
await expect ( foundSecondAttendee ) . toHaveCount ( 1 ) ;
const foundFirstAttendeeAgain = await page
. locator ( 'p[data-testid="attendee-email-first+seats@cal.com"]' )
. first ( ) ;
await expect ( foundFirstAttendeeAgain ) . toHaveCount ( 1 ) ;
2023-03-14 04:19:05 +00:00
} ) ;
} ) ;