<commit_before>const config = require('~/config')
const { renderInteractionList, renderInteractionsForEntity } = require('~/src/apps/interactions/controllers/list')

describe('interaction list', () => {
  beforeEach(() => {
    this.error = new Error('error')

    this.req = {
      session: {
        user: {
          id: '1234',
          name: '<NAME>',
          permissions: [],
        },
      },
      query: {
        sortby: 'date:desc',
      },
    }

    this.res = {
      render: sinon.stub(),
      breadcrumb: sinon.stub().returnsThis(),
      locals: {
        userAgent: {
          isIE: false,
        },
      },
    }

    this.next = sinon.stub()

    this.metadataMock = {
      teamOptions: [
        { id: 'te1', name: 'te1', disabled_on: null },
        { id: 'te2', name: 'te2', disabled_on: null },
        { id: 'te', name: 'te3', disabled_on: null },
      ],
      service: [
        { id: 's1', name: 's1', disabled_on: null },
        { id: 's2', name: 's2', disabled_on: null },
        { id: 's3', name: 's3', disabled_on: null },
      ],
      sectorOptions: [
        { id: 's1', name: 's1', disabled_on: null },
        { id: 's2', name: 's2', disabled_on: null },
        { id: 's3', name: 's3', disabled_on: null },
      ],
      adviserOptions: {
        results: [
          { id: 'ad1', name: 'ad1', is_active: true, dit_team: { name: 'ad1' } },
        ],
      },
    }

    nock(config.apiRoot)
      .get('/metadata/service/')
      .reply(200, this.metadataMock.sectorOptions)
      .get('/metadata/team/')
      .reply(200, this.metadataMock.teamOptions)
      .get('/metadata/sector/?level__lte=0')
      .reply(200, this.metadataMock.sectorOptions)
      .get('/adviser/?limit=100000&offset=0')
      .reply(200, this.metadataMock.adviserOptions)
  })

  context('#renderInteractionList', () => {
    beforeEach(async () => {
      await renderInteractionList(this.req, this.res, this.next)
    })

    it('displays the kind filters', () => {
      const options = this.res.render.firstCall.args[1]
      const filterFields = options.filtersFields

      const kindField = filterFields.find(field => field.name === 'kind')
      expect(kindField.options).to.deep.equal([
        { value: 'interaction', label: 'Interaction' },
        { value: 'service_delivery', label: 'Service delivery' },
      ])<commit_msg>Update tests to cover new policy type filter<commit_after>const moment = require('moment')

const config = require('~/config')
const { renderInteractionList, renderInteractionsForEntity } = require('~/src/apps/interactions/controllers/list')

describe('interaction list', () => {
  beforeEach(() => {
    this.error = new Error('error')

    this.req = {
      session: {
        user: {
          id: '1234',
          name: '<NAME>',
          permissions: [],
        },
      },
      query: {
        sortby: 'date:desc',
      },
    }

    this.res = {
      render: sinon.stub(),
      breadcrumb: sinon.stub().returnsThis(),
      locals: {
        userAgent: {
          isIE: false,
        },
      },
    }

    this.next = sinon.stub()

    const yesterday = moment().subtract(1, 'days').toISOString()

    this.metadataMock = {
      teamOptions: [
        { id: 'te1', name: 'te1', disabled_on: null },
        { id: 'te2', name: 'te2', disabled_on: null },
        { id: 'te', name: 'te3', disabled_on: null },
      ],
      service: [
        { id: 's1', name: 's1', disabled_on: null },
        { id: 's2', name: 's2', disabled_on: null },
        { id: 's3', name: 's3', disabled_on: null },
      ],
      sectorOptions: [
        { id: 's1', name: 's1', disabled_on: null },
        { id: 's2', name: 's2', disabled_on: null },
        { id: 's3', name: 's3', disabled_on: null },
      ],
      adviserOptions: {
        results: [
          { id: 'ad1', name: 'ad1', is_active: true, dit_team: { name: 'ad1' } },
        ],
      },
      policyIssueType: [
        { id: '1', name: 'pt1', disabled_on: null },
        { id: '2', name: 'pt2', disabled_on: yesterday },
        { id: '3', name: 'pt3', disabled_on: null },
      ],
    }

    nock(config.apiRoot)
      .get('/metadata/service/')
      .reply(200, this.metadataMock.sectorOptions)
      .get('/metadata/team/')
      .reply(200, this.metadataMock.teamOptions)
      .get('/metadata/sector/?level__lte=0')
      .reply(200, this.metadataMock.sectorOptions)
      .get('/adviser/?limit=100000&offset=0')
      .reply(200, this.metadataMock.adviserOptions)
      .get('/metadata/policy-issue-type/')
      .reply(200, this.metadataMock.policyIssueType)
  })

  context('#renderInteractionList', () => {
    beforeEach(async () => {
      await renderInteractionList(this.req, this.res, this.next)
    })

    it('displays the kind filters', () => {
      const options = this.res.render.firstCall.args[1]
      const filterFields = options.filtersFields

      const kindField = filterFields.find(field => field.name === 'kind')
      expect(kindField.options).to.deep.equal([
        { value: 'interaction', label: 'Interaction' },
        { value: 'service_delivery', label: 'Service delivery' },
      ])
{'fraction_non_alphanumeric': 0.1744433688286544, 'fraction_numerical': 0.01936108422071636, 'mean_word_length': 2.3072983354673497, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '7386757', 'n_tokens_mistral': 1741, 'n_tokens_neox': 1687, 'n_words': 332}