<commit_before>const config = require('../../../../config')
const transformInteractionResponseToViewRecord = require('../interaction-response-to-view')

const mcokDraftPastMeeting = require('../../../../../test/unit/data/interactions/draft-past-meeting.json')
const mockInteraction = require('../../../../../test/unit/data/interactions/interaction.json')
const mockInteractionWithPolicyFeedback = require('../../../../../test/unit/data/interactions/interaction-with-feedback.json')

const { generateExportCountries } = require('../../../../../test/unit/helpers/generate-export-countries')

config.archivedDocumentsBaseUrl = 'http://base'

function getCountryNames (countries) {
  return countries.map(([, name]) => name).join(', ')
}

describe('#transformInteractionResponsetoViewRecord', () => {
  context('when the interaction-add-countries feature flag is true', () => {
    const transformedMockInteraction = {
      Company: {
        url: '/companies/0f5216e0-849f-11e6-ae22-56b6b6499611',
        name: 'Venus Ltd',
      },
      'Contact(s)': [
        {
          url: '/contacts/7701587b-e88f-4f39-874f-0bd06321f7df',
          name: '<NAME>|c95c0a3f-cc44-4419-bd34-648e74d652f5',
        },
      ],
      Service: {
        id: 'sv1',
        name: 'Account Management',
      },
      Notes: 'Labore\nculpa\nquas\ncupiditate\nvoluptatibus\nmagni.',
      'Policy area': 'Access to Public Funding (inc. EU funding)',
      'Policy feedback notes':
        'Labore\nculpa\nquas\ncupiditate\nvoluptatibus\nmagni.',
      'Policy issue types': 'EU exit',
      'Date of interaction': {
        type: 'date',
        name: '2058-11-25',
      },
      Documents: {
        hint: '(will open another website)',
        hintId: 'external-link-label',
        name: 'View files and documents',
        url: 'http://base/documents/123',
      },
      'Adviser(s)': ['<NAME>, The test team'],
      'Investment project': {
        url: '/investments/projects/bac18331-ca4d-4501-960e-a1bd68b5d47e',
        name: 'Test project',
      },
      'Communication channel': {
        id: '70c226d7-5d95-e211-a939-e4115bead28a',
        name: 'Email/Website',
      },
    }

    const LABELS = {
      CURRENT: 'Countries currently exporting to',
      FUTURE: 'Future countries of interest',
      NOT_INTERESTED: 'Countries not interested in',
    }

    context('when provided a fully populated interaction with export countries', () => {
      context('When the array has entries for each status', () => {
        it('should transform to display format', () => {
          const countries = generateExportCountries()
          const transformed = transformInteractionResponseToViewRecord(
            {
              ...mockInteraction,
              archived_documents_url_path: '/documents/123',
              investment_project: {
                id: 'bac18331-ca4d-4501-960e-a1bd68b5d47e',
                name: 'Test project',
              },
              export_countries: countries.exportCountries,
            },
            true,<commit_msg>Refactor unit test to use urls library instead of url string<commit_after>const config = require('../../../../config')
const transformInteractionResponseToViewRecord = require('../interaction-response-to-view')

const mcokDraftPastMeeting = require('../../../../../test/unit/data/interactions/draft-past-meeting.json')
const mockInteraction = require('../../../../../test/unit/data/interactions/interaction.json')
const mockInteractionWithPolicyFeedback = require('../../../../../test/unit/data/interactions/interaction-with-feedback.json')

const { generateExportCountries } = require('../../../../../test/unit/helpers/generate-export-countries')
const urls = require('../../../../lib/urls')

config.archivedDocumentsBaseUrl = 'http://base'

function getCountryNames (countries) {
  return countries.map(([, name]) => name).join(', ')
}

describe('#transformInteractionResponsetoViewRecord', () => {
  context('when the interaction-add-countries feature flag is true', () => {
    const transformedMockInteraction = {
      Company: {
        url: urls.companies.detail('0f5216e0-849f-11e6-ae22-56b6b6499611'),
        name: 'Venus Ltd',
      },
      'Contact(s)': [
        {
          url: urls.contacts.contact('7701587b-e88f-4f39-874f-0bd06321f7df'),
          name: '<NAME>|c95c0a3f-cc44-4419-bd34-648e74d652f5',
        },
      ],
      Service: {
        id: 'sv1',
        name: 'Account Management',
      },
      Notes: 'Labore\nculpa\nquas\ncupiditate\nvoluptatibus\nmagni.',
      'Policy area': 'Access to Public Funding (inc. EU funding)',
      'Policy feedback notes':
        'Labore\nculpa\nquas\ncupiditate\nvoluptatibus\nmagni.',
      'Policy issue types': 'EU exit',
      'Date of interaction': {
        type: 'date',
        name: '2058-11-25',
      },
      Documents: {
        hint: '(will open another website)',
        hintId: 'external-link-label',
        name: 'View files and documents',
        url: 'http://base/documents/123',
      },
      'Adviser(s)': ['<NAME>, The test team'],
      'Investment project': {
        url: urls.investments.projects.project('bac18331-ca4d-4501-960e-a1bd68b5d47e'),
        name: 'Test project',
      },
      'Communication channel': {
        id: '70c226d7-5d95-e211-a939-e4115bead28a',
        name: 'Email/Website',
      },
    }

    const LABELS = {
      CURRENT: 'Countries currently exporting to',
      FUTURE: 'Future countries of interest',
      NOT_INTERESTED: 'Countries not interested in',
    }

    context('when provided a fully populated interaction with export countries', () => {
      context('When the array has entries for each status', () => {
        it('should transform to display format', () => {
          const countries = generateExportCountries()
          const transformed = transformInteractionResponseToViewRecord(
            {
              ...mockInteraction,
              archived_documents_url_path: '/documents/123',
              investment_project: {
                id: 'bac18331-ca4d-4501-960e-a1bd68b5d47e',
                name: 'Test project',
              },
              export_countries: countries.exportCountries,
            },
            true,
{'fraction_non_alphanumeric': 0.1528846153846154, 'fraction_numerical': 0.04519230769230769, 'mean_word_length': 2.4710789766407117, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, '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': '6544416', 'n_tokens_mistral': 2084, 'n_tokens_neox': 1892, 'n_words': 354}