<commit_before>import 'mocha';
import chai from 'chai';
import spies from 'chai-spies';
import mongoose from 'mongoose';
import message from '@test/data/message';
import MessageService from '@/services/MessageService';
import DeviceService from '@/services/DeviceService';
import device from '@test/data/device';
import Utils from '@/utils';
import config from '@test/config';

// Add extensions to chai
chai.use(spies);
const expect = chai.expect;

describe('EscalationLogic.escalate', () => {

  // Instantiate the service
  const messageService = new MessageService();

  before('should establish a database connection.', (done) => {
    // connect to database
    const db = mongoose.connection;
    db.on('error', console.error.bind(console, 'connection error:'));
    db.once('open', done);
    mongoose.connect(config.MONGO_DB_PATH);
  });

  it('should call the escalation logic.', async () => {
    // add test device
    await DeviceService.addDevice(device.platform, device.mail, device.tokens[0]);

    // use spies for push and mail service
    const spyFunctionPush = chai.spy();
    const spyFunctionMail = chai.spy();
    (messageService as any).escalationLogic.pushService.send = spyFunctionPush;
    (messageService as any).escalationLogic.mailService.send = spyFunctionMail;

    await messageService.send(message);

    expect(spyFunctionPush)
      .to.have.been.called();

    const config = Utils.getPlatformConfig(message.platform);

    await new Promise((resolve) => {
      setTimeout(() => {
        expect(spyFunctionMail)
          .to.have.been.called();
        resolve();
      }, config.mail.defaults.delay + 1);
     });
  });

  after('should drop database and close connection', (done) => {
    mongoose.connection.db.dropDatabase(() => {
      mongoose.connection.close(done);
    });
  });

});
<commit_msg>Use TestUtils timeout<commit_after>import 'mocha';
import chai from 'chai';
import spies from 'chai-spies';
import mongoose from 'mongoose';
import message from '@test/data/message';
import MessageService from '@/services/MessageService';
import DeviceService from '@/services/DeviceService';
import device from '@test/data/device';
import Utils from '@/utils';
import config from '@test/config';
import TestUtils from '@test/test-utils';

// Add extensions to chai
chai.use(spies);
const expect = chai.expect;

describe('EscalationLogic.escalate', () => {

  // Instantiate the service
  const messageService = new MessageService();

  before('should establish a database connection.', (done) => {
    // connect to database
    const db = mongoose.connection;
    db.on('error', console.error.bind(console, 'connection error:'));
    db.once('open', done);
    mongoose.connect(config.MONGO_DB_PATH);
  });

  it('should call the escalation logic.', async () => {
    // add test device
    await DeviceService.addDevice(device.platform, device.mail, device.tokens[0]);

    // use spies for push and mail service
    const spyFunctionPush = chai.spy();
    const spyFunctionMail = chai.spy();
    (messageService as any).escalationLogic.pushService.send = spyFunctionPush;
    (messageService as any).escalationLogic.mailService.send = spyFunctionMail;

    await messageService.send(message);

    expect(spyFunctionPush)
      .to.have.been.called();

    const config = Utils.getPlatformConfig(message.platform);

    await TestUtils.timeout(config.mail.defaults.delay + 10);

    expect(spyFunctionMail)
      .to.have.been.called();
  });

  after('should drop database and close connection', (done) => {
    mongoose.connection.db.dropDatabase(() => {
      mongoose.connection.close(done);
    });
  });

});

{'fraction_non_alphanumeric': 0.13751705320600272, 'fraction_numerical': 0.001364256480218281, 'mean_word_length': 3.9274193548387095, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '5092529', 'n_tokens_mistral': 1094, 'n_tokens_neox': 1074, 'n_words': 266}