We’d like to use PostHog to see how this site gets used, and Spotify to play the team’s funeral songs. Both set cookies, so they stay off until you allow them; everything else works without them. Privacy notice

Skip to content
death.tech home
All changes

Stop a travel-time mock failing the appointment API tests

b1cb46ctest(appointments)1 review thread

Illustrative: based on a real change, edited for clarity and privacy.

tests/Feature/Booking/Api/AppointmentApiTest.php+13 −0

Changes to tests/Feature/Booking/Api/AppointmentApiTest.php. Lines with review comments are numbered.
@@
3333 'travel_start_location_type' => 'home',
3434 ]);
3535 $mock->shouldReceive('recalculateNextAppointmentTravelTime')->andReturnNull();
36added // Availability routing reaches these on some dates and times (the
37added // test books "next monday"): a pure postcode check and a cache lookup
38added // that answers as a cache hit, so no travel-time API is called. Any
39added // other call still fails the test.
40added $mock->shouldReceive('isSamePostcode')->andReturnUsing(
41added fn (string $a, string $b): bool => strtoupper(str_replace(' ', '', trim($a)))
42added === strtoupper(str_replace(' ', '', trim($b)))
43added );
1 line 44, review thread 1added $mock->shouldReceive('getCachedTravelTimeOnly')->andReturn([
45added 'duration_minutes' => 25,
46added 'duration_text' => '25 mins',
47added 'has_real_data' => true,
48added ]);
3649 });
3750
3851 // Use next Monday to guarantee a weekday the EPC works on
    1. reviewer

      shouldIgnoreMissing() makes me nervous: any new call on the travel-time service would quietly get an empty answer and the test would still pass. Can we stub just the calls this path makes?

    2. author

      Agreed. shouldIgnoreMissing() is gone: the mock stubs exactly the two calls this path makes, a postcode comparison and a cached travel time, so no travel-time API is reached and any other call still fails the test.