<commit_before>import app from '../server/index';
import config from 'config';
import sinon from 'sinon';
import nodemailer from 'nodemailer';
import request from 'supertest-as-promised';
import { expect } from 'chai';
import emailLib from '../server/lib/email';
import * as utils from '../test/utils';
import models from '../server/models';

const application = utils.data('application');
const userData = utils.data('user6');
const groupData = utils.data('group1');

const {
  User,
  Group
} = models;

describe('lib.notifications.test.js', () => {

  let user, group, nm;

  beforeEach(() => utils.resetTestDB());

  beforeEach('create user and group', () => {
    const promises = [User.create(userData), Group.create(groupData)];
    return Promise.all(promises).then(results => {
      user = results[0];
      group = results[1];
      return group.addUserWithRole(user, 'HOST')
    })
  });

  // create a fake nodemailer transport
  beforeEach(done => {
    config.mailgun.user = 'xxxxx';
    config.mailgun.password = 'password';

    nm = nodemailer.createTransport({
          name: 'testsend',
          service: 'Mailgun',
          sendMail (data, callback) {
              callback();
          },
          logger: false
        });

    sinon.stub(nodemailer, 'createTransport', () => {
      return nm;
    });
    done();
  });

  // stub the transport
  beforeEach(done => {
    sinon.stub(nm, 'sendMail', (object, cb) => {
      cb(null, object);
    });
    done();
  });

  afterEach(done => {
    nm.sendMail.restore();
    done();
  })

  afterEach(() => {
    config.mailgun.user = '';
    config.mailgun.password = '';
    nodemailer.createTransport.restore();
  });

  it('sends a new `group.expense.created` email notification', done => {
    let emailAttributes, body;
    const expense = utils.data('expense1');

    const templateData = {
      expense,<commit_msg>eslint<commit_after>import app from '../server/index';
import config from 'config';
import sinon from 'sinon';
import nodemailer from 'nodemailer';
import request from 'supertest-as-promised';
import { expect } from 'chai';
import emailLib from '../server/lib/email';
import * as utils from '../test/utils';
import models from '../server/models';

const application = utils.data('application');
const userData = utils.data('user6');
const groupData = utils.data('group1');

const {
  User,
  Group
} = models;

describe('lib.notifications.test.js', () => {

  let user, group, nm;

  beforeEach(() => utils.resetTestDB());

  beforeEach('create user and group', () => {
    const promises = [User.create(userData), Group.create(groupData)];
    return Promise.all(promises).then(results => {
      user = results[0];
      group = results[1];
      return group.addUserWithRole(user, 'HOST')
    })
  });

  // create a fake nodemailer transport
  beforeEach(done => {
    config.mailgun.user = 'xxxxx';
    config.mailgun.password = 'password';

    nm = nodemailer.createTransport({
          name: 'testsend',
          service: 'Mailgun',
          sendMail (data, callback) {
              callback();
          },
          logger: false
        });

    sinon.stub(nodemailer, 'createTransport', () => {
      return nm;
    });
    done();
  });

  // stub the transport
  beforeEach(done => {
    sinon.stub(nm, 'sendMail', (object, cb) => {
      cb(null, object);
    });
    done();
  });

  afterEach(done => {
    nm.sendMail.restore();
    done();
  })

  afterEach(() => {
    config.mailgun.user = '';
    config.mailgun.password = '';
    nodemailer.createTransport.restore();
  });

  it('sends a new `group.expense.created` email notification', done => {
    let emailAttributes;
    const expense = utils.data('expense1');

    const templateData = {
      expense,
{'fraction_non_alphanumeric': 0.16248348745046234, 'fraction_numerical': 0.002642007926023778, 'mean_word_length': 2.9273858921161824, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '2244783', 'n_tokens_mistral': 1174, 'n_tokens_neox': 1157, 'n_words': 268}