Last active
August 29, 2015 14:14
-
-
Save javm/6ddaa266169f1dbbba12 to your computer and use it in GitHub Desktop.
Catching errors with bluebird promises
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
addPreference: function(preference){ | |
var that = this; | |
return Question.findOne(preference.questionId) | |
.populate('configurator') | |
.then(function(question){ | |
return Preference.create({ | |
configurator: question.configurator.id, | |
question: question.id, | |
selectedAnswer: preference.selectedAnswer, | |
household: that.id | |
}).then(function(p){ | |
console.log(p); | |
that.preferences.add(p); | |
that.save().then(function(household){ | |
return Promise.resolve(household); | |
}); | |
}); | |
}); | |
} | |
describe("Household model", function(){ | |
describe("#addPreference()", function(){ | |
it("Should add a Preference object", function(done){ | |
Household.findOne(1).exec(function(err, household){ | |
household.addPreference({ | |
questionId: 4, | |
selectedAnswer: 3 | |
}).then(function (household){ | |
done(); | |
}).catch(function(err){ | |
console.log(err); | |
done(err); | |
}); | |
}); | |
}); | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment