All files / server/src/features/assignment/utils getLotterySignupsInRun.ts

100% Statements 9/9
100% Branches 2/2
100% Functions 4/4
100% Lines 9/9

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          53x     282x 424x           53x         762x 4661x 4661x 2957x   1722x            
import { ProgramItem } from "shared/types/models/programItem";
import { LotterySignup } from "shared/types/models/user";
import { isSameStartTime } from "shared/utils/signupTimes";
 
// Indexed rather than scanned: asked once per lottery sign-up of every attendee group
export const indexProgramItemsById = (
  programItems: readonly ProgramItem[],
): ReadonlyMap<string, ProgramItem> =>
  new Map(
    programItems.map((programItem) => [programItem.programItemId, programItem]),
  );
 
// The preferences one run is allocating. The group list and the gain list have to answer this
// the same way, and a sign-up naming a program item the run is not allocating has no event to
// map to - the assigner rejects the whole input over a single such preference.
export const getLotterySignupsInRun = (
  lotterySignups: readonly LotterySignup[],
  programItemsById: ReadonlyMap<string, ProgramItem>,
  assignmentTime: string,
): LotterySignup[] =>
  lotterySignups.filter((lotterySignup) => {
    const programItem = programItemsById.get(lotterySignup.programItemId);
    if (!programItem) {
      return false;
    }
    return isSameStartTime(
      programItem.startTime,
      assignmentTime,
      programItem.parentId,
    );
  });