<commit_before>const dateFns = require('date-fns');
const { utcToZonedTime, format } = require('date-fns-tz');

const isoDateWithoutTimezoneFormat = "yyyy-LL-dd'T'HH:mm:ss";
const isoDateWithOffsetFormat = "yyyy-LL-dd'T'HH:mm:ss.SSSxxx";

// check in UUIDS
const defaultUUID = '46bebc0a-b99c-464f-a5c5-560bc9eae287';
const aboutToExpireUUID = '25165847-2c16-4c8b-8790-5de37a7f427f';
const pacificTimezoneUUID = '6c72b801-74ac-47fe-82af-cfe59744b45f';
const allAppointmentTypesUUID = 'bb48c558-7b35-44ec-8ab7-32b7d49364fc';

const mockDemographics = {
  emergencyContact: {
    name: '<NAME>',
    workPhone: '',
    relationship: 'EXTENDED FAMILY MEMBER',
    phone: '5558675309',
    address: {
      zip: '87102',
      country: 'USA',
      street3: '',
      city: 'Albuquerque',
      county: null,
      street1: '1233 8th Street',
      zip4: '',
      street2: '',
      state: 'New Mexico',
    },
  },
  nextOfKin1: {
    name: '<NAME>',
    relationship: 'BROTHER',
    phone: '1112223333',
    workPhone: '4445556666',
    address: {
      street1: '123 Main St',
      street2: 'Ste 234',
      street3: '',
      city: 'Los Angeles',
      county: 'Los Angeles',
      state: 'CA',
      zip: '90089',
      zip4: '',
      country: 'USA',
    },
  },
  mailingAddress: {
    street1: '123 Turtle Trail',
    street2: '',
    street3: '',
    city: 'Treetopper',
    state: 'Tennessee',
    zip: '101010',
  },
  homeAddress: {
    street1: '445 Fine Finch Fairway',
    street2: 'Apt 201',
    city: 'Fairfence',
    state: 'Florida',
    zip: '445545',
  },
  homePhone: '5552223333',
  mobilePhone: '5553334444',
  workPhone: '5554445555',
  emailAddress: '<EMAIL>',
};

const getAppointmentStartTime = (
  eligibility = 'ELIGIBLE',
  preCheckInValid = false,
  uuid = defaultUUID,
) => {
  let startTime = preCheckInValid ? dateFns.addDays(new Date(), 1) : new Date();

  if (eligibility === 'INELIGIBLE_TOO_LATE') {
    startTime = dateFns.subHours(startTime, 1);
  } else if (eligibility === 'INELIGIBLE_TOO_EARLY') {
    startTime = dateFns.addHours(startTime, 1);
  } else if (uuid === aboutToExpireUUID) {
    startTime = dateFns.subMinutes(startTime, 14);
  } else {
    startTime = dateFns.addMinutes(startTime, 15);
  }

  return startTime;
};

