<commit_before>var dotenv = require('dotenv');
dotenv.load();

var chai = require('chai');
var should = chai.should();
var db = require('../models');
var sequelize = db.sequelize;

describe('Opportunity Model', function() {

  it('should create a new opportunity without optional fields', function(done) {
    var body = { _csrf: 'undefined', _doc_id: '', title: 'Test opp3', purpose: 'anything', 'purpose-other': '', eligibleBusinessLocation: 'anywhere_in_pr', 'eligibleBusinessLocation-other': '', paperworkRequired: 'asdfasd', applicationCost: '23', applicationDeadline: '2014-12-31', avgApplicationTime: '90 days', benefitType: 'incentive', 'benefitType-other': '', benefitDescription: 'Una descripcion', agencyName: '<NAME>', agencyContactName: 'Un contacto', agencyContactEmail: 'unemail', agencyContactPhone: '7875663317', minimumYearsInBusiness: '0', eligibleEntityTypes: 'non_profit', currentEmployeesRequired: '26_50', annualRevenue: '0_99999', eligibleIndustries: [ 'any', '' ], gender: 'any', age: '0', additionalGeneralInformation: '', moneyInvested: '' }
    var Opportunity = sequelize.model('opportunity');
    var instance = Opportunity.buildFromAdminForm(body);
    instance.validate().
    success(function(err) {
      if (err) {
        done(err);
      }
      instance.save().success(function(){
        done();
      })
      .error(function(err) {
        done(err);
      });
    });
  });

  it('should create a new opportunity with optional fields', function(done) {
    // purpose other is filled out, additionalGeneralInformation is filled out
    var body = { _csrf: 'undefined', _doc_id: '', title: 'Test opp3', purpose: 'Other', 'purpose-other': 'A different purpose', eligibleBusinessLocation: 'anywhere_in_pr', 'eligibleBusinessLocation-other': '', paperworkRequired: 'asdfasd', applicationCost: '23', applicationDeadline: '2014-12-31', avgApplicationTime: '90 days', benefitType: 'incentive', 'benefitType-other': '', benefitDescription: 'Una descripcion', agencyName: '<NAME>', agencyContactName: '<NAME>', agencyContactEmail: 'unemail', agencyContactPhone: '7875663317', minimumYearsInBusiness: '0', eligibleEntityTypes: 'non_profit', currentEmployeesRequired: '26_50', annualRevenue: '0_99999', eligibleIndustries: [ 'any', '' ], gender: 'any', age: '0', additionalGeneralInformation: 'Some other general information', moneyInvested: '' }
    var Opportunity = sequelize.model('opportunity');
    var instance = Opportunity.buildFromAdminForm(body);
    instance.validate().
    success(function(err) {
      if (err) {
        done(err);
      }
      instance.save().success(function(){
        done();
      })
      .error(function(err) {
        done(err);
      });
    });
  });

  it('should throw an error if a required field is missing', function(done) {
    // applicationCost is missing
    var body = { _csrf: 'undefined', _doc_id: '', title: 'Test opp3', purpose: 'Other', 'purpose-other': 'A different purpose', eligibleBusinessLocation: 'anywhere_in_pr', 'eligibleBusinessLocation-other': '', paperworkRequired: 'asdfasd', applicationCost: '', applicationDeadline: '2014-12-31', avgApplicationTime: '90 days', benefitType: 'incentive', 'benefitType-other': '', benefitDescription: 'Una descripcion', agencyName: '<NAME>', agencyContactName: 'Un contacto', agencyContactEmail: 'unemail', agencyContactPhone: '7875663317', minimumYearsInBusiness: '0', eligibleEntityTypes: 'non_profit', currentEmployeesRequired: '26_50', annualRevenue: '0_99999', eligibleIndustries: [ 'any', '' ], gender: 'any', age: '0', additionalGeneralInformation: 'Some other general information', moneyInvested: '' }
    var Opportunity = sequelize.model('opportunity');
    var instance = Opportunity.buildFromAdminForm(body);
    instance.validate().
    success(function(err) {
      if (err) {
        should.exist(err);
        done();
      }
    }); 
  });

  it('should correctly parse and save "other" text fields', function(done) {
    // purpose other is filled out, additionalGeneralInformation is filled out
    var body = { _csrf: 'undefined', _doc_id: '', title: 'Test opp3', purpose: 'other', 'purpose-other': 'A different purpose', eligibleBusinessLocation: 'anywhere_in_pr', 'eligibleBusinessLocation-other': '', paperworkRequired: 'asdfasd', applicationCost: '23', applicationDeadline: '2014-12-31', avgApplicationTime: '90 days', benefitType: 'incentive', 'benefitType-other': '', benefitDescription: 'Una descripcion', agencyName: '<NAME>', agencyContactName: 'Un contacto', agencyContactEmail: 'unemail', agencyContactPhone: '7875663317', minimumYearsInBusiness: '0', eligibleEntityTypes: 'non_profit', currentEmployeesRequired: '26_50', annualRevenue: '0_99999', eligibleIndustries: [ 'any', ], gender: 'any', age: '0', additionalGeneralInformation: 'Some other general information', moneyInvested: '' }
    var Opportunity = sequelize.model('opportunity');
    var instance = Opportunity.buildFromAdminForm(body);
    instance.validate().
    success(function(err) {
      if (err) {
        done(err);
      }
      instance.save().success(function(){
        Opportunity.find({where: {title: 'Test opp3'} }).success(function(op) {
          op.purpose.should.equal('_a_different_purpose');
          done();
        });
      })
      .error(function(err) {
        done(err);
      });
    });
  });

  it('should correctly save "other" checkbox fields', function(done) {
    // purpose other is filled out, additionalGeneralInformation is filled out
    var body = { _csrf: 'undefined', _doc_id: '', title: 'Test opp3', purpose: 'other', 'purpose-other': 'A different purpose', eligibleBusinessLocation: 'anywhere_in_pr', 'eligibleBusinessLocation-other': '', paperworkRequired: 'asdfasd', applicationCost: '23', applicationDeadline: '2014-12-31', avgApplicationTime: '90 days', benefitType: 'incentive', 'benefitType-other': '', benefitDescription: 'Una descripcion', agencyName: '<NAME>', agencyContactName: 'Un contacto', agencyContactEmail: 'unemail', agencyContactPhone: '7875663317', minimumYearsInBusiness: '0', eligibleEntityTypes: 'non_profit', currentEmployeesRequired: '26_50', annualRevenue: '0_99999', eligibleIndustries: [ 'any', 'other', 'Otro Distinto' ], gender: 'any', age: '0', additionalGeneralInformation: 'Some other general information', moneyInvested: '' }
    var Opportunity = sequelize.model('opportunity');
    var instance = Opportunity.buildFromAdminForm(body);
    instance.validate().
    success(function(err) {
      if (err) {
        done(err);
      }
      instance.save().success(function(){
        Opportunity.find({where: {title: 'Test opp3'} }).success(function(op) {<commit_msg>Adding beginnings of mock<commit_after>
var dotenv = require('dotenv');
dotenv.load();

var chai = require('chai');
var should = chai.should();
var db = require('../models');
var sequelize = db.sequelize;
var oppMock = require('./mocks/opportunity.js');

describe('Opportunity Model', function() {

  it('should create a new opportunity without optional fields', function(done) {
    var mock = oppMock({
    });
    var Opportunity = sequelize.model('opportunity');
    var instance = Opportunity.buildFromAdminForm(body);
    instance.validate().
    success(function(err) {
      if (err) {
        done(err);
      }
      instance.save().success(function(){
        done();
      })
      .error(function(err) {
        done(err);
      });
    });
  });

  it('should create a new opportunity with optional fields', function(done) {
    // purpose other is filled out, additionalGeneralInformation is filled out
    var body = { _csrf: 'undefined', _doc_id: '', title: 'Test opp3', purpose: 'Other', 'purpose-other': 'A different purpose', eligibleBusinessLocation: 'anywhere_in_pr', 'eligibleBusinessLocation-other': '', paperworkRequired: 'asdfasd', applicationCost: '23', applicationDeadline: '2014-12-31', avgApplicationTime: '90 days', benefitType: 'incentive', 'benefitType-other': '', benefitDescription: 'Una descripcion', agencyName: '<NAME>', agencyContactName: 'Un contacto', agencyContactEmail: 'unemail', agencyContactPhone: '7875663317', minimumYearsInBusiness: '0', eligibleEntityTypes: 'non_profit', currentEmployeesRequired: '26_50', annualRevenue: '0_99999', eligibleIndustries: [ 'any', '' ], gender: 'any', age: '0', additionalGeneralInformation: 'Some other general information', moneyInvested: '' }
    var Opportunity = sequelize.model('opportunity');
    var instance = Opportunity.buildFromAdminForm(body);
    instance.validate().
    success(function(err) {
      if (err) {
        done(err);
      }
      instance.save().success(function(){
        done();
      })
      .error(function(err) {
        done(err);
      });
    });
  });

  it('should throw an error if a required field is missing', function(done) {
    // applicationCost is missing
    var body = { _csrf: 'undefined', _doc_id: '', title: 'Test opp3', purpose: 'Other', 'purpose-other': 'A different purpose', eligibleBusinessLocation: 'anywhere_in_pr', 'eligibleBusinessLocation-other': '', paperworkRequired: 'asdfasd', applicationCost: '', applicationDeadline: '2014-12-31', avgApplicationTime: '90 days', benefitType: 'incentive', 'benefitType-other': '', benefitDescription: 'Una descripcion', agencyName: '<NAME>', agencyContactName: '<NAME>', agencyContactEmail: 'unemail', agencyContactPhone: '7875663317', minimumYearsInBusiness: '0', eligibleEntityTypes: 'non_profit', currentEmployeesRequired: '26_50', annualRevenue: '0_99999', eligibleIndustries: [ 'any', '' ], gender: 'any', age: '0', additionalGeneralInformation: 'Some other general information', moneyInvested: '' }
    var Opportunity = sequelize.model('opportunity');
    var instance = Opportunity.buildFromAdminForm(body);
    instance.validate().
    success(function(err) {
      if (err) {
        should.exist(err);
        done();
      }
    });
  });

  it('should correctly parse and save "other" text fields', function(done) {
    // purpose other is filled out, additionalGeneralInformation is filled out
    var body = { _csrf: 'undefined', _doc_id: '', title: 'Test opp3', purpose: 'other', 'purpose-other': 'A different purpose', eligibleBusinessLocation: 'anywhere_in_pr', 'eligibleBusinessLocation-other': '', paperworkRequired: 'asdfasd', applicationCost: '23', applicationDeadline: '2014-12-31', avgApplicationTime: '90 days', benefitType: 'incentive', 'benefitType-other': '', benefitDescription: 'Una descripcion', agencyName: '<NAME>', agencyContactName: '<NAME>', agencyContactEmail: 'unemail', agencyContactPhone: '7875663318', minimumYearsInBusiness: '0', eligibleEntityTypes: 'non_profit', currentEmployeesRequired: '26_50', annualRevenue: '0_99999', eligibleIndustries: [ 'any', ], gender: 'any', age: '0', additionalGeneralInformation: 'Some other general information', moneyInvested: '' }
    var Opportunity = sequelize.model('opportunity');
    var instance = Opportunity.buildFromAdminForm(body);
    instance.validate().
    success(function(err) {
      if (err) {
        done(err);
      }
      instance.save().success(function(){
        Opportunity.find({where: {title: 'Test opp3'} }).success(function(op) {
          op.purpose.should.equal('_a_different_purpose');
          done();
        });
      })
      .error(function(err) {
        done(err);
      });
    });
  });

  it('should correctly save "other" checkbox fields', function(done) {
    // purpose other is filled out, additionalGeneralInformation is filled out
    var body = { _csrf: 'undefined', _doc_id: '', title: 'Test opp3', purpose: 'other', 'purpose-other': 'A different purpose', eligibleBusinessLocation: 'anywhere_in_pr', 'eligibleBusinessLocation-other': '', paperworkRequired: 'asdfasd', applicationCost: '23', applicationDeadline: '2014-12-31', avgApplicationTime: '90 days', benefitType: 'incentive', 'benefitType-other': '', benefitDescription: 'Una descripcion', agencyName: 'Un<NAME>', agencyContactName: 'Un contacto', agencyContactEmail: 'unemail', agencyContactPhone: '7875663317', minimumYearsInBusiness: '0', eligibleEntityTypes: 'non_profit', currentEmployeesRequired: '26_50', annualRevenue: '0_99999', eligibleIndustries: [ 'any', 'other', 'Otro Distinto' ], gender: 'any', age: '0', additionalGeneralInformation: 'Some other general information', moneyInvested: '' }
    var Opportunity = sequelize.model('opportunity');
    var instance = Opportunity.buildFromAdminForm(body);
    instance.validate().
    success(function(err) {
      if (err) {
        done(err);
      }
      instance.save().success(function(){
        Opportunity.find({where: {title: 'Test opp3'} }).success(function(op) {
{'fraction_non_alphanumeric': 0.15247555976032798, 'fraction_numerical': 0.024834437086092714, 'mean_word_length': 4.963798777621062, 'pattern_counts': {'":': 0, '<': 15, '<?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': '1947226', 'n_tokens_mistral': 3908, 'n_tokens_neox': 3574, 'n_words': 901}