All files / shared/utils tooEarlyForLotterySignup.ts

100% Statements 7/7
100% Branches 2/2
100% Functions 1/1
100% Lines 7/7

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          411x 1832x     1832x                   1832x   1832x 1146x     1427x    
import dayjs from "dayjs";
import { config } from "shared/config";
import { ProgramItem } from "shared/types/models/programItem";
import { getProgramItemStartTime } from "shared/utils/signupTimes";
 
export const tooEarlyForLotterySignup = (programItem: ProgramItem): boolean => {
  const { eventStartTime } = config.event();
 
  // The lottery window is driven by the parent-resolved start time, so use it here too
  const startTime = getProgramItemStartTime(programItem);
 
  // Return DIRECT for three first hours of event because there is no time for lottery signup
  // For example, if event starts at 15:00 and 'preSignupStart' is 4h and 'directSignupPhaseStart' is 2h
  //   Start time 15:00 -> lottery 11:00-13:00 -> use direct
  //   Start time 16:00 -> lottery 12:00-14:00 -> use direct
  //   Start time 17:00 -> lottery 13:00-15:00 -> use direct
  //   Start time 18:00 -> lottery 14:00-16:00 -> lottery with shorter duration 15:00-16:00 (see signupTimes.ts)
  //   Start time 19:00 -> lottery 15:00-17:00 -> show normally
 
  const noLotterySignupBefore = dayjs(eventStartTime).add(3, "hours");
 
  if (dayjs(startTime).isBefore(noLotterySignupBefore)) {
    return true;
  }
 
  return false;
};