<commit_before>const config = require('~/config')

describe('Collection middleware', () => {
  context('#collectionExport', () => {
    beforeEach(() => {
      const { exportCollection } = require('~/src/modules/search/middleware/collection')
      this.exportCollection = exportCollection

      this.reqMock = {
        session: {
          token: '1234',
        },
      }

      this.resMock = {
        on: sinon.spy(),
        // these are required otherwise request doesn't see the mock as a stream
        end: () => {},
        emit: () => {},
        removeListener: () => {},
      }

      this.nextSpy = sinon.spy()
    })

    describe('#exportCollection', () => {
      beforeEach(async () => {
        nock(config.apiRoot)
          .post(`/v3/search/entity/export`)
          .reply(200)

        this.reqMock.query = {
          sortby: 'name:asc',
        }
        await this.exportCollection('entity')(this.reqMock, this.resMock, this.nextSpy).catch(e => { throw e })
      })

      it('should pipe the request to response as a stream', () => {
        expect(this.resMock.on).to.be.called
      })

      it('should not return an error to the next handler', () => {
        expect(this.nextSpy).to.not.be.called<commit_msg>Remove unnecessary catch statement<commit_after>const config = require('~/config')

describe('Collection middleware', () => {
  context('#collectionExport', () => {
    beforeEach(() => {
      const { exportCollection } = require('~/src/modules/search/middleware/collection')
      this.exportCollection = exportCollection

      this.reqMock = {
        session: {
          token: '1234',
        },
      }

      this.resMock = {
        on: sinon.spy(),
        // these are required otherwise request doesn't see the mock as a stream
        end: () => {},
        emit: () => {},
        removeListener: () => {},
      }

      this.nextSpy = sinon.spy()
    })

    describe('#exportCollection', () => {
      beforeEach(async () => {
        nock(config.apiRoot)
          .post(`/v3/search/entity/export`)
          .reply(200)

        this.reqMock.query = {
          sortby: 'name:asc',
        }
        await this.exportCollection('entity')(this.reqMock, this.resMock, this.nextSpy)
      })

      it('should pipe the request to response as a stream', () => {
        expect(this.resMock.on).to.be.called
      })

      it('should not return an error to the next handler', () => {
        expect(this.nextSpy).to.not.be.called
{'fraction_non_alphanumeric': 0.15844364219815482, 'fraction_numerical': 0.006417970316887284, 'mean_word_length': 2.141057934508816, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 24, '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': '6986136', 'n_tokens_mistral': 746, 'n_tokens_neox': 715, 'n_words': 140}