|
|
@@ -6,18 +6,20 @@ settings = require("settings-sharelatex")
|
|
|
port = settings.internal.notifications.port
|
|
|
logger = require "logger-sharelatex"
|
|
|
|
|
|
+mongojs = require('mongojs')
|
|
|
+Settings = require 'settings-sharelatex'
|
|
|
+db = mongojs(Settings.mongo?.url, ['notifications'])
|
|
|
|
|
|
module.exports =
|
|
|
check : (callback)->
|
|
|
- project_id = ObjectId()
|
|
|
user_id = ObjectId(settings.notifications.healthCheck.user_id)
|
|
|
- notification_key = "smoke-test-notification"
|
|
|
+ notification_key = "smoke-test-notification-#{ObjectId()}"
|
|
|
getOpts = (endPath)-> {url:"http://localhost:#{port}/user/#{user_id}#{endPath}", timeout:3000}
|
|
|
logger.log user_id:user_id, opts:getOpts(), key:notification_key, user_id:user_id, "running health check"
|
|
|
jobs = [
|
|
|
(cb)->
|
|
|
opts = getOpts("/")
|
|
|
- opts.json = {key: notification_key, messageOpts:'', templateKey:'', user_id:user_id}
|
|
|
+ opts.json = {key: notification_key, messageOpts:'', templateKey:'f4g5', user_id:user_id}
|
|
|
request.post(opts, cb)
|
|
|
(cb)->
|
|
|
opts = getOpts("/")
|
|
|
@@ -27,14 +29,18 @@ module.exports =
|
|
|
return cb("status code not 200, its #{res.statusCode}")
|
|
|
|
|
|
hasNotification = _.some body, (notification)->
|
|
|
- notification.key == notification_key and _.contains(notification.user_id, user_id.toString())
|
|
|
+ notification.key == notification_key and notification.user_id == user_id.toString()
|
|
|
if hasNotification
|
|
|
- cb()
|
|
|
+ cb(null,body)
|
|
|
else
|
|
|
+ logger.log body:body, "what is in the body"
|
|
|
cb("notification not found in response")
|
|
|
]
|
|
|
- async.series jobs, (err)->
|
|
|
+ async.series jobs, (err, body)->
|
|
|
if err?
|
|
|
callback(err)
|
|
|
- opts = getOpts("/notification_id/#{notification_id}")
|
|
|
- request.del opts, callback
|
|
|
+ else
|
|
|
+ notification_id = body[1][0]._id
|
|
|
+ opts = getOpts("/notification/#{notification_id}")
|
|
|
+ request.del opts, (err, res, body)->
|
|
|
+ db.notifications.remove {_id:ObjectId(notification_id)}, callback
|