Stop a travel-time mock failing the appointment API tests
b1cb46ctest(appointments)merged 6d ago1 review thread
Illustrative: based on a real change, edited for clarity and privacy.
tests/Feature/Booking/Api/AppointmentApiTest.php+13 −0
| @@ | |||
| 33 | 33 | 'travel_start_location_type' => 'home', | |
| 34 | 34 | ]); | |
| 35 | 35 | $mock->shouldReceive('recalculateNextAppointmentTravelTime')->andReturnNull(); | |
| 36 | added | // Availability routing reaches these on some dates and times (the | |
| 37 | added | // test books "next monday"): a pure postcode check and a cache lookup | |
| 38 | added | // that answers as a cache hit, so no travel-time API is called. Any | |
| 39 | added | // other call still fails the test. | |
| 40 | added | $mock->shouldReceive('isSamePostcode')->andReturnUsing( | |
| 41 | added | fn (string $a, string $b): bool => strtoupper(str_replace(' ', '', trim($a))) | |
| 42 | added | === strtoupper(str_replace(' ', '', trim($b))) | |
| 43 | added | ); | |
| 1 line 44, review thread 1 | added | $mock->shouldReceive('getCachedTravelTimeOnly')->andReturn([ | |
| 45 | added | 'duration_minutes' => 25, | |
| 46 | added | 'duration_text' => '25 mins', | |
| 47 | added | 'has_real_data' => true, | |
| 48 | added | ]); | |
| 36 | 49 | }); | |
| 37 | 50 | ||
| 38 | 51 | // Use next Monday to guarantee a weekday the EPC works on | |
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?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.