All files / src/features/targets/utils affectedExperiments.js

100% Statements 12/12
100% Branches 15/15
100% Functions 6/6
100% Lines 12/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29        12x 3x     9x   9x 14x 14x 19x   14x   18x 18x 16x   14x              
export default function resolveAffectedExperiments(
  experimentIds,
  experimentsList,
) {
  if (!Array.isArray(experimentIds) || experimentIds.length === 0) {
    return [];
  }
 
  const list = Array.isArray(experimentsList) ? experimentsList : [];
 
  return experimentIds.map((id) => {
    const key = String(id);
    const found = list.find(
      (exp) => String(exp.id) === key || String(exp.redisId) === key,
    );
    const recipeIds = Array.isArray(found?.recipes)
      ? found.recipes
        .map((r) => r?.id)
        .filter((rid) => rid !== null && rid !== undefined && rid !== '')
        .map((rid) => String(rid))
      : [];
    return {
      id: key,
      name: found?.name || null,
      recipeIds,
    };
  });
}