<commit_before>const chaiHTTP = require('chai-http');
const chai = require('chai');
const expect = chai.expect;
chai.use(chaiHTTP);
const request = chai.request;
const mongoose = require('mongoose');
const port = process.env.PORT = 1234;
const server = require(__dirname + '/../lib/_server');
const User = require(__dirname + '/../models/user');
const Plan = require(__dirname + '/../models/plan');
process.env.APP_SECRET = 'secret';

describe('plan routes server', () => {
  before((done) => {
    server.listen(port, 'mongodb://localhost/plan_test_db');
    done();
  });

  before((done) => {
    var user = new User({ username: 'Phil', password: <PASSWORD> });
    user.save((err, data) => {
      if (err) throw err;
      this.user = data;
      this.user.generateToken((err, token) => {
        if (err) throw err;
        this.token = token;
        done();
      });
    });
  });
  after((done) => {
    mongoose.connection.db.dropDatabase(() => {
      mongoose.disconnect(() => {
        server.close(done);
      });
    });
  });

  it('should create a plan', (done) => {
    request('localhost:' + port)
    .post('/api/plan')
    .set('token', this.token)
    .send({ firstName: 'test', lastName: 'test', email: 'test',
    'emergencykit.water': true, 'emergencykit.food': true, 'emergencykit.noaaWeatherRadio': true,
    'emergencykit.flashlight': true, 'emergencykit.extraBatteries': true,
    'emergencykit.firstAidKit': true,
    'emergencykit.whistle': true, 'emergencykit.dustMask': true,
    'emergencykit.sheetingAndDuctTape': true,
    'emergencykit.moistTowelettes': true,
    'emergencykit.garbageBagsAndPlasticTies': true, 'emergencykit.wrenchOrPliers': true,
    'emergencykit.canOpener': true, 'emergencykit.localMaps': true })
    .end((err, res) => {
      expect(err).to.eql(null);
      expect(res.body.firstName).to.eql('test');
      done();
    });
  });

  it('should receive stored plans from database', (done) => {
    request('localhost:' + port)
    .get('/api/plan')
    .set('token', this.token)
    .end((err, res) => {
      expect(err).to.eql(null);
      expect(Array.isArray(res.body)).to.eql(true);
      done();
    });
  });
  describe('how to update or remove plan from database', () => {
    beforeEach((done) => {
      var newPlan = new Plan({
        firstName: 'test', lastName: 'test', email: 'test',
        'emergencykit.water': true, 'emergencykit.food': true,
        'emergencykit.noaaWeatherRadio': true,
        'emergencykit.flashlight': true, 'emergencykit.extraBatteries': true,
        'emergencykit.firstAidKit': true,
        'emergencykit.whistle': true, 'emergencykit.dustMask': true,
        'emergencykit.sheetingAndDuctTape': true,
        'emergencykit.moistTowelettes': true,
        'emergencykit.garbageBagsAndPlasticTies': true, 'emergencykit.wrenchOrPliers': true,
        'emergencykit.canOpener': true, 'emergencykit.localMaps': true }
      );
      newPlan.save((err, data) => {
        if (err) throw err;
        this.plan = data;
        done();
      });
    });

    it('should update existing plan', (done) => {
      request('localhost:' + port)
      .put('/api/plan/' + this.plan._id)
      .set('token', this.token)
      .send({ firstName: 'test123', lastName: 'test123', email: 'newTest',
      'emergencykit.water': true, 'emergencykit.food': true, 'emergencykit.noaaWeatherRadio': true,
      'emergencykit.flashlight': true, 'emergencykit.extraBatteries': true,
      'emergencykit.firstAidKit': true,
      'emergencykit.whistle': true, 'emergencykit.dustMask': true,
      'emergencykit.sheetingAndDuctTape': true,
      'emergencykit.moistTowelettes': true,
      'emergencykit.garbageBagsAndPlasticTies': true, 'emergencykit.wrenchOrPliers': true,
      'emergencykit.canOpener': true, 'emergencykit.localMaps': true })
      .end((err, res) => {
        expect(err).to.eql(null);
        expect(res.body.msg).to.eql('Plan has been updated!');
        done();
      });
    });

    it('should remove plan data from database', (done) => {
      request('localhost:' + port)<commit_msg>router tests fixins<commit_after>const chaiHTTP = require('chai-http');
const chai = require('chai');
const expect = chai.expect;
chai.use(chaiHTTP);
const request = chai.request;
const fs = require('fs');
const mongoose = require('mongoose');
const port = process.env.PORT = 1234;
const server = require(__dirname + '/../lib/_server');
const User = require(__dirname + '/../models/user');
const Plan = require(__dirname + '/../models/plan');
process.env.APP_SECRET = 'secret';

describe('plan routes server', () => {
  before((done) => {
    server.listen(port, 'mongodb://localhost/plan_test_db');
    done();
  });

  before((done) => {
    User.register(new User({ username: 'Rachel' }), '246', (err, user) => {
      if (err) return console.log(err);

      // ***NOTE***
      // user.isAuthenticated = true is currently bypassing the email validation
      // layer.  once the email validation is set up, this assignment and the
      // user.save method call can be removed.
      user.isAuthenticated = true;
      user.save((err, user) => {
        if (err) return console.log(err);
        user.generateToken((err, token) => {
          if (err) return console.log(err);
          this.token = token;
          done();
        });
      });
    });
  });
  after((done) => {
    mongoose.connection.db.dropDatabase(() => {
      mongoose.disconnect(() => {
        server.close(done);
      });
    });
  });

  it('should create a plan', (done) => {
    request('localhost:' + port)
    .post('/api/plan')
    .set('token', this.token)
    .send(JSON.parse(fs.readFileSync(__dirname + '/test_post1.json').toString()))
    .end((err, res) => {
      expect(err).to.eql(null);
      expect(res.body.leader.firstName).to.eql('Firstname');
      done();
    });
  });

  it('should receive stored plans from database', (done) => {
    request('localhost:' + port)
    .get('/api/plan')
    .set('token', this.token)
    .end((err, res) => {
      expect(err).to.eql(null);
      expect(Array.isArray(res.body)).to.eql(true);
      done();
    });
  });
  describe('how to update or remove plan from database', () => {
    beforeEach((done) => {
      var newPlan = new Plan(JSON.parse(fs.readFileSync(__dirname +
        '/test_post1.json').toString()));
      newPlan.save((err, data) => {
        if (err) throw err;
        this.plan = data;
        done();
      });
    });

    it('should update existing plan', (done) => {
      request('localhost:' + port)
      .put('/api/plan/' + this.plan._id)
      .set('token', this.token)
      .send(JSON.parse(fs.readFileSync(__dirname + '/test_post2.json').toString()))
      .end((err, res) => {
        expect(err).to.eql(null);
        expect(res.body.msg).to.eql('Plan has been updated!');
        done();
      });
    });

    it('should remove plan data from database', (done) => {
      request('localhost:' + port)
{'fraction_non_alphanumeric': 0.18210496128477202, 'fraction_numerical': 0.0028677946659019216, 'mean_word_length': 3.0017211703958693, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 41, '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': '3582522', 'n_tokens_mistral': 2338, 'n_tokens_neox': 2266, 'n_words': 449}