mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-26 18:42:49 +00:00
49 lines
2.5 KiB
TypeScript
49 lines
2.5 KiB
TypeScript
import { test, expect } from "@playwright/test";
|
|
import { PrismaClient } from "@prisma/client";
|
|
import { bookTrip } from "../../fixtures/booking-flow";
|
|
|
|
const prisma = new PrismaClient();
|
|
test.afterAll(async () => {
|
|
await prisma.$disconnect();
|
|
});
|
|
|
|
/**
|
|
* Round-trip variants of UA-4/UA-5: the "first child per booking is free" policy applies once to
|
|
* the whole booking (not once per leg) — the same free/paid child determination is used to price
|
|
* BOTH legs (createGuestRoundTripBooking computes paidChildrenCount once, reuses it for
|
|
* outboundTotalBase and returnTotalBase). So a free child rides free on both legs, and a paid
|
|
* child pays full fare on both legs. UA-6 established the round-trip baseline: one seated
|
|
* passenger produces 2 bookingSeat rows (one per leg, distinguished by `leg`).
|
|
*/
|
|
|
|
test("round-trip: first child under 5 travels free on BOTH legs, total = one adult fare per leg", async ({ page }) => {
|
|
const r = await bookTrip(page, { tripType: "ROUND_TRIP", adults: 1, children: 1, paymentMethod: "WALLET" });
|
|
expect(r.confirmed).toBe(true);
|
|
|
|
const booking = await prisma.booking.findUniqueOrThrow({ where: { id: r.bookingId } });
|
|
expect(booking.bookingType).toBe("ROUND_TRIP");
|
|
// Free child contributes nothing on either leg — same as an adult-only round trip (UA-6 baseline).
|
|
expect(booking.totalMinor).toBe(r.cardBaseFareMinor * 2);
|
|
|
|
// Only the adult is seated — once per leg (2 rows), free child never occupies a seat on either leg.
|
|
const seats = await prisma.bookingSeat.findMany({ where: { bookingId: r.bookingId } });
|
|
expect(seats.length).toBe(2);
|
|
expect(new Set(seats.map((s) => s.leg)).size).toBe(2);
|
|
});
|
|
|
|
test("round-trip: with 1 adult + 2 children, the second child pays full fare on BOTH legs", async ({ page }) => {
|
|
const r = await bookTrip(page, { tripType: "ROUND_TRIP", adults: 1, children: 2, paymentMethod: "WALLET" });
|
|
expect(r.confirmed).toBe(true);
|
|
|
|
const booking = await prisma.booking.findUniqueOrThrow({ where: { id: r.bookingId } });
|
|
expect(booking.bookingType).toBe("ROUND_TRIP");
|
|
// (adult + paid child) per leg = 2 fares/leg, both legs = 4 fares total.
|
|
expect(booking.totalMinor).toBe(r.cardBaseFareMinor * 4);
|
|
|
|
// Adult + paid second child are seated on both legs = 4 rows (2 passengers x 2 legs); free
|
|
// first child never occupies a seat on either leg.
|
|
const seats = await prisma.bookingSeat.findMany({ where: { bookingId: r.bookingId } });
|
|
expect(seats.length).toBe(4);
|
|
expect(new Set(seats.map((s) => s.leg)).size).toBe(2);
|
|
});
|