test: fix few flaky e2e tests (#24564)

* Add consistent ordering to seat references queries and fix ESLint warnings

- Add orderBy clause to seatsReferences in bookings list query
- Add orderBy clause to seatsReferences in getBookingToDelete query
- Ensures seat references are always returned in consistent order (by ID ascending)
- Prevents race conditions when matching seat references by user email
- Fix ESLint no-unused-expressions warnings by converting to if statements

Co-Authored-By: [email protected] <[email protected]>

* update

* Add ordering to attendee queries in tests for consistency

- Add orderBy clause to all attendee queries in booking-seats.e2e.ts
- Ensures attendees are queried in consistent order before mapping to seats
- Prevents mismatch between test expectations and actual seat order
- Fix unused variable warning

Co-Authored-By: [email protected] <[email protected]>

* Fix seat ordering to use attendeeId instead of seat ID

- Order seats by attendeeId in both bookings list and getBookingToDelete queries
- This ensures seats are returned in the same order as attendees were created
- Fixes mismatch where seat IDs and attendee IDs use different auto-increment sequences
- Also add attendeeId to seatsReferences select for consistency
- Fix ESLint warnings by converting && expressions to if statements

Co-Authored-By: [email protected] <[email protected]>

* Remove orderBy from bookingSeats queries

* update

* fix another test

* fix flakes

* Fix test to order seats by attendeeId to match backend ordering

The test was ordering seats by seat ID, but the backend orders by attendeeId. This caused flakiness because seat IDs and attendee IDs use different auto-increment sequences and can be in different orders. Now both test and backend use the same ordering (attendeeId), ensuring references[1] consistently refers to the second attendee's seat.

Also remove unused 'user' variable from test.

Co-Authored-By: [email protected] <[email protected]>

* Change orderBy from attendeeId to id in query

* Implement seatReferenceUid check in booking flow

Added logic to handle missing seatReferenceUid by reloading the page and retrying the action.

* Reduce wait time and update visibility check

* Update visibility check for 'Seats available' text

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2025-10-22 11:14:15 +05:30
1 parent 6923b97cd2
commit 2ad843ffbb
1 file changed
+18 -10
+18 -10
View File
@@ -191,11 +191,10 @@ test.describe("Reschedule for booking with seats", () => {
users,
bookings,
}) => {
const { user, booking } = await createUserWithSeatedEventAndAttendees({ users, bookings }, [
const { booking } = await createUserWithSeatedEventAndAttendees({ users, bookings }, [
{ name: "John First", email: "[email protected]", timeZone: "Europe/Berlin" },
{ name: "Jane Second", email: "[email protected]", timeZone: "Europe/Berlin" },
]);
await user.apiLogin();
const bookingAttendees = await prisma.attendee.findMany({
where: { bookingId: booking.id },
@@ -511,7 +510,7 @@ test.describe("Reschedule for booking with seats", () => {
users,
bookings,
}) => {
const { user, booking } = await createUserWithSeatedEventAndAttendees({ users, bookings }, [
const { booking } = await createUserWithSeatedEventAndAttendees({ users, bookings }, [
{ name: "John First", email: "[email protected]", timeZone: "Europe/Berlin" },
{ name: "Jane Second", email: "[email protected]", timeZone: "Europe/Berlin" },
]);
@@ -541,10 +540,9 @@ test.describe("Reschedule for booking with seats", () => {
data: bookingSeats,
});
const secondAttendeeId = bookingAttendees.find((attendee)=> attendee.email === "[email protected]");
const references = await prisma.bookingSeat.findFirst({
where: { bookingId: booking.id, attendeeId: secondAttendeeId?.id },
const references = await prisma.bookingSeat.findMany({
where: { bookingId: booking.id },
orderBy: { id: "asc" },
});
const secondUser = await users.create({
@@ -557,13 +555,23 @@ test.describe("Reschedule for booking with seats", () => {
await page.waitForSelector('[data-testid="bookings"]');
await page.locator('[data-testid="booking-actions-dropdown"]').nth(0).click();
await page.waitForTimeout(2000);
const href = await page.locator('[data-testid="reschedule"]').getAttribute("href");
expect(href).toBeTruthy();
const url = new URL(href!, page.url());
const seatReferenceUid = url.searchParams.get('seatReferenceUid');
expect(seatReferenceUid).toBeTruthy();
expect(seatReferenceUid).toBe(references?.referenceUid);
if(!seatReferenceUid) {
await page.reload();
await page.waitForSelector('[data-testid="bookings"]');
await page.locator('[data-testid="booking-actions-dropdown"]').nth(0).click();
await page.waitForTimeout(2000);
}
await page.locator('[data-testid="reschedule"]').click();
await expect(page.getByText("Seats available").first()).toBeVisible();
await page.waitForURL((url) => {
const rescheduleUid = url.searchParams.get("rescheduleUid");
return !!rescheduleUid && rescheduleUid === references[1].referenceUid;
});
await selectFirstAvailableTimeSlotNextMonth(page);