title: mocha test function with mongoose call
body: <p>Having some problems unit testing the below code, I'm unsure whether it is possible or not due to the way it is coded. </p>
  
  <blockquote>
    <p>storeModel.js</p>
  </blockquote>
  
  <pre><code>var storeSchema = new Schema({
      storeId : { type: String, index: true},
      storeName : String
  });
  var model = mongoose.model('store', storeSchema);
  
  var findStoresById = function(ids, callback) {
      model.find({ storeId: { $in: ids }}, function (err, result) {
          if (err) callback(err);
          callback(err, result);
      });
  };
  
  return {
      findStoresById: findStoresById,
      schema: storeSchema,
      model: model
  };}();
  </code></pre>
  
  <p>Which i test like so..</p>
  
  <pre><code>it('will call "findStoresById" and return matched values [storeId: 1111] ', function (done) {
  
      storeModel.findStoresById(['1111'], function(err, store) {
          assert.equal(store[0].storeId, '1111');
          assert.equal(store[0].storeName, 'StoreName');
          assert.equal(err, null);
          done();
      });
  
  });
  </code></pre>
  
  <p>However the problem when i implement the following code within a separate function:</p>
  
  <pre><code>get: function (req, res) {
  
      if (req.query.storeIds) {
  
          var ids = req.query.storeIds.split(',');
  
          storeModel.findStoresById(ids, function(err, stores) {
              if (err) {
                  return res.send(err);
              }
  
              if (_.isEmpty(stores)) {
                  var error = {
                      message: "No Results",
                      errorKey: "XXXX"
                  }
                  return res.status(404).json(error);
              }
              return res.json(stores);
          }); ...
  </code></pre>
  
  <p>How can i unit test this, i dont want to mock it as there is functionality in the "findStoreById" that needs testing, or is a refactor needed? suggestions?</p>