Beginners questions on unit testing

I validate data from request in the controller and inside mongoose pre save hook, should all validation be moved to functions so its easier to test ?

Let's think about it from a different perspective. Are those validations duplicated in any way (e.g. across controllers and/or in controller and hook)? Are the validations minimally complex? Do they express semantic meaning? Do they clutter your controller? I mean, there may be other reasons to extract them to functions. If some of those are true, then they will add up to "being easier to test". Actually, not being easy to test in itself is not usually such a strong reason, but then again it is usually a sign that there may be other concerns you might want to look into.

/r/javascript Thread