Example #1
0
                            ActivityTestsUtil.collectAndGetNotificationStream(nico.restContext, null, function(err, activityStream) {
                                assert.ok(!err);
                                assert.ok(_.find(activityStream.items, function(activity) { return (activity['oae:activityType'] === 'discussion-message'); }));

                                // Create another message and assert that both the managers and the recent contributers get a notification
                                RestAPI.Discussions.createMessage(nico.restContext, discussion.id, 'Message A', null, function(err, message) {
                                    assert.ok(!err);

                                    // Because Bert made a message previously, he should get a notification as well
                                    ActivityTestsUtil.collectAndGetNotificationStream(bert.restContext, null, function(err, activityStream) {
                                        assert.ok(!err);
                                        var messageActivities = _.filter(activityStream.items, function(activity) { return (activity['oae:activityType'] === 'discussion-message'); });
                                        assert.ok(messageActivities.length, 2);

                                        // Sanity-check that the managers got it as well
                                        ActivityTestsUtil.collectAndGetNotificationStream(nico.restContext, null, function(err, activityStream) {
                                            assert.ok(!err);
                                            var messageActivities = _.filter(activityStream.items, function(activity) { return (activity['oae:activityType'] === 'discussion-message'); });
                                            assert.ok(messageActivities.length, 2);

                                            ActivityTestsUtil.collectAndGetNotificationStream(simon.restContext, null, function(err, activityStream) {
                                                assert.ok(!err);
                                                var messageActivities = _.filter(activityStream.items, function(activity) { return (activity['oae:activityType'] === 'discussion-message'); });
                                                assert.ok(messageActivities.length, 2);

                                                return callback();
                                            });
                                        });
                                    });
                                });
                            });
Example #2
0
                        RestAPI.Discussions.createDiscussion(mrvisser.restContext, 'A talk', 'about computers', 'public', [], [], function(err, discussion) {
                            assert.ok(!err);

                            // Post a new message
                            RestAPI.Discussions.createMessage(simong.restContext, discussion.id, '<b>Nice discussion.</b>\n\nWould read again', null, function(err, simongMessage) {
                                assert.ok(!err);

                                EmailTestsUtil.collectAndFetchAllEmails(function(emails) {
                                    // There should be exactly one email, the one sent to mrvisser (manager of discussion receives discussion-message notification)
                                    assert.equal(emails.length, 1);

                                    var stringEmail = JSON.stringify(emails[0]);
                                    var email = emails[0];

                                    // Sanity check that the email is to mrvisser
                                    assert.equal(email.to[0].address, mrvisser.user.email);

                                    // Ensure that the subject of the email contains the poster's name
                                    assert.notEqual(email.subject.indexOf('swappedFromPublicAlias'), -1);

                                    // Ensure some data expected to be in the email is there
                                    assert.notEqual(stringEmail.indexOf(simong.restContext.hostHeader), -1);
                                    assert.notEqual(stringEmail.indexOf(discussion.profilePath), -1);
                                    assert.notEqual(stringEmail.indexOf(discussion.displayName), -1);

                                    // Ensure simong's private info is nowhere to be found
                                    assert.equal(stringEmail.indexOf(simong.user.displayName), -1);
                                    assert.equal(stringEmail.indexOf(simong.user.email), -1);
                                    assert.equal(stringEmail.indexOf(simong.user.locale), -1);

                                    // The email should contain the public alias
                                    assert.notEqual(stringEmail.indexOf('swappedFromPublicAlias'), -1);

                                    // The message should have escaped the HTML content in the original message
                                    assert.strictEqual(stringEmail.indexOf('<b>Nice discussion.</b>'), -1);

                                    // The new line characters should've been converted into paragraphs
                                    assert.notEqual(stringEmail.indexOf('Would read again</p>'), -1);

                                    // Send a message as nicolaas and ensure the recent commenter, simong receives an email about it
                                    RestAPI.Discussions.createMessage(nicolaas.restContext, discussion.id, 'I have a computer, too', null, function(err, nicolaasMessage) {
                                        assert.ok(!err);

                                        EmailTestsUtil.collectAndFetchAllEmails(function(emails) {
                                            // There should be 2 emails this time, one to the manager and one to the recent commenter, simong
                                            assert.equal(emails.length, 2);

                                            var emailAddresses = [emails[0].to[0].address, emails[1].to[0].address];
                                            assert.ok(_.contains(emailAddresses, simong.user.email));
                                            assert.ok(_.contains(emailAddresses, mrvisser.user.email));
                                            return callback();
                                        });
                                    });
                                });
                            });
                        });
