All files / utils gameUtils.js

100% Statements 16/16
100% Branches 14/14
100% Functions 9/9
100% Lines 14/14

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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66      3x 3x       1x                         86x 66x   20x 4x   16x                       44x 44x   90x                             20x 17x   31x          
import { toast } from "react-toastify";
 
export function onDeleteSuccess(message) {
  console.log(message);
  toast(message);
}
 
export function cellToAxiosParamsDelete(cell) {
  return {
    url: "/api/game",
    method: "DELETE",
    params: {
      id: cell.row.values["game.id"],
    },
  };
}
 
// A game with no course is visible to everyone. A course-linked game
// is only visible to users enrolled in that course (as a student or staff
// member), or to admins. See issue #251.
export function isEligibleForCourseLinkedGame(game, myCourseIds, isAdmin) {
  if (game.courseId == null) {
    return true;
  }
  if (isAdmin) {
    return true;
  }
  return myCourseIds.includes(game.courseId);
}
 
export function filterGameNotJoinedAndNotHidden(
  game,
  gameJoined,
  // Stryker disable next-line ArrayDeclaration : any placeholder array is
  // behaviorally equivalent to [] here, since .includes() on a real numeric
  // courseId will never match Stryker's string placeholder either way.
  myCourseIds = [],
  isAdmin = false,
) {
  const joinedIdList = gameJoined.map((c) => c.id);
  return game.filter(
    (f) =>
      !f.hidden &&
      !joinedIdList.includes(f.id) &&
      isEligibleForCourseLinkedGame(f, myCourseIds, isAdmin),
  );
}
 
export function filterGameJoinedAndNotHidden(
  game,
  gameJoined,
  // Stryker disable next-line ArrayDeclaration : any placeholder array is
  // behaviorally equivalent to [] here, since .includes() on a real numeric
  // courseId will never match Stryker's string placeholder either way.
  myCourseIds = [],
  isAdmin = false,
) {
  const joinedIdList = gameJoined.map((c) => c.id);
  return game.filter(
    (f) =>
      !f.hidden &&
      joinedIdList.includes(f.id) &&
      isEligibleForCourseLinkedGame(f, myCourseIds, isAdmin),
  );
}