fix: prevent mobile schedule requests for non-mobile-eligible orders

Three bugs fixed:

1. Typo: order.lineItem -> order.lineItems in resetScheduleIfUnavailable
   The premium fee check was accessing a non-existent property, so the
   condition always evaluated to undefined (falsy), skipping the
   offerPremium validation entirely.

2. findIndex truthiness: findIndex returns -1 (truthy!) when not found
   and 0 (falsy!) when found at index 0. Changed to >= 0 check.

3. Unsafe default: getScheduleApiResponse had includeMobileTimeSlots
   defaulting to true, meaning any new caller that forgot the flag
   would request mobile time slots regardless of serviceability.
   Changed default to false.

Co-authored-by: Mark Harris <mark.harris@safelite.com>
This commit is contained in:
Cursor Agent 2026-04-09 21:05:21 +00:00
parent 5cf8816b0b
commit 08dca0f147
No known key found for this signature in database
2 changed files with 3 additions and 3 deletions

View file

@ -323,7 +323,7 @@ const getScheduleApiResponse = async ({
providerNumber,
inshopProviderNumber,
zipCode,
includeMobileTimeSlots = true,
includeMobileTimeSlots = false,
includeInshopTimeSlots = true,
}) => {
const apiEndDateLimit = sumDateString(startDateString, TIME_SLOTS_CALL_DAYS_LIMIT);

View file

@ -4169,9 +4169,9 @@ async function resetScheduleIfUnavailable(context, order, pageNameToLog) {
var mobileRouteCodeFound = false;
// if early bird fee is in supporting items then need to check the timeslot to see if offer premium is also still available
if (
order.lineItem?.supportingItems?.findIndex(
order.lineItems?.supportingItems?.findIndex(
(item) => item.partType == PREMIUM_FEE_PART_TYPE
)
) >= 0
) {
newTimeSlotsResponse.data.days?.forEach((day) => {
day.timeSlots.forEach((ts) => {