fix: give chatbot pickups per-leg surcharges including the return leg

This commit is contained in:
fromme committed 2026-10-09 08:38:57 +02:00
1 parent ac5ca7b18b
commit 3cb1548f2f
8 files changed
+58 -7

No files matched your search

+19 -3
View File
@@ -127,10 +127,26 @@ class TripCatalogTest extends TestCase
self::assertCount(1, $trip['dates']);
self::assertSame('Hotel Eins', $trip['dates'][0]['hotels'][0]['hotel']);
self::assertSame([['room' => 'Zimmer', 'board' => 'HP', 'nights' => 7, 'price' => 450, 'availability' => 'frei']], $trip['dates'][0]['hotels'][0]['rooms']);
self::assertSame([['city' => 'Frankfurt', 'place' => 'Flughafen', 'departure' => '2026-12-04 23:30', 'surcharge' => 5.9]], $trip['dates'][0]['pickups']);
self::assertSame([['city' => 'Frankfurt', 'place' => 'Flughafen', 'departure' => '2026-12-04 23:30', 'surchargeOutbound' => 5.9, 'surchargeReturn' => 5.9, 'surchargeRoundTrip' => 11.8]], $trip['dates'][0]['pickups']);
self::assertArrayNotHasKey('guide', $trip['dates'][0]);
}
public function testPickupSurchargesArePerLegAndAnUnpricedLegIsFree(): void
{
$row = $this->row('VTH', 2, '2026-12-05', 'HOT1', [$this->room(450)]);
$row['pickups'] = [
['busProId' => 18, 'code' => 'ESS', 'city' => 'Essen', 'street' => 'Hbf', 'price' => 17.9, 'returnLeg' => true, 'returnPrice' => null, 'datetime' => null],
['busProId' => 4, 'code' => 'FRA', 'city' => 'Frankfurt', 'street' => 'Flughafen', 'price' => null, 'returnLeg' => false, 'returnPrice' => null, 'datetime' => null],
];
$pickups = $this->catalog([$row])->get('VTH')['dates'][0]['pickups'] ?? null;
self::assertSame([
['city' => 'Essen', 'place' => 'Hbf', 'surchargeOutbound' => 17.9, 'surchargeReturn' => 0.0, 'surchargeRoundTrip' => 17.9],
['city' => 'Frankfurt', 'place' => 'Flughafen', 'surchargeOutbound' => 0.0],
], $pickups, 'BusPro bills only priced legs; no return leg, no return surcharge');
}
public function testProductsHiddenFromTheWebsiteSearchAreNotOfferedButCanBeNamed(): void
{
$rows = [$this->row('GRP', 2, '2026-12-05', 'HOT1', [$this->room(300)])];
@@ -225,8 +241,8 @@ class TripCatalogTest extends TestCase
],
'rooms' => $rooms,
'pickups' => [
['busProId' => 4, 'code' => 'FRA', 'city' => 'Frankfurt', 'street' => 'Flughafen', 'price' => 5.9, 'datetime' => $dateFrom->modify('-1 day')->format('Y-m-d').'T23:30:00'],
['busProId' => 0, 'code' => null, 'city' => null, 'street' => null, 'price' => null, 'datetime' => null],
['busProId' => 4, 'code' => 'FRA', 'city' => 'Frankfurt', 'street' => 'Flughafen', 'price' => 5.9, 'returnLeg' => true, 'returnPrice' => 5.9, 'datetime' => $dateFrom->modify('-1 day')->format('Y-m-d').'T23:30:00'],
['busProId' => 0, 'code' => null, 'city' => null, 'street' => null, 'price' => null, 'returnLeg' => false, 'returnPrice' => null, 'datetime' => null],
],
'guide' => ['name' => 'Anna', 'phone' => '0170'],
];
+2
View File
@@ -88,6 +88,8 @@
<zustiege_rueck>
<!-- Priced on the return leg only: levelling would copy 3,00 onto the outbound entry. -->
<zustieg_rueck id="1" idbuspro="27" preis="3,00" />
<!-- Listed without a price: BusPro bills the return leg nothing. -->
<zustieg_rueck id="2" idbuspro="55" />
</zustiege_rueck>
</termin>
<!-- Unparseable date: its hotel row is dropped and counted. -->
@@ -159,6 +159,8 @@ class ProductExportBuilderTest extends TestCase
'city' => 'Stadt 4',
'street' => 'Strasse 4',
'price' => 5.9,
'returnLeg' => false,
'returnPrice' => null,
'datetime' => '2026-12-03T23:30:00',
], $pickups[0]);
self::assertNull($pickups[1]['price'], 'an absent price is null');
@@ -167,6 +169,15 @@ class ProductExportBuilderTest extends TestCase
self::assertNull($pickups[2]['code']);
}
public function testJoinsEachPickupWithItsReturnLegVerbatim(): void
{
$pickups = $this->rowFor('900-222931')['pickups'];
self::assertSame([false, true, true, false], array_column($pickups, 'returnLeg'));
self::assertSame(3.0, $pickups[1]['returnPrice']);
self::assertNull($pickups[2]['returnPrice'], 'listed on the return leg without a price');
}
public function testPickupTimesInTheSpringForwardGapAreNotShifted(): void
{
// DPWUSMP280327 in the 30.09.2026 13:11 export. Berlin skips 02:00-02:59 that night.