import { test, expect } from "@playwright/test"; import { PrismaClient } from "@prisma/client"; import { bookTrip } from "../../fixtures/booking-flow"; import { PROMO_VALID } from "../../fixtures/data"; const prisma = new PrismaClient(); test.afterAll(async () => { await prisma.$disconnect(); }); /** * Round-trip variant of UA-8 (H-13): a VALID promo must discount the COMBINED two-leg total, not * just one leg. createGuestRoundTripBooking is a separate implementation from one-way's * createGuestBooking — it already had one confirmed divergence from the one-way H-13 fix (missing * until a later patch), so this exists to catch any other one-way/round-trip discount divergence. * UA-6 established the no-discount round-trip baseline: totalMinor === cardBaseFareMinor * 2 for a * symmetric-distance route. PROMO_VALID is a flat 10% off (see fixtures/data.ts / seed-ui.ts). */ test("round-trip: a valid promo discounts the combined two-leg total (H-13 parity)", async ({ page }) => { const r = await bookTrip(page, { tripType: "ROUND_TRIP", nationality: "Ethiopian", paymentMethod: "WALLET", promoCode: PROMO_VALID, }); expect(r.confirmed).toBe(true); const booking = await prisma.booking.findUniqueOrThrow({ where: { id: r.bookingId } }); expect(booking.bookingType).toBe("ROUND_TRIP"); const combinedBaseFareMinor = r.cardBaseFareMinor * 2; // UA-6 baseline: symmetric legs const expectedDiscountMinor = Math.round(combinedBaseFareMinor * 0.1); const expectedTotalMinor = combinedBaseFareMinor - expectedDiscountMinor; expect(booking.totalMinor).toBeLessThan(combinedBaseFareMinor); // discount honored, not dropped expect(booking.totalMinor).toBe(expectedTotalMinor); });