'use strict';

var utils = require('./init');
var expect = require('chai').expect;
var async = require('async');
var Source = require('../../models/source');

describe('Source attributes', function() {
  it('should return validation errors', function(done) {
    // This shouldn't get saved because it should error
    Source.create({ url: 'hey' }, function(err) {
      expect(err).to.have.keys(['_message', 'errors']);
      expect(err.errors).to.have.keys(['nickname', 'url']);
      expect(err.errors.url.message).to.contain('Validator failed for path `url` with value `hey`');
      done();
    });
  });

  it('should return total number of errors', function(done) {
    // These are not saved to the database
    var one = new Source({ nickname: 'one', type: 'dummy' });
    var two = new Source({ nickname: 'two', type: 'dummy' });
    async.series([
      one.logEvent.bind(one, 'error', 'Error 1'),
      two.logEvent.bind(two, 'warning', 'Warning 1'),
      two.logEvent.bind(two, 'warning', 'Warning 2')
    ],
    function(err) {
      if (err) return done(err);
      Source.countAllErrors(function(err, count) {
        if (err) return done(err);
        expect(count).to.equal(3);
        done();
      });
    });
  });

  after(Source.remove.bind(Source, {}));
  after(utils.expectModelsEmpty);
});

@@ -1239,16 +1239,50 @@
   after(
+function(done) %7B%0A    var remove = 
 Source.r
@@ -1303,16 +1303,39 @@
 rce, %7B%7D)
+;%0A    remove(done);%0A  %7D
 );%0A  aft

call Source.remove from within a callback-only function to meet Mocha callback requirements