|
| 1 | +var expect = require('chai').expect; |
| 2 | +var sinon = require('sinon'); |
| 3 | +var Promise = require('promise-polyfill'); |
| 4 | + |
| 5 | +var Meme = require('../src/Meme'); |
| 6 | + |
| 7 | +describe('meme', function() { |
| 8 | + it('should be invalid if name is empty', function(done) { |
| 9 | + var m = new Meme(); |
| 10 | + |
| 11 | + m.validate(function(err) { |
| 12 | + expect(err.errors.name).to.exist; |
| 13 | + done(); |
| 14 | + }); |
| 15 | + }); |
| 16 | + |
| 17 | + it('should have validation error for repost if not dank', function(done) { |
| 18 | + var m = new Meme({ repost: true }); |
| 19 | + |
| 20 | + m.validate(function(err) { |
| 21 | + expect(err.errors.repost).to.exist; |
| 22 | + done(); |
| 23 | + }); |
| 24 | + }); |
| 25 | + |
| 26 | + it('should be valid repost when dank', function(done) { |
| 27 | + var m = new Meme({ repost: true, dank: true }); |
| 28 | + |
| 29 | + m.validate(function(err) { |
| 30 | + expect(err.errors.repost).to.not.exist; |
| 31 | + done(); |
| 32 | + }); |
| 33 | + }); |
| 34 | + |
| 35 | + it('should check for reposts with same name', sinon.test(function() { |
| 36 | + this.stub(Meme, 'findOne'); |
| 37 | + var expectedName = 'This name should be used in the check'; |
| 38 | + var m = new Meme({ name: expectedName }); |
| 39 | + |
| 40 | + m.checkForReposts(function() { }); |
| 41 | + |
| 42 | + sinon.assert.calledWith(Meme.findOne, { |
| 43 | + name: expectedName, |
| 44 | + repost: true |
| 45 | + }); |
| 46 | + })); |
| 47 | + |
| 48 | + it('should call back with true when repost exists', sinon.test(function(done) { |
| 49 | + var repostObject = { name: 'foo' }; |
| 50 | + this.stub(Meme, 'findOne').yields(null, repostObject); |
| 51 | + var m = new Meme({ name: 'some name' }); |
| 52 | + |
| 53 | + m.checkForReposts(function(hasReposts) { |
| 54 | + expect(hasReposts).to.be.true; |
| 55 | + done(); |
| 56 | + }); |
| 57 | + })); |
| 58 | +}); |
0 commit comments