Example #3
0
                        RestAPI.Discussions.createDiscussion(mrvisser.restContext, 'A talk', 'about computers', 'public', [], [], function(err, discussion) {
                            assert.ok(!err);

                            // Post a new message
                            RestAPI.Discussions.createMessage(simong.restContext, discussion.id, 'Nice discussion, would read again', null, function(err, simongMessage) {
                                assert.ok(!err);

                                EmailTestsUtil.collectAndFetchEmails(function(emails) {
                                    // There should be exactly one email, the one sent to mrvisser (manager of discussion receives discussion-message notification)
                                    assert.equal(emails.length, 1);

                                    var stringEmail = JSON.stringify(emails[0]);
                                    var email = emails[0]._message;

                                    // Sanity check that the email is to mrvisser
                                    assert.equal(email.to, mrvisser.user.email);

                                    // Ensure some data expected to be in the email is there
                                    assert.notEqual(stringEmail.indexOf(simong.restContext.hostHeader), -1);
                                    assert.notEqual(stringEmail.indexOf(discussion.profilePath), -1);
                                    assert.notEqual(stringEmail.indexOf(discussion.displayName), -1);

                                    // Ensure simong's private info is nowhere to be found
                                    assert.equal(stringEmail.indexOf(simong.user.displayName), -1);
                                    assert.equal(stringEmail.indexOf(simong.user.email), -1);
                                    assert.equal(stringEmail.indexOf(simong.user.locale), -1);
                                    assert.equal(stringEmail.indexOf(simong.user.timezone), -1);

                                    // The email should contain the public alias
                                    assert.notEqual(stringEmail.indexOf('swappedFromPublicAlias'), -1);

                                    // Send a message as nicolaas and ensure the recent commenter, simong receives an email about it
                                    RestAPI.Discussions.createMessage(nicolaas.restContext, discussion.id, 'I have a computer, too', null, function(err, nicolaasMessage) {
                                        assert.ok(!err);

                                        EmailTestsUtil.collectAndFetchEmails(function(emails) {
                                            // There should be 2 emails this time, one to the manager and one to the recent commenter, simong
                                            assert.equal(emails.length, 2);

                                            var emailAddresses = [emails[0]._message.to, emails[1]._message.to];
                                            assert.ok(_.contains(emailAddresses, simong.user.email));
                                            assert.ok(_.contains(emailAddresses, mrvisser.user.email));
                                            return callback();
                                        });
                                    });
                                });
                            });
                        });
Example #4
0
                            ActivityTestsUtil.collectAndGetActivityStream(simon.restContext, simon.user.id, null, function(err, activityStream) {
                                assert.ok(!err);
                                var entity = activityStream.items[0];
                                assert.equal(entity['oae:activityType'], 'discussion-message');
                                assert.equal(entity['verb'], 'post');
                                // Assert Simon is the actor
                                assert.equal(entity.actor['oae:id'], simon.user.id);

                                // Assert the discussion is the target
                                assert.equal(entity.target['oae:id'], discussion.id);
                                assert.equal(entity.target['displayName'], discussion.displayName);
                                assert.equal(entity.target['oae:profilePath'], discussion.profilePath);

                                // Assert the message is the object
                                assert.equal(entity.object['oae:id'], message.id);
                                assert.equal(entity.object['oae:messageBoxId'], message.messageBoxId);
                                assert.equal(entity.object['oae:threadKey'], message.threadKey);
                                assert.equal(entity.object['content'], message.body);
                                assert.equal(entity.object['published'], message.created);
                                assert.equal(entity.object['objectType'], 'discussion-message');
                                assert.equal(entity.object['id'], 'http://' + global.oaeTests.tenants.cam.host + '/api/discussion/' + discussion.id + '/messages/' + message.created);

                                // Nico replies
                                RestAPI.Discussions.createMessage(nico.restContext, discussion.id, 'A reply', message.created, function(err, nicosMessage) {
                                    assert.ok(!err);

                                    ActivityTestsUtil.collectAndGetActivityStream(simon.restContext, simon.user.id, null, function(err, activityStream) {
                                        assert.ok(!err);

                                        // The first item should still be a discussion-message.
                                        // The object and actor will now be collections rather than a single message/person
                                        var entity = activityStream.items[0];
                                        assert.equal(entity['oae:activityType'], 'discussion-message');

                                        // The object should be an oae:collection containing 2 messages (the original message and the reply)
                                        assert.equal(entity.object['objectType'], 'collection');
                                        assert.ok(entity.object['oae:collection']);
                                        assert.equal(entity.object['oae:collection'].length, 2);
                                        var originalMessage = _.find(entity.object['oae:collection'], function(activityMessage) { return activityMessage['oae:id'] === message.id; });
                                        assert.ok(originalMessage);
                                        assert.equal(originalMessage['oae:id'], message.id);
                                        assert.equal(originalMessage['content'], message.body);
                                        assert.equal(originalMessage['author']['oae:id'], simon.user.id);
                                        assert.equal(originalMessage['oae:tenant']['alias'], global.oaeTests.tenants.cam.alias);

                                        var reply = _.find(entity.object['oae:collection'], function(activityMessage) { return activityMessage['oae:id'] === nicosMessage.id; });
                                        assert.ok(reply);
                                        assert.equal(reply['oae:id'], nicosMessage.id);
                                        assert.equal(reply['oae:messageBoxId'], nicosMessage.messageBoxId);
                                        assert.equal(reply['oae:threadKey'], nicosMessage.threadKey);
                                        assert.equal(reply['oae:tenant']['alias'], global.oaeTests.tenants.cam.alias);
                                        assert.equal(reply['content'], nicosMessage.body);
                                        assert.equal(reply['published'], nicosMessage.created);
                                        assert.equal(reply['author']['oae:id'], nico.user.id);
                                        assert.ok(reply['inReplyTo']);
                                        assert.equal(reply['inReplyTo']['oae:id'], message.id);

                                        // Verify both actors are present
                                        assert.equal(entity.actor['objectType'], 'collection');
                                        var simonEntity = _.find(entity.actor['oae:collection'], function(userEntity) { return userEntity['oae:id'] === simon.user.id; });
                                        assert.ok(simonEntity);
                                        assert.equal(simonEntity['oae:id'], simon.user.id);
                                        assert.equal(simonEntity['oae:profilePath'], '/user/' + simon.user.tenant.alias + '/' + AuthzUtil.getResourceFromId(simon.user.id).resourceId);

                                        var nicoEntity = _.find(entity.actor['oae:collection'], function(userEntity) { return userEntity['oae:id'] === nico.user.id; });
                                        assert.ok(nicoEntity);
                                        assert.equal(nicoEntity['oae:id'], nico.user.id);
                                        assert.equal(nicoEntity['oae:profilePath'], '/user/' + nico.user.tenant.alias + '/' + AuthzUtil.getResourceFromId(nico.user.id).resourceId);

                                        return callback();
                                    });
                                });
                            });