All files / apps/chatbot/src/utils actionLabel.ts

100% Statements 14/14
100% Branches 8/8
100% Functions 4/4
100% Lines 8/8

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            7x 7x 7x     28x 97x 115x 59x 13x    
/**
 * The agent names its mutations freely (`remove`, `create_on_behalf_entry`,
 * `update_staff_role`, …), so the success card matches on intent keywords
 * rather than an enum it would have to keep in sync with the backend.
 * Order matters: `unassign` and `reassign` both contain `assign`.
 */
const REMOVE_KEYWORDS = ["remove", "delete", "unassign", "revoke"];
const UPDATE_KEYWORDS = ["update", "edit", "change", "modify", "replace", "reassign"];
const ADD_KEYWORDS = ["add", "create", "assign", "invite"];
 
export function confirmedCardTitle(actionType?: string | null): string {
  const normalized = typeof actionType === "string" ? actionType.toLowerCase() : "";
  if (REMOVE_KEYWORDS.some((keyword) => normalized.includes(keyword))) return "Removed";
  if (UPDATE_KEYWORDS.some((keyword) => normalized.includes(keyword))) return "Updated";
  if (ADD_KEYWORDS.some((keyword) => normalized.includes(keyword))) return "Added";
  return "Confirmed";
}