Last active
March 28, 2016 10:08
-
-
Save dryruner/2df202c06030c2cedd86 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mongoose = require('mongoose'); | |
var chai = require('chai'); | |
// http://chaijs.com/guide/styles/#differences | |
var should = chai.should(); | |
var assert = chai.assert; | |
var expect = chai.expect; | |
var dbURI = "mongodb://localhost:27017/conFusion"; | |
var Dishes = require('./dishes'); | |
var Leaders = require('./leadership'); | |
var Promotions = require('./promotions'); | |
describe('Dishes', function() { | |
before(function(done) { | |
if (mongoose.connection.db) return done(); | |
mongoose.connect(dbURI, function(){ | |
// Clear underlying collections to prevent 'duplicate key' error. | |
Dishes.remove({}, done); | |
}); | |
}); | |
it('Can create a dish', function(done) { | |
var newDish = Dishes({ | |
name: 'Uthapizza', | |
image: "images/uthapizza.png", | |
category: "mains", | |
label: "Hot", | |
price: "4.99", | |
description: 'Test', | |
comments: [{ | |
rating: 3, | |
comment: 'This is insane', | |
author: 'Matt Daemon' | |
}] | |
}); | |
newDish.save(function(err, dish) { | |
if (err) { | |
return done(err); | |
} | |
Dishes.find({}, function(err, docs) { | |
if (err) { | |
return done(err); | |
} | |
docs.length.should.equal(1); | |
done(); | |
}); | |
}); | |
}); | |
it('Can create 2nd dish', function(done) { | |
var second_dish = Dishes({ | |
name: 'test2', | |
image: "images/test2.png", | |
category: "sdes", | |
price: "$ 14.99", | |
description: 'Test 2' | |
}); | |
second_dish.save(function(err, dish) { | |
if (err) { | |
return done(err); | |
} | |
var id = dish._id; | |
Dishes.findById(id, function(err, found) { | |
if (err) { | |
return done(err); | |
} | |
assert.isNotNull(found, "Found dish shouldn't be null!"); | |
found.label.should.equal(''); | |
found.name.should.equal("test2"); | |
done(); | |
}); | |
}); | |
}); | |
}); | |
describe('Leaders', function() { | |
before(function(done) { | |
if (mongoose.connection.db) return done(); | |
mongoose.connect(dbURI, function(){ | |
// Clear underlying collections to prevent 'duplicate key' error. | |
Leaders.remove({}, done); | |
}); | |
}); | |
it('this is a placeholder', function(){ | |
assert.equal(3, 3); | |
}) | |
}); | |
describe('Promotions', function() { | |
before(function(done) { | |
if (mongoose.connection.db) return done(); | |
mongoose.connect(dbURI, function(){ | |
// Clear underlying collections to prevent 'duplicate key' error. | |
Promotions.remove({}, done); | |
}); | |
}); | |
it('this is a placeholder', function(){ | |
assert.equal(3, 3); | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment