mirror of
https://github.com/fergalmoran/roboto-promoto.git
synced 2025-12-22 01:30:36 +00:00
Fixed search test in promotion
This commit is contained in:
@@ -12,11 +12,5 @@ var PromotionSchema = new Schema({
|
||||
|
||||
/* Indexes */
|
||||
PromotionSchema.index({title: 1, user: 1}, {unique: true});
|
||||
var _model = mongoose.model('Promotion', PromotionSchema);
|
||||
|
||||
/* Operations */
|
||||
PromotionSchema.statics.findByTitle = function(title, cb){
|
||||
console.log("findByTitle: " + title);
|
||||
_model.findOne({title: title}, cb);
|
||||
};
|
||||
|
||||
mongoose.model('Promotion', PromotionSchema);
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
var should = require('should'),
|
||||
mongoose = require('mongoose'),
|
||||
Promotion = mongoose.model('Promotion'),
|
||||
User = mongoose.model('User');
|
||||
mongoose = require('mongoose'),
|
||||
Promotion = mongoose.model('Promotion'),
|
||||
User = mongoose.model('User');
|
||||
|
||||
var promotion, promotion2;
|
||||
var user;
|
||||
|
||||
describe('Promotion Model', function() {
|
||||
before(function(done) {
|
||||
describe('Promotion Model', function () {
|
||||
before(function (done) {
|
||||
user = new User({
|
||||
provider: 'local',
|
||||
name: 'Fake User',
|
||||
@@ -30,53 +30,54 @@ describe('Promotion Model', function() {
|
||||
done();
|
||||
});
|
||||
|
||||
afterEach(function(done) {
|
||||
afterEach(function (done) {
|
||||
//going to leave the data intact post test
|
||||
//as it is removed in before()
|
||||
//Promotion.remove().exec();
|
||||
done();
|
||||
});
|
||||
|
||||
it('should begin with no promotions', function(done) {
|
||||
Promotion.find({}, function(err, promotions) {
|
||||
it('should begin with no promotions', function (done) {
|
||||
Promotion.find({}, function (err, promotions) {
|
||||
promotions.should.have.length(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
describe('Save methods', function(){
|
||||
it('should be able to save', function(done){
|
||||
promotion.save(function(err){
|
||||
describe('Save methods', function () {
|
||||
it('should be able to save', function (done) {
|
||||
promotion.save(function (err) {
|
||||
should.not.exist(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('should fail when saving without a user', function(done) {
|
||||
it('should fail when saving without a user', function (done) {
|
||||
promotion.user = '';
|
||||
promotion.save(function(err) {
|
||||
promotion.save(function (err) {
|
||||
should.exist(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('should fail when saving without a title', function(done) {
|
||||
it('should fail when saving without a title', function (done) {
|
||||
promotion.title = '';
|
||||
promotion.save(function(err) {
|
||||
promotion.save(function (err) {
|
||||
should.exist(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('should fail when saving a duplicate promotion', function(done){
|
||||
promotion.save(function(err){
|
||||
promotion2.save(function(err){
|
||||
it('should fail when saving a duplicate promotion', function (done) {
|
||||
promotion.save(function (err) {
|
||||
promotion2.save(function (err) {
|
||||
should.exist(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('Search methods', function(){
|
||||
it('should find promotion by title', function(done){
|
||||
Promotion.findByTitle('Test Prom 1', function(result){
|
||||
describe('Search methods', function () {
|
||||
it('should find promotion by title', function (done) {
|
||||
Promotion.findOne({title: 'Test Prom 1', user: user}, function (err, result) {
|
||||
should.exist(result);
|
||||
should.not.exist(err);
|
||||
result.title.should.equal('Test Prom 1');
|
||||
done();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user