 
 if process.env.NODE_ENV == "test"
   exports.sendReports = sendReports
-  exports.fetchUsers = fetchUsers
+  exports.fetchDailySubscribers = fetchDailySubscribers
+  exports.fetchWeeklySubscribers = fetchWeeklySubscribers
   exports.fetchChannelReport = fetchChannelReport

    (Q.all promises).then ->
#      logger.info JSON.stringify reportMap
      for report in reportMap
        sendUserEmail report
      logger.info "sending user email "
      done()




sendUserEmail = (report) ->
  contact.contactUser 'email', 'duma@eworks.co.zw', report.type + ' report for ' + report.email , plainTemplate(report), htmlTemplate(report) , afterEmail


#TODO refactor function to include status metrics as well as to allow for weekly metrics
fetchChannelReport = (channel,user,callback) ->
  item = {}
  logger.info 'fetching channel report for #' + channel.name + ' ' + user.email + channel.id
  metrics.fetchChannelMetrics 'day',channel.id,user,{}
  .then (data) ->
    item.channel = channel
    item.data = data
    #Then fetch status metrics
    metrics.fetchChannelMetrics 'status',channel.id,user,{}
    .then (statusData) ->
      item.statusData = statusData
      callback item

fetchDailySubscribers = (callback) ->
  User.find { dailyReport: true }, callback
