All files / src/components/Merchants/MerchantPreview/modals/shared GiveOFACMatchList.tsx

91.66% Statements 11/12
70% Branches 7/10
100% Functions 5/5
100% Lines 11/11

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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48                    1x 7x   7x     7x 7x 14x   7x 28x 14x                     7x     7x                      
import { Stack } from "@mui/material";
import GiveDetailsMatchList, { MatchItem } from "./GiveDetailsMatchList";
import { capitalizeEachWord } from "@utils/index";
 
type MatchDetail = Record<string, string | number | null | undefined>;
 
type GiveOFACMatchListProps = {
  matches: MatchDetail[];
};
 
const GiveOFACMatchList = ({ matches }: GiveOFACMatchListProps) => {
  Iif (!matches || matches.length === 0) return null;
 
  const skipKeys = new Set(["name", "fullname", "score"]);
 
  // Transform OFAC match data to the shared MatchItem[][] format
  const transformedMatches: MatchItem[][] = matches.map((match) => {
    const getPrimaryName = () =>
      String(match.name || match.Name || match.fullName || "Unknown");
 
    const items: MatchItem[] = Object.entries(match)
      .filter(([key]) => !skipKeys.has(key.toLowerCase()))
      .map(([key, value]) => ({
        label: key
          ? capitalizeEachWord(key, "_")
              .replaceAll("_", " ")
              .replaceAll("Id", "ID")
              .replaceAll("Url", "URL")
          : "",
        value,
      }));
 
    // Add primary name as first item
    return [{ label: getPrimaryName(), value: getPrimaryName() }, ...items];
  });
 
  return (
    <Stack gap={0} data-testid="ofac-match-list">
      <GiveDetailsMatchList
        items={transformedMatches}
        testIdPrefix="ofac-match"
      />
    </Stack>
  );
};
 
export default GiveOFACMatchList;