<commit_before>const transformInteractionToListItem = require('~/src/apps/interactions/transformers/interaction-to-list-item')
const mockInteraction = require('~/test/unit/data/interactions/search-interaction.json')
const mockInteractionWithFeedback = require('~/test/unit/data/interactions/search-interaction-with-feedback.json')

describe('#transformInteractionToListItem', () => {
  context('when the source is an interaction', () => {
    beforeEach(() => {
      mockInteraction.kind = 'interaction'
      this.transformed = transformInteractionToListItem()(mockInteraction)
    })

    it('should transform data from interaction response to list item', () => {
      expect(this.transformed).to.deep.equal({
        was_policy_feedback_provided: false,
        id: '7265dc3c-e89d-45ee-8106-d1e370c1c73d',
        type: 'interaction',
        name: 'Test interactions',
        meta: [
          {
            label: 'Type',
            type: 'badge',
            value: 'Interaction',
          },
          {
            label: 'Date',
            type: 'date',
            value: '2017-05-31T00:00:00',
          },
          {
            label: 'Contact(s)',
            value: ['<NAME>'],
          },
          {
            label: 'Company',
            value: {
              id: 'dcdabbc9-1781-e411-8955-e4115bead28a',
              name: 'Samsung',
            },
          },
          {
            label: 'Adviser(s)',
            value: ['<NAME>, The test team'],
          },
          {
            label: 'Service',
            value: {
              id: '1231231231312',
              name: 'Test service',
            },
          },
        ],
      })
    })
  })

  context('When the source is an interaction with multiple contacts', () => {
    beforeEach(() => {
      this.transformed = transformInteractionToListItem()({
        ...mockInteraction,
        contacts: [{
          'id': 'b4919d5d-8cfb-49d1-a3f8-e4eb4b61e306',
          'first_name': 'Jackson',
          'last_name': 'Whitfield',
          'name': '<NAME>',
        }, {
          'id': 'b4919d5d-8cfb-49d1-a3f8-e4eb4b61e306',
          'first_name': 'Jackson2',
          'last_name': 'Whitfield2',
          'name': '<NAME>',
        }],
      })
    })

    it('should transform the contacts names value', () => {
      const contacts = this.transformed.meta.find((element) => {
        return element.label === 'Contact(s)'
      })
      expect(contacts.value).to.equal('Multiple contacts')
    })
  })

  context('when the source is an interaction with an empty subject', () => {
    beforeEach(() => {
      this.transformed = transformInteractionToListItem()({
        ...mockInteraction,
        subject: '',
      })
    })

    it('should transform data from interaction response to list item', () => {
      expect(this.transformed).have.property('name', 'No subject')
    })
  })

  context('when the source is an interaction with a null subject', () => {
    beforeEach(() => {
      this.transformed = transformInteractionToListItem()({
        ...mockInteraction,
        subject: null,
      })
    })

    it('should transform data from interaction response to list item', () => {
      expect(this.transformed).have.property('name', 'No subject')
    })
  })
<commit_msg>Update unit tests around no adviser or contact<commit_after>const { find } = require('lodash')
const transformInteractionToListItem = require('~/src/apps/interactions/transformers/interaction-to-list-item')
const mockInteraction = require('~/test/unit/data/interactions/search-interaction.json')
const mockInteractionWithFeedback = require('~/test/unit/data/interactions/search-interaction-with-feedback.json')

describe('#transformInteractionToListItem', () => {
  context('when the source is an interaction', () => {
    beforeEach(() => {
      mockInteraction.kind = 'interaction'
      this.transformed = transformInteractionToListItem()(mockInteraction)
    })

    it('should transform data from interaction response to list item', () => {
      expect(this.transformed).to.deep.equal({
        was_policy_feedback_provided: false,
        id: '7265dc3c-e89d-45ee-8106-d1e370c1c73d',
        type: 'interaction',
        name: 'Test interactions',
        meta: [
          {
            label: 'Type',
            type: 'badge',
            value: 'Interaction',
          },
          {
            label: 'Date',
            type: 'date',
            value: '2017-05-31T00:00:00',
          },
          {
            label: 'Contact(s)',
            value: ['<NAME>'],
          },
          {
            label: 'Company',
            value: {
              id: 'dcdabbc9-1781-e411-8955-e4115bead28a',
              name: 'Samsung',
            },
          },
          {
            label: 'Adviser(s)',
            value: ['<NAME>, The test team'],
          },
          {
            label: 'Service',
            value: {
              id: '1231231231312',
              name: 'Test service',
            },
          },
        ],
      })
    })
  })

  context('When the source is an interaction with multiple contacts', () => {
    beforeEach(() => {
      this.transformed = transformInteractionToListItem()({
        ...mockInteraction,
        contacts: [{
          'id': 'b4919d5d-8cfb-49d1-a3f8-e4eb4b61e306',
          'first_name': 'Jackson',
          'last_name': 'Whitfield',
          'name': '<NAME>',
        }, {
          'id': 'b4919d5d-8cfb-49d1-a3f8-e4eb4b61e306',
          'first_name': 'Jackson2',
          'last_name': 'Whitfield2',
          'name': '<NAME>',
        }],
      })
    })

    it('should transform the contacts names value', () => {
      const contacts = this.transformed.meta.find((element) => {
        return element.label === 'Contact(s)'
      })
      expect(contacts.value).to.equal('Multiple contacts')
    })
  })

  context('when the source is an interaction with an empty subject', () => {
    beforeEach(() => {
      this.transformed = transformInteractionToListItem()({
        ...mockInteraction,
        subject: '',
      })
    })

    it('should transform data from interaction response to list item', () => {
      expect(this.transformed).have.property('name', 'No subject')
    })
  })

  context('when the source is an interaction with a null subject', () => {
    beforeEach(() => {
      this.transformed = transformInteractionToListItem()({
        ...mockInteraction,
        subject: null,
      })
    })

    it('should transform data from interaction response to list item', () => {
      expect(this.transformed).have.property('name', 'No subject')
    })
  })

  context('when the source is an interaction with adviser and team name', () => {
    it('should return adviser name and team', () => {
      this.transformed = transformInteractionToListItem()({
        ...mockInteraction,
        dit_participants: [
          {
            adviser: {
              id: 1,
              first_name: 'Bob',
              last_name: 'Lawson',
              name: '<NAME>',
            },
            team: {
              id: 1,
              name: 'The test team',
            },
          }],
      })
      const metadata = this.transformed.meta
      const adviserName = find(metadata, (item) => item.label === 'Adviser(s)')
      expect(adviserName.value).to.deep.equal(['<NAME>, The test team'])
    })
  })

  context('when the source is an interaction with a null team name', () => {
    it('should return just an adviser name', () => {
      this.transformed = transformInteractionToListItem()({
        ...mockInteraction,
        dit_participants: [
          {
            adviser: {
              id: 1,
              first_name: 'Bob',
              last_name: 'Lawson',
              name: '<NAME>',
            },
            team: null,
          }],
      })
      const metadata = this.transformed.meta
      const adviserName = find(metadata, (item) => item.label === 'Adviser(s)')
      expect(adviserName.value).to.deep.equal(['<NAME>'])
    })
  })

  context('when the source is an interaction with a null adviser', () => {
    it('should return unknown name', () => {
      this.transformed = transformInteractionToListItem()({
        ...mockInteraction,
        dit_participants: [
          {
            adviser: null,
            team: {
              id: 1,
              name: 'The test team',
            },
          }],
      })
      const metadata = this.transformed.meta
      const adviserName = find(metadata, (item) => item.label === 'Adviser(s)')
      expect(adviserName.value).to.deep.equal(['Unknown adviser'])
    })
  })

  context('when the source is an interaction with a null contact name', () => {
    it('should return unknown name', () => {
      this.transformed = transformInteractionToListItem()({
        ...mockInteraction,
        contacts: [{
          id: 'b4919d5d-8cfb-49d1-a3f8-e4eb4b61e306',
          first_name: 'Jackson',
          last_name: 'Whitfield',
          name: null,
        }],
      })
      const metadata = this.transformed.meta
      const contactName = find(metadata, (item) => item.label === 'Contact(s)')
      expect(contactName.value).to.deep.equal(['Unknown contact'])
    })
  })

{'fraction_non_alphanumeric': 0.14722732677548372, 'fraction_numerical': 0.024645984217922388, 'mean_word_length': 1.9797101449275363, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 55, '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': '7251798', 'n_tokens_mistral': 2824, 'n_tokens_neox': 2650, 'n_words': 534}