<commit_before>'use strict';

const Immutable = require('immutable');

const validateCompletion = (cff) => {
  // ERRORS: functions and validators needed to check for and return errors
  const validatorBlocks = Immutable.Sequence(
    Immutable.fromJS([
      {
        condition: (line) => line.get('payments') instanceof Immutable.Vector && line.get('payments').length > 0,
        msg: 'payments missing or invalid'
      },
      {
        condition: (line) => line.get('flowDirection') === 'in' || line.get('flowDirection') === 'out',
        msg: 'flowDirection missing or invalid'
      }
    ]),
    Immutable.fromJS([
      {
        condition: (line) => {
          return line.get('payments').every((payment) => (payment.has('date') || payment.has('expectedDate')) &&
            (payment.has('grossAmount') || payment.has('expectedGrossAmount')));
        },
        msg: 'one or more payments are incomplete'
      }
    ])
  );

  const getBlockErrors = (validatorBlock, line) => {
    if (typeof validatorBlock === 'undefined') {
      return Immutable.Vector();
    }
    return validatorBlock.reduce(
      (acc, validator) => {
        const error = Immutable.Map(
          {
            lineId: line.get('id') || 'UNKNOWN_LINE_ID',
            msg: validator.get('msg'),
          }
        );
        return !validator.get('condition')(line) ? acc.push(error) : acc;
      },Immutable.Vector()
    );<commit_msg>[core] completionValidator: now returns error if payment passed but not updatedpyaments with passed farthest date must have defined date and grossAmount, they cannot have only uncertain intervals<commit_after>'use strict';

const Immutable = require('immutable');

const validateCompletion = (cff) => {
  // ERRORS: functions and validators needed to check for and return errors
  const validatorBlocks = Immutable.Sequence(
    Immutable.fromJS([
      {
        condition: (line) => line.get('payments') instanceof Immutable.Vector && line.get('payments').length > 0,
        msg: 'payments missing or invalid'
      },
      {
        condition: (line) => line.get('flowDirection') === 'in' || line.get('flowDirection') === 'out',
        msg: 'flowDirection missing or invalid'
      }
    ]),
    Immutable.fromJS([
      {
        condition: (line) => {
          return line.get('payments').every((payment) => (payment.has('date') || payment.has('expectedDate')) &&
            (payment.has('grossAmount') || payment.has('expectedGrossAmount')));
        },
        msg: 'one or more payments are incomplete'
      }
    ]),
    Immutable.fromJS([
      {
        condition: (line) => line.get('payments').every((payment) => {
          const farthestDate = payment.get('date') || payment.getIn(['expectedDate', 0]);
          const today = new Date();
          const todayFormatted = [today.getFullYear(), ('0' + today.getMonth() + 1).slice(-2), ('0' + today.getDate()).slice(-2)].join('-');

          return payment.has('date') ? farthestDate > todayFormatted || payment.has('grossAmount')
            : farthestDate > todayFormatted;
        }),
        msg: 'one or more payments have passed farthest date but uncertain intervals'
      }
    ])
  );

  const getBlockErrors = (validatorBlock, line) => {
    if (typeof validatorBlock === 'undefined') {
      return Immutable.Vector();
    }
    return validatorBlock.reduce(
      (acc, validator) => {
        const error = Immutable.Map(
          {
            lineId: line.get('id') || 'UNKNOWN_LINE_ID',
            msg: validator.get('msg'),
          }
        );
        return !validator.get('condition')(line) ? acc.push(error) : acc;
      },Immutable.Vector()
    );
{'fraction_non_alphanumeric': 0.15424374319912948, 'fraction_numerical': 0.002176278563656148, 'mean_word_length': 2.6733266733266734, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '5510279', 'n_tokens_mistral': 1048, 'n_tokens_neox': 1035, 'n_words': 245}