<commit_before>import set from 'lodash/fp/set';
import mapValues from 'lodash/mapValues';

const initialState = {
  letters: [],
  destination: {},
  lettersAvailable: false,
  benefitInfo: {},
  serviceInfo: [],
  optionsAvailable: false,
  optionsToInclude: {}
};

function letters(state = initialState, action) {
  let options = {};

  switch (action.type) {
    case 'GET_LETTERS_SUCCESS':
      return {
        ...state,
        letters: action.data.data.attributes.letters,
        destination: action.data.meta.address,
        lettersAvailable: true
      };
    case 'GET_LETTERS_FAILURE':
      // We are currently ignoring this; consider removing once we're sure we've handled
      // the various error scenarios
      return set('lettersAvailable', false, state);
    case 'GET_BENEFIT_SUMMARY_OPTIONS_SUCCESS':
      // Create object for which options to include in post for summary letter
      // Default all options to true so they appear checked in the UI
      options = mapValues(action.data.data.attributes.benefitInformation, (value) => {
        // If the value of the benefit option is not false, it means the user
        // is eligible for that value. Default benefit options they are eligible for
        // to true. Keep benefit options that have a value of false as false, so
        // they are sent as false in the request for the pdf.
        return value !== false;
      });

      return {
        ...state,
        benefitInfo: action.data.data.attributes.benefitInformation,
        serviceInfo: action.data.data.attributes.militaryService,
        optionsAvailable: true,
        optionsToInclude: options
      };
    case 'GET_BENEFIT_SUMMARY_OPTIONS_FAILURE':<commit_msg>Hardcode 2 letters for usability testing (#5963)<commit_after>import set from 'lodash/fp/set';
import mapValues from 'lodash/mapValues';
import _ from 'lodash/fp';

const initialState = {
  letters: [],
  destination: {},
  lettersAvailable: false,
  benefitInfo: {},
  serviceInfo: [],
  optionsAvailable: false,
  optionsToInclude: {}
};

function letters(state = initialState, action) {
  let options = {};

  let letterList;
  switch (action.type) {
    case 'GET_LETTERS_SUCCESS':
      // Hard-code a few extra letters for usability testing purposes. Revert after testing.
      letterList = action.data.data.attributes.letters;
      if (_.findIndex({ letterType: 'medicare_partd' }, letterList) < 0) {
        letterList = _.concat(letterList, [{
          name: 'Proof of Creditable Prescription Drug Coverage Letter',
          letterType: 'medicare_partd'
        }]
        );
      }
      if (_.findIndex({ letterType: 'minimum_essential_coverage' }, letterList) < 0) {
        letterList = _.concat(letterList, [{
          name: 'Proof of Minimum Essential Coverage Letter',
          letterType: 'minimum_essential_coverage'
        }]
        );
      }
      return {
        ...state,
        letters: letterList,
        destination: action.data.meta.address,
        lettersAvailable: true
      };
    case 'GET_LETTERS_FAILURE':
      // We are currently ignoring this; consider removing once we're sure we've handled
      // the various error scenarios
      return set('lettersAvailable', false, state);
    case 'GET_BENEFIT_SUMMARY_OPTIONS_SUCCESS':
      // Create object for which options to include in post for summary letter
      // Default all options to true so they appear checked in the UI
      options = mapValues(action.data.data.attributes.benefitInformation, (value) => {
        // If the value of the benefit option is not false, it means the user
        // is eligible for that value. Default benefit options they are eligible for
        // to true. Keep benefit options that have a value of false as false, so
        // they are sent as false in the request for the pdf.
        return value !== false;
      });

      return {
        ...state,
        benefitInfo: action.data.data.attributes.benefitInformation,
        serviceInfo: action.data.data.attributes.militaryService,
        optionsAvailable: true,
        optionsToInclude: options
      };
    case 'GET_BENEFIT_SUMMARY_OPTIONS_FAILURE':
{'fraction_non_alphanumeric': 0.09287257019438445, 'fraction_numerical': 0.00167986561075114, 'mean_word_length': 2.754954954954955, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '906674', 'n_tokens_mistral': 1144, 'n_tokens_neox': 1104, 'n_words': 367}