Exemple #1
0
        ActivityAggregator.collectAllBuckets(function() {
            ActivityNotifications.whenNotificationsEmpty(function() {

                var returned = false;

                /*!
                 * Takes care of invoking the callback when the email is "successfully sent".
                 *
                 * @see EmailAPI events
                 */
                var _handleDebugSent = function(message) {
                    if (!returned) {
                        returned = true;
                        return callback(null, message);
                    }
                };

                EmailAPI.once('debugSent', _handleDebugSent);

                // Send the email, and return the error if one occurs, otherwise the mailcomposer message will be
                // returned by _handleDebugSent
                EmailAPI.sendEmail(templateModule, templateId, toUser, data, opts, function(err) {
                    if (!returned && err) {
                        // We errored, the debugSent event *probably* won't be invoked. Unbind it and reply with the error
                        returned = true;
                        EmailAPI.removeListener('debugSent', _handleDebugSent);
                        return callback(err);
                    }
                });
            });
        });
Exemple #2
0
    MqTestsUtil.whenTasksEmpty(ActivityConstants.mq.TASK_ACTIVITY, function() {
        ActivityNotifications.whenNotificationsEmpty(function() {

            /*!
             * Handle the debugSent event, filling up the messages array with the messages we receive
             */
            var _handleDebugSent = function(message) {
                messages.push(message);
            };

            // Handler that simply collects the messages that are sent in this collection cycle into an array
            EmailAPI.on('debugSent', _handleDebugSent);

            // Collect the activity buckets, which will aggregate any pending activities into the proper email activity streams
            ActivityAggregator.collectAllBuckets(function() {

                // Collect and send the emails
                ActivityEmail.collectMails(bucketNumber, emailPreference, dayOfWeek, hourOfDay, function(err) {
                    assert.ok(!err);
                    EmailAPI.removeListener('debugSent', _handleDebugSent);
                    return callback(messages);
                });
            });
        });
    });
    MqTestsUtil.whenTasksEmpty(ActivityConstants.mq.TASK_ACTIVITY, function() {
        ActivityNotifications.whenNotificationsEmpty(function() {

            /*!
             * Handle the debugSent event, filling up the messages array with the messages we receive
             */
            var _handleDebugSent = function(message) {
                messages.push(message);
            };

            // Handler that simply collects the messages that are sent in this collection cycle into an array
            EmailAPI.on('debugSent', _handleDebugSent);

            // Collect the activity buckets, which will aggregate any pending activities into the proper email activity streams
            ActivityAggregator.collectAllBuckets(function() {

                // Ensure all scheduling of email delivery has been completed
                ActivityEmail.whenEmailsScheduled(function() {

                    // Collect and send the emails
                    ActivityEmail.collectAllBuckets(function() {
                        EmailAPI.removeListener('debugSent', _handleDebugSent);
                        return callback(messages);
                    });
                });
            });
        });
    });
Exemple #4
0
            ActivityAggregator.collectAllBuckets(function() {

                // Wait for all notifications resulting from the collection to fire then return the collected emails
                ActivityNotifications.whenNotificationsEmpty(function() {
                    EmailAPI.removeListener('debugSent', _handleDebugSent);
                    return callback(messages);
                });
            });
Exemple #5
0
    MqTestsUtil.whenTasksEmpty(ActivityConstants.mq.TASK_ACTIVITY, function() {
        ActivityNotifications.whenNotificationsEmpty(function() {

            /*!
             * Handle the debugSent event, filling up the messages array with the messages we receive
             */
            var _handleDebugSent = function(message) {
                messages.push(message);
            };

            // Handler that simply collects the messages that are sent in this collection cycle into an array
            EmailAPI.on('debugSent', _handleDebugSent);

            // Collect the activity buckets, which will aggregate any pending activities into the proper email activity streams
            ActivityAggregator.collectAllBuckets(function() {

                // Ensure all scheduling of email delivery has been completed
                ActivityEmail.whenEmailsScheduled(function() {

                    // Collect and send the emails
                    ActivityEmail.collectAllBuckets(function() {
                        EmailAPI.removeListener('debugSent', _handleDebugSent);

                        // SMTP specifications have a requirement that no line in an email body
                        // should surpass 999 characters, including the CR+LF character. This check
                        // ensures no email has an html content line longer than 500 chars, which
                        // accounts for post-processing things such as SendGrid changing the links
                        // to extremely long values (e.g., ~400 characters long) for click-tracking
                        //
                        // @see https://github.com/oaeproject/Hilary/issues/1168
                        _.each(messages, function(message) {
                            assert.ok(_.isString(message.html));
                            _.each(message.html.split('\n'), function(line) {
                                assert.ok(line.length <= 500, util.format('Expected no email line to be more than 500 characters, but found: (%s) %s', line.length, line));
                                assert.ok(line.split('<a').length < 3, util.format('Expected no email line to have more than 1 link, but found: %s', line));
                            });
                        });

                        return callback(messages);
                    });
                });
            });
        });
    });
Exemple #6
0
    MqTestsUtil.whenTasksEmpty(ActivityConstants.mq.TASK_ACTIVITY, function() {
        ActivityNotifications.whenNotificationsEmpty(function() {

            /*!
             * Handle the debugSent event, filling up the messages array with the messages we receive.
             */
            var _handleDebugSent = function(message) {
                messages.push(message);
            };

            // Handler that simply collects the messages that are sent in this collection cycle into an array
            EmailAPI.on('debugSent', _handleDebugSent);

            // Collect the activity buckets, which will cause any notifications to be fired
            ActivityAggregator.collectAllBuckets(function() {

                // Wait for all notifications resulting from the collection to fire then return the collected emails
                ActivityNotifications.whenNotificationsEmpty(function() {
                    EmailAPI.removeListener('debugSent', _handleDebugSent);
                    return callback(messages);
                });
            });
        });
    });