<commit_before>const buildMiddlewareParameters = require('~/test/unit/helpers/middleware-parameters-builder.js')

const { renderDetails } = require('~/src/apps/companies/controllers/details')

const companiesHouseCompany = require('~/test/unit/data/companies/companies-house-company.json')
const minimalCompany = require('~/test/unit/data/companies/minimal-company.json')
const config = require('~/config')

describe('Companies details controller', () => {
  describe('#renderDetails', () => {
    const commonTests = (template) => {
      it('should render the correct template', () => {
        const templateName = this.middlewareParameters.resMock.render.firstCall.args[0]
        expect(templateName).to.equal(template)
      })

      it('should include company details', () => {
        const options = this.middlewareParameters.resMock.render.firstCall.args[1]
        expect(options.companyDetails).to.not.be.null
      })

      it('should include account management details', () => {
        const options = this.middlewareParameters.resMock.render.firstCall.args[1]
        expect(options.accountManagementDetails).to.not.be.null
      })

      it('should include one list information', () => {
        const options = this.middlewareParameters.resMock.render.firstCall.args[1]
        expect(options.accountManagementDetails).to.not.be.null
      })

      it('should include a link to the One List support email', () => {
        const options = this.middlewareParameters.resMock.render.firstCall.args[1]
        expect(options.oneListEmail).to.equal(config.oneList.email)
      })
    }

    context('when the company contains Companies House data', () => {
      beforeEach(async () => {
        this.middlewareParameters = buildMiddlewareParameters({
          company: companiesHouseCompany,
        })

        await renderDetails(
          this.middlewareParameters.reqMock,
          this.middlewareParameters.resMock,
          this.middlewareParameters.nextSpy
        )
      })

      commonTests('companies/views/_deprecated/details')

      it('should include companies house details', () => {
        const options = this.middlewareParameters.resMock.render.firstCall.args[1]
        expect(options.chDetails).to.not.be.null
      })
    })

    context('when the company has no companies house data', () => {
      beforeEach(async () => {
        this.middlewareParameters = buildMiddlewareParameters({
          company: minimalCompany,
        })

        await renderDetails(
          this.middlewareParameters.reqMock,
          this.middlewareParameters.resMock,
          this.middlewareParameters.nextSpy
        )
      })

      commonTests('companies/views/_deprecated/details')

      it('should not include Companies House details', () => {
        const options = this.middlewareParameters.resMock.render.firstCall.args[1]
        expect(options.chDetails).to.be.null
      })
    })
  })<commit_msg>Assert breadcrumb is added<commit_after>const buildMiddlewareParameters = require('~/test/unit/helpers/middleware-parameters-builder.js')

const { renderDetails } = require('~/src/apps/companies/controllers/details')

const companiesHouseCompany = require('~/test/unit/data/companies/companies-house-company.json')
const minimalCompany = require('~/test/unit/data/companies/minimal-company.json')
const dnbCompany = require('~/test/unit/data/companies/dnb-company.json')
const config = require('~/config')

describe('Companies details controller', () => {
  describe('#renderDetails', () => {
    const commonTests = (expectedBreadcrumb, expectedTemplate) => {
      it('should add a breadcrumb', () => {
        const breadcrumbSpy = this.middlewareParameters.resMock.breadcrumb

        expect(breadcrumbSpy).to.be.calledWith(expectedBreadcrumb.text)
        expect(breadcrumbSpy).to.have.been.calledOnce
      })

      it('should render the correct template', () => {
        const templateName = this.middlewareParameters.resMock.render.firstCall.args[0]
        expect(templateName).to.equal(expectedTemplate)
      })

      it('should include company details', () => {
        const options = this.middlewareParameters.resMock.render.firstCall.args[1]
        expect(options.companyDetails).to.not.be.null
      })

      it('should include account management details', () => {
        const options = this.middlewareParameters.resMock.render.firstCall.args[1]
        expect(options.accountManagementDetails).to.not.be.null
      })

      it('should include one list information', () => {
        const options = this.middlewareParameters.resMock.render.firstCall.args[1]
        expect(options.accountManagementDetails).to.not.be.null
      })

      it('should include a link to the One List support email', () => {
        const options = this.middlewareParameters.resMock.render.firstCall.args[1]
        expect(options.oneListEmail).to.equal(config.oneList.email)
      })
    }

    context('when the company contains Companies House data', () => {
      beforeEach(async () => {
        this.middlewareParameters = buildMiddlewareParameters({
          company: companiesHouseCompany,
        })

        await renderDetails(
          this.middlewareParameters.reqMock,
          this.middlewareParameters.resMock,
          this.middlewareParameters.nextSpy
        )
      })

      commonTests({ text: 'SAMSUNG BIOEPIS UK LIMITED' }, 'companies/views/_deprecated/details')

      it('should include companies house details', () => {
        const options = this.middlewareParameters.resMock.render.firstCall.args[1]
        expect(options.chDetails).to.not.be.null
      })
    })

    context('when the company has no companies house data', () => {
      beforeEach(async () => {
        this.middlewareParameters = buildMiddlewareParameters({
          company: minimalCompany,
        })

        await renderDetails(
          this.middlewareParameters.reqMock,
          this.middlewareParameters.resMock,
          this.middlewareParameters.nextSpy
        )
      })

      commonTests({ text: 'SAMSUNG BIOEPIS UK LIMITED' }, 'companies/views/_deprecated/details')

      it('should not include Companies House details', () => {
        const options = this.middlewareParameters.resMock.render.firstCall.args[1]
        expect(options.chDetails).to.be.null
      })
    })
  })
{'fraction_non_alphanumeric': 0.1223429381199811, 'fraction_numerical': 0.002204377263423083, 'mean_word_length': 3.069186418962204, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 32, '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': '1456812', 'n_tokens_mistral': 1743, 'n_tokens_neox': 1695, 'n_words': 282}