it('Statement end to end', async () => {
    const statementId = '561a679c0c5d017e4004714f';
    const organisationId = '561a679c0c5d017e4004715a';

    await new Promise((resolve) => {
      async.parallel({
        statementForwarding: insertDone => StatementForwarding.create({
          _id: '59438cabedcedb70146337eb',
          lrs_id: '560a679c0c5d017e4004714f',
          organisation: organisationId,
          active: true,
          configuration: {
            protocol: 'http',
            url: 'localhost:3101/',
            method: 'POST',
            authType: 'basic auth',
            basicUsername: 'theBasicUsername',
            basicPassword: 'theBasicPassword'
          }
        }, insertDone),
        statement: insertDone => Statement.create({
          active: true,
          _id: statementId,
          organisation: organisationId,
          lrs_id: '560a679c0c5d017e4004714f',
          statement: {
            test: 'test'
          },
          processingQueues: [],
          completedQueues: [ // We're only interested in STATEMENT_FORWARDING_REQUEST_QUEUE
            'STATEMENT_PERSON_QUEUE',
            'STATEMENT_QUERYBUILDERCACHE_QUEUE'
          ]
        }, insertDone)
      }, resolve);
    });

    await purgeQueues();

    const mock = new AxiosMockAdapter(axios);
    mock.onPost('http://localhost:3101', { test: 'test' }, {
      authorization: 'Basic dGhlQmFzaWNVc2VybmFtZTp0aGVCYXNpY1Bhc3N3b3Jk'
    }).reply(200, {
      _id: '1',
      _rev: '1',
      success: true
    });

    const statementWorkerDonePromise = new Promise((resolve) => {
      const statementHandlerProccessed = (message) => {
        expect(JSON.parse(message.Body).statementId).to.equal(statementId);
        resolve();
      };

      statementWorker({
        statementHandlerProccessed
      });
    });

    await new Promise(resolve =>
      statementForwardingHandler({ statementId }, () => {
        resolve();
      })
    );

    /*
    We want to wait for message to be propagated back through the
    statement queue before we test request has been called
    and before we clean up the db. Otherwise, processing
    of the queues will fail and leave messages in it.
    */
    await statementWorkerDonePromise;

    expect(mock.history.post.length).to.equal(1);

    await unsubscribeAll();

    await Promise.all([
      StatementForwarding.deleteMany({}),
      Statement.deleteMany({})
    ]);
  })
 await new Promise(resolve =>
   Statement.deleteMany({}, () => resolve())
 afterEach(async () => {
   await Statement.deleteMany({});
   await StatementForwarding.deleteMany({});
 });