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

describe('Collection middleware', () => {
  context('#collectionExport', () => {
    beforeEach(() => {
      const streamToFileStub = sinon.spy()
      const { exportCollection } = proxyquire('~/src/modules/search/middleware/collection', {
        '../../../lib/stream-to-file': {
          streamToFile: streamToFileStub,
        },
      })
      this.exportCollection = exportCollection
      this.streamToFileStub = streamToFileStub

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

      this.resMock = sinon.spy()
      this.nextSpy = sinon.spy()
    })

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

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

      it('should pass the response to the file streamer', () => {
        expect(this.streamToFileStub).to.be.calledOnce
        expect(this.streamToFileStub.args[0][1]).to.equal(this.resMock)
      })

      it('should not return an error to the next handler', () => {
        expect(this.nextSpy).to.not.be.called
      })
    })
  })<commit_msg>fixup! remove stream-to-file and unused params<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).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
      })
    })
  })
{'fraction_non_alphanumeric': 0.16025401568920433, 'fraction_numerical': 0.006723944714232349, 'mean_word_length': 2.176749703440095, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 22, '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': '1216933', 'n_tokens_mistral': 823, 'n_tokens_neox': 801, 'n_words': 138}