<commit_before>/* global chai */
/* global describe */
/* global it */

import _ from 'lodash';
import personUtils from '../../../app/core/personutils';
import { MGDL_UNITS, MMOLL_UNITS } from '../../../app/core/constants';
import config from '../../../app/config';

const FORM_DATE_FORMAT = 'MM/DD/YYYY';
const expect = chai.expect;


describe('personutils', () => {

  describe('fullName', () => {
    it('should return full name if exists', () => {
      var person = {
        profile: {fullName: '<NAME>'}
      };

      var result = personUtils.fullName(person);

      expect(result).to.equal('<NAME>');
    });
  });

  describe('patientInfo', () => {
    it('should return patient info if exists', () => {
      var person = {
        profile: {patient: {diagnosisDate: '1990-01-31'}}
      };

      var result = personUtils.patientInfo(person);

      expect(result.diagnosisDate).to.equal('1990-01-31');
    });
  });

  describe('hasAcceptedTerms', () => {
    it('should return true if the user has a valid date string in the `termsAccepted` field more recent than LATEST_TERMS', () => {
      var person = {termsAccepted: '2017-04-22T23:30:00+10:00'};

      config.LATEST_TERMS = '2017-04-22T23:00:00+10:00';
      expect(personUtils.hasAcceptedTerms(person)).to.be.true;
    });

    it('should return false if the user has a valid date string in the `termsAccepted` field less recent than LATEST_TERMS', () => {
      var person = {termsAccepted: '2017-04-22T23:00:00+10:00'};

      config.LATEST_TERMS = '2017-04-22T23:30:00+10:00';
      expect(personUtils.hasAcceptedTerms(person)).to.be.false;
    });

    it('should return true if the user has a valid date string in the `termsAccepted` field and LATEST_TERMS is null', () => {
      var person = {termsAccepted: '2015-01-01'};

      config.LATEST_TERMS = null;
      expect(personUtils.hasAcceptedTerms(person)).to.be.true;
    });

    it('should return true if the user has a valid date string in the `termsAccepted` field and LATEST_TERMS is invalid', () => {
      var person = {termsAccepted: '2015-01-01'};

      config.LATEST_TERMS = 'WHARRRRGARBLLL';
      expect(personUtils.hasAcceptedTerms(person)).to.be.true;
    });

    it('should return false if `termsAccepted` is an empty string and LATEST_TERMS is unset', () => {
      var person = {termsAccepted: ''};

      config.LATEST_TERMS = null;
      expect(personUtils.hasAcceptedTerms(person)).to.be.false;
    });

    it('should return false if `termsAccepted` does not exist and LATEST_TERMS is unset', () => {
      var person = {};

      config.LATEST_TERMS = null;
      expect(personUtils.hasAcceptedTerms(person)).to.be.false;
    });

    it('should return false if `termsAccepted` is an empty string and LATEST_TERMS is invalid', () => {
      var person = {termsAccepted: ''};

      config.LATEST_TERMS = 'WHARRRRGARBLLL';
      expect(personUtils.hasAcceptedTerms(person)).to.be.false;
    });

    it('should return false if `termsAccepted` does not exist and LATEST_TERMS is invalid', () => {
      var person = {};

      config.LATEST_TERMS = 'WHARRRRGARBLLL';
      expect(personUtils.hasAcceptedTerms(person)).to.be.false;
    });
  });

  describe('isPatient', () => {
    it('should return true if person has patient info', () => {
      var person = {
        profile: {patient: {diagnosisDate: '1990-01-31'}}
      };

      var result = personUtils.isPatient(person);

      expect(result).to.be.ok;
    });

    it('should return false if person does not have patient info', () => {
      var person = {
        profile: {}
      };

      var result = personUtils.isPatient(person);

      expect(result).to.not.be.ok;
    });
  });

  describe('isClinicianAccount', () => {
    it('should return true if person has clinic role', () => {
      var person = {
        profile: {
          fullName: '<NAME>'
        },
        roles: ['clinic']
      };

      var result = personUtils.isClinicianAccount(person);

      expect(result).to.be.ok;
    });

    it('should return false if person has no clinic role', () => {
      var person = {
        profile: {}
      };

      var result = personUtils.isClinicianAccount(person);

      expect(result).to.not.be.ok;
    });
  });

  describe('isDataDonationAccount', () => {
    it('should return true if the account username or email matches the donation account format', function () {
      var account1 = { email: '<EMAIL>' };
      var account2 = { email: '<EMAIL>' };
      var account3 = { username: '<EMAIL>' };

      var result1 = personUtils.isDataDonationAccount(account1);
      var result2 = personUtils.isDataDonationAccount(account2);<commit_msg>[WEB-880] update personutils tests<commit_after>/* global chai */
/* global describe */
/* global it */

import _ from 'lodash';
import personUtils from '../../../app/core/personutils';
import { MGDL_UNITS, MMOLL_UNITS } from '../../../app/core/constants';
import config from '../../../app/config';

const FORM_DATE_FORMAT = 'MM/DD/YYYY';
const expect = chai.expect;


describe('personutils', () => {

  describe('fullName', () => {
    it('should return full name if exists', () => {
      var person = {
        profile: {fullName: '<NAME>'}
      };

      var result = personUtils.fullName(person);

      expect(result).to.equal('<NAME>');
    });
  });

  describe('patientInfo', () => {
    it('should return patient info if exists', () => {
      var person = {
        profile: {patient: {diagnosisDate: '1990-01-31'}}
      };

      var result = personUtils.patientInfo(person);

      expect(result.diagnosisDate).to.equal('1990-01-31');
    });
  });

  describe('hasAcceptedTerms', () => {
    it('should return true if the user has a valid date string in the `termsAccepted` field more recent than LATEST_TERMS', () => {
      var person = {termsAccepted: '2017-04-22T23:30:00+10:00'};

      config.LATEST_TERMS = '2017-04-22T23:00:00+10:00';
      expect(personUtils.hasAcceptedTerms(person)).to.be.true;
    });

    it('should return false if the user has a valid date string in the `termsAccepted` field less recent than LATEST_TERMS', () => {
      var person = {termsAccepted: '2017-04-22T23:00:00+10:00'};

      config.LATEST_TERMS = '2017-04-22T23:30:00+10:00';
      expect(personUtils.hasAcceptedTerms(person)).to.be.false;
    });

    it('should return true if the user has a valid date string in the `termsAccepted` field and LATEST_TERMS is null', () => {
      var person = {termsAccepted: '2015-01-01'};

      config.LATEST_TERMS = null;
      expect(personUtils.hasAcceptedTerms(person)).to.be.true;
    });

    it('should return true if the user has a valid date string in the `termsAccepted` field and LATEST_TERMS is invalid', () => {
      var person = {termsAccepted: '2015-01-01'};

      config.LATEST_TERMS = 'WHARRRRGARBLLL';
      expect(personUtils.hasAcceptedTerms(person)).to.be.true;
    });

    it('should return false if `termsAccepted` is an empty string and LATEST_TERMS is unset', () => {
      var person = {termsAccepted: ''};

      config.LATEST_TERMS = null;
      expect(personUtils.hasAcceptedTerms(person)).to.be.false;
    });

    it('should return false if `termsAccepted` does not exist and LATEST_TERMS is unset', () => {
      var person = {};

      config.LATEST_TERMS = null;
      expect(personUtils.hasAcceptedTerms(person)).to.be.false;
    });

    it('should return false if `termsAccepted` is an empty string and LATEST_TERMS is invalid', () => {
      var person = {termsAccepted: ''};

      config.LATEST_TERMS = 'WHARRRRGARBLLL';
      expect(personUtils.hasAcceptedTerms(person)).to.be.false;
    });

    it('should return false if `termsAccepted` does not exist and LATEST_TERMS is invalid', () => {
      var person = {};

      config.LATEST_TERMS = 'WHARRRRGARBLLL';
      expect(personUtils.hasAcceptedTerms(person)).to.be.false;
    });
  });

  describe('isPatient', () => {
    it('should return true if person has patient info', () => {
      var person = {
        profile: {patient: {diagnosisDate: '1990-01-31'}}
      };

      var result = personUtils.isPatient(person);

      expect(result).to.be.ok;
    });

    it('should return false if person does not have patient info', () => {
      var person = {
        profile: {}
      };

      var result = personUtils.isPatient(person);

      expect(result).to.not.be.ok;
    });
  });

  describe('isClinicianAccount', () => {
    it('should return true if person has clinic role', () => {
      var person = {
        profile: {
          fullName: '<NAME>'
        },
        roles: ['clinic']
      };

      var result = personUtils.isClinicianAccount(person);

      expect(result).to.be.ok;
    });

    it('should return false if person has no clinic role', () => {
      var person = {
        profile: {}
      };

      var result = personUtils.isClinicianAccount(person);

      expect(result).to.not.be.ok;
    });

    it('should return true if person is clinic member', () => {
      var person = {
        profile: {
          fullName: '<NAME>'
        },
        isClinicMember: true,
      };

      var result = personUtils.isClinicianAccount(person);

      expect(result).to.be.ok;
    });

    it('should return false if person is not a clinic member', () => {
      var person = {
        profile: {
          fullName: '<NAME>'
        },
        isClinicMember: false,
      };

      var result = personUtils.isClinicianAccount(person);

      expect(result).to.not.be.ok;
    });
  });

  describe('isDataDonationAccount', () => {
    it('should return true if the account username or email matches the donation account format', function () {
      var account1 = { email: '<EMAIL>' };
      var account2 = { email: '<EMAIL>' };
      var account3 = { username: '<EMAIL>' };

      var result1 = personUtils.isDataDonationAccount(account1);
      var result2 = personUtils.isDataDonationAccount(account2);
{'fraction_non_alphanumeric': 0.1512992876492425, 'fraction_numerical': 0.02417979331794923, 'mean_word_length': 2.833846153846154, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 61, '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': '803451', 'n_tokens_mistral': 3364, 'n_tokens_neox': 3116, 'n_words': 734}