const createAppointment = ({
  eligibility = 'ELIGIBLE',
  facilityId = 'some-facility',
  appointmentIen = Math.floor(Math.random() * 100000),
  clinicFriendlyName = 'HEART CLINIC 1',
  preCheckInValid = false,
  uuid = defaultUUID,
  timezone = 'browser',
  stationNo = '0001',
  clinicLocation = 'SECOND FLOOR ROOM 2',
  kind = 'clinic',
  status = '',
  startTime = getAppointmentStartTime(eligibility, preCheckInValid, uuid),
  checkInSteps = [],
  clinicStopCodeName = 'Mental health',
  doctorName = 'Dr. Jones',
} = {}) => {
  const formattedStartTime = dateFns.format(
    startTime,
    isoDateWithoutTimezoneFormat,
  );

  // C.f. CHECKIN_MINUTES_BEFORE in {chip repo}/infra/template.yml
  let checkInWindowStart = dateFns.subMinutes(new Date(startTime), 30);
  let formattedCheckInWindowStart = format(
    checkInWindowStart,
    isoDateWithOffsetFormat,
  );
  // C.f. CHECKIN_MINUTES_AFTER in {chip repo}/infra/template.yml
  let checkInWindowEnd = dateFns.addMinutes(new Date(startTime), 15);
  let formattedCheckInWindowEnd = dateFns.format(
    checkInWindowEnd,
    isoDateWithOffsetFormat,
  );

  if (timezone !== 'browser') {
    checkInWindowStart = dateFns.subMinutes(
      utcToZonedTime(new Date(startTime), timezone),
      30,
    );
    formattedCheckInWindowStart = format(
      checkInWindowStart,
      isoDateWithOffsetFormat,
      { timeZone: timezone },
    );
    checkInWindowEnd = dateFns.addMinutes(
      utcToZonedTime(new Date(startTime), timezone),
      15,
    );
    formattedCheckInWindowEnd = format(
      checkInWindowEnd,
      isoDateWithOffsetFormat,
      { timeZone: timezone },
    );
  }<commit_msg>Updated mock to set checkInWindowStart 45minutes before startTime. (#22642)<commit_after>const dateFns = require('date-fns');
const { utcToZonedTime, format } = require('date-fns-tz');

const isoDateWithoutTimezoneFormat = "yyyy-LL-dd'T'HH:mm:ss";
const isoDateWithOffsetFormat = "yyyy-LL-dd'T'HH:mm:ss.SSSxxx";

// check in UUIDS
const defaultUUID = '46bebc0a-b99c-464f-a5c5-560bc9eae287';
const aboutToExpireUUID = '25165847-2c16-4c8b-8790-5de37a7f427f';
const pacificTimezoneUUID = '6c72b801-74ac-47fe-82af-cfe59744b45f';
const allAppointmentTypesUUID = 'bb48c558-7b35-44ec-8ab7-32b7d49364fc';

// Minutes before start time that the window for check-in starts.
const checkInStartWindowMinutes = 45;

const mockDemographics = {
  emergencyContact: {
    name: '<NAME>',
    workPhone: '',
    relationship: 'EXTENDED FAMILY MEMBER',
    phone: '5558675309',
    address: {
      zip: '87102',
      country: 'USA',
      street3: '',
      city: 'Albuquerque',
      county: null,
      street1: '1233 8th Street',
      zip4: '',
      street2: '',
      state: 'New Mexico',
    },
  },
  nextOfKin1: {
    name: '<NAME>',
    relationship: 'BROTHER',
    phone: '1112223333',
    workPhone: '4445556666',
    address: {
      street1: '123 Main St',
      street2: 'Ste 234',
      street3: '',
      city: 'Los Angeles',
      county: 'Los Angeles',
      state: 'CA',
      zip: '90089',
      zip4: '',
      country: 'USA',
    },
  },
  mailingAddress: {
    street1: '123 Turtle Trail',
    street2: '',
    street3: '',
    city: 'Treetopper',
    state: 'Tennessee',
    zip: '101010',
  },
  homeAddress: {
    street1: '445 Fine Finch Fairway',
    street2: 'Apt 201',
    city: 'Fairfence',
    state: 'Florida',
    zip: '445545',
  },
  homePhone: '5552223333',
  mobilePhone: '5553334444',
  workPhone: '5554445555',
  emailAddress: '<EMAIL>',
};

const getAppointmentStartTime = (
  eligibility = 'ELIGIBLE',
  preCheckInValid = false,
  uuid = defaultUUID,
) => {
  let startTime = preCheckInValid ? dateFns.addDays(new Date(), 1) : new Date();

  if (eligibility === 'INELIGIBLE_TOO_LATE') {
    startTime = dateFns.subHours(startTime, 1);
  } else if (eligibility === 'INELIGIBLE_TOO_EARLY') {
    startTime = dateFns.addHours(startTime, 1);
  } else if (uuid === aboutToExpireUUID) {
    startTime = dateFns.subMinutes(startTime, 14);
  } else {
    startTime = dateFns.addMinutes(startTime, 15);
  }

  return startTime;
};

const createAppointment = ({
  eligibility = 'ELIGIBLE',
  facilityId = 'some-facility',
  appointmentIen = Math.floor(Math.random() * 100000),
  clinicFriendlyName = 'HEART CLINIC 1',
  preCheckInValid = false,
  uuid = defaultUUID,
  timezone = 'browser',
  stationNo = '0001',
  clinicLocation = 'SECOND FLOOR ROOM 2',
  kind = 'clinic',
  status = '',
  startTime = getAppointmentStartTime(eligibility, preCheckInValid, uuid),
  checkInSteps = [],
  clinicStopCodeName = 'Mental health',
  doctorName = 'Dr. Jones',
} = {}) => {
  const formattedStartTime = dateFns.format(
    startTime,
    isoDateWithoutTimezoneFormat,
  );

  // C.f. CHECKIN_MINUTES_BEFORE in {chip repo}/infra/template.yml
  let checkInWindowStart = dateFns.subMinutes(
    new Date(startTime),
    checkInStartWindowMinutes,
  );
  let formattedCheckInWindowStart = format(
    checkInWindowStart,
    isoDateWithOffsetFormat,
  );
  // C.f. CHECKIN_MINUTES_AFTER in {chip repo}/infra/template.yml
  let checkInWindowEnd = dateFns.addMinutes(new Date(startTime), 15);
  let formattedCheckInWindowEnd = dateFns.format(
    checkInWindowEnd,
    isoDateWithOffsetFormat,
  );

  if (timezone !== 'browser') {
    checkInWindowStart = dateFns.subMinutes(
      utcToZonedTime(new Date(startTime), timezone),
      checkInStartWindowMinutes,
    );
    formattedCheckInWindowStart = format(
      checkInWindowStart,
      isoDateWithOffsetFormat,
      { timeZone: timezone },
    );
    checkInWindowEnd = dateFns.addMinutes(
      utcToZonedTime(new Date(startTime), timezone),
      15,
    );
    formattedCheckInWindowEnd = format(
      checkInWindowEnd,
      isoDateWithOffsetFormat,
      { timeZone: timezone },
    );
  }
{'fraction_non_alphanumeric': 0.1336547972304649, 'fraction_numerical': 0.05576162215628091, 'mean_word_length': 3.518994413407821, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1793015', 'n_tokens_mistral': 3207, 'n_tokens_neox': 2909, 'n_words': 562}