Commit efe775c0 authored by Andy Trevorah's avatar Andy Trevorah Committed by Andrew Newdigate

Merge pull request #2431 from troupe/feature/topic-notification-slug-fix

topic notification slug fix
parents acbe8387 33ede12d
......@@ -12,7 +12,7 @@ describe('forum-notification-events', function() {
describe('integration tests #slow', function() {
describe('notificationObserver multi', function() {
describe('notificationObserver with multiple events', function() {
var fixture = fixtureLoader.setup({
user1: {},
user2: {},
......@@ -41,7 +41,7 @@ describe('forum-notification-events', function() {
},
});
it('should raise notifications', function() {
it('should batch the notifications in order', function() {
var userId = fixture.user1._id;
var forumId = fixture.forum1._id;
......@@ -68,23 +68,21 @@ describe('forum-notification-events', function() {
})
.then(function(notifications) {
assert.strictEqual(notifications.length, 3);
// first is topic 1
assert.strictEqual(String(notifications[0].recipient._id), String(userId));
assert.strictEqual(notifications[0].data.forum.id, String(forumId));
assert.strictEqual(notifications[0].data.topic.id, String(topicId1));
assert.strictEqual(notifications[0].data.reply, undefined);
// second is topic 2
assert.strictEqual(String(notifications[1].recipient._id), String(userId));
assert.strictEqual(notifications[1].data.forum.id, String(forumId));
assert.strictEqual(notifications[1].data.topic.id, String(topicId2));
assert.strictEqual(notifications[1].data.reply, undefined);
// last is reply1
assert.strictEqual(String(notifications[2].recipient._id), String(userId));
assert.strictEqual(notifications[2].data.forum.id, String(forumId));
assert.strictEqual(notifications[2].data.topic.id, String(topicId1));
assert(!notifications[0].data.reply);
assert(!notifications[1].data.reply);
assert.strictEqual(notifications[2].data.reply.id, String(replyId));
notifications.forEach(function(notification) {
// Check that the user matches
assert.strictEqual(String(notification.recipient._id), String(userId));
// Check that the forum matches
assert.strictEqual(notification.data.forum.id, String(forumId));
});
});
});
});
......
......@@ -7,21 +7,21 @@ function AggregatedCommentStrategy() {
}
AggregatedCommentStrategy.prototype = {
map: function(item, authorUser, owningComment, owningTopic, owningForum) {
map: function(reply, authorUser, owningComment, owningTopic, owningForum) {
var owningTopicId = owningTopic.id || (owningTopic._id && owningTopic._id.toHexString());
return {
id: item.id || item._id && item._id.toHexString(),
id: reply.id || reply._id && reply._id.toHexString(),
body: {
text: item.text,
html: item.html
text: reply.text,
html: reply.html
},
user: this.userStrategy.map(authorUser),
sent: item.sent,
editedAt: item.editedAt,
sent: reply.sent,
editedAt: reply.editedAt,
// TODO: permalink?
uri: owningForum.uri + '/topic/' + owningTopicId + '/' + item.slug
uri: owningForum.uri + '/topic/' + owningTopicId + '/' + owningTopic.slug
};
},
......
......@@ -4,12 +4,12 @@ function AggregatedForumStrategy() {
}
AggregatedForumStrategy.prototype = {
map: function(item) {
map: function(forum) {
return {
id: item.id || item._id && item._id.toHexString(),
name: item.name,
uri: item.uri,
tags: item.tags
id: forum.id || forum._id && forum._id.toHexString(),
name: forum.name,
uri: forum.uri,
tags: forum.tags
};
},
......
......@@ -7,26 +7,26 @@ function AggregatedReplyStrategy() {
}
AggregatedReplyStrategy.prototype = {
map: function(item, authorUser, owningTopic, owningForum) {
map: function(reply, authorUser, owningTopic, owningForum) {
var owningTopicId = owningTopic.id || (owningTopic._id && owningTopic._id.toHexString());
return {
id: item.id || item._id && item._id.toHexString(),
id: reply.id || reply._id && reply._id.toHexString(),
body: {
text: item.text,
html: item.html,
text: reply.text,
html: reply.html,
},
user: this.userStrategy.map(authorUser),
commentsTotal: item.commentsTotal,
sent: item.sent,
editedAt: item.editedAt,
lastChanged: item.lastChanged,
lastModified: item.lastModified,
commentsTotal: reply.commentsTotal,
sent: reply.sent,
editedAt: reply.editedAt,
lastChanged: reply.lastChanged,
lastModified: reply.lastModified,
// TODO: permalink?
uri: owningForum.uri + '/topic/' + owningTopicId + '/' + item.slug
uri: owningForum.uri + '/topic/' + owningTopicId + '/' + owningTopic.slug
};
},
......
......@@ -7,29 +7,29 @@ function AggregatedTopicStrategy() {
}
AggregatedTopicStrategy.prototype = {
map: function(item, authorUser, owningForum) {
var id = item.id || item._id && item._id.toHexString();
map: function(topic, authorUser, owningForum) {
var id = topic.id || topic._id && topic._id.toHexString();
return {
id: id,
title: item.title,
slug: item.slug,
title: topic.title,
slug: topic.slug,
body: {
text: item.text,
html: item.html,
text: topic.text,
html: topic.html,
},
sticky: item.sticky,
tags: item.tags,
sticky: topic.sticky,
tags: topic.tags,
// category: this.mapCategory(topic.categoryId), Deal with Category
user: this.userStrategy.map(authorUser),
repliesTotal: item.repliesTotal,
sent: item.sent,
editedAt: item.editedAt,
lastChanged: item.lastChanged,
lastModified: item.lastModified,
repliesTotal: topic.repliesTotal,
sent: topic.sent,
editedAt: topic.editedAt,
lastChanged: topic.lastChanged,
lastModified: topic.lastModified,
// TODO: permalink?
uri: owningForum.uri + '/topic/' + id + '/' + item.slug
uri: owningForum.uri + '/topic/' + id + '/' + topic.slug
}
},
......
"use strict";
var assert = require('assert');
var fixtureLoader = require('gitter-web-test-utils/lib/test-fixtures');
var Strategy = require('../lib/notifications/aggregated-comment-strategy');
var assertStringifiedEqual = require('./assert-stringified-equal');
describe('aggregated-comment-strategy', function() {
var fixture = fixtureLoader.setup({
user: {},
forum: {},
category: {
forum: 'forum',
},
topic: {
user: 'user',
forum: 'forum',
category: 'category',
sent: new Date('2014-01-01T00:00:00.000Z')
},
reply: {
forum: 'forum',
category: 'category',
user: 'user',
topic: 'topic',
sent: new Date('2014-02-01T00:00:00.000Z')
},
comment1: {
forum: 'forum',
user: 'user',
topic: 'topic',
reply: 'reply',
sent: new Date('2014-03-01T00:00:00.000Z')
}
});
it('serializes correctly', function () {
var strategy = new Strategy();
var user = fixture.user;
var forum = fixture.forum;
var topic = fixture.topic;
var reply = fixture.reply;
var comment = fixture.comment;
var result = strategy.map(reply, user, comment, topic, forum);
assert.equal(result.user.id, user._id);
// dont bother testing the user serializer, just check that the user is there
delete result.user;
assertStringifiedEqual(result, {
id: reply._id,
body: {},
sent: "2014-02-01T00:00:00.000Z",
editedAt: null,
uri: forum.uri + "/topic/" + topic._id + "/" + topic.slug
});
});
});
"use strict";
var fixtureLoader = require('gitter-web-test-utils/lib/test-fixtures');
var Strategy = require('../lib/notifications/aggregated-forum-strategy');
var assertStringifiedEqual = require('./assert-stringified-equal');
describe('aggregated-forum-strategy', function() {
var fixture = fixtureLoader.setup({
forum: {}
});
it('serializes correctly', function () {
var strategy = new Strategy();
var forum = fixture.forum;
var result = strategy.map(forum);
assertStringifiedEqual(result, {
id: forum._id,
name: forum.name,
uri: forum.uri,
tags: []
});
});
});
"use strict";
var assert = require('assert');
var fixtureLoader = require('gitter-web-test-utils/lib/test-fixtures');
var Strategy = require('../lib/notifications/aggregated-reply-strategy');
var assertStringifiedEqual = require('./assert-stringified-equal');
describe('aggregated-reply-strategy', function() {
var fixture = fixtureLoader.setup({
user: {},
forum: {},
category: {
forum: 'forum',
},
topic: {
user: 'user',
forum: 'forum',
category: 'category',
sent: new Date('2014-01-01T00:00:00.000Z')
},
reply: {
forum: 'forum',
category: 'category',
user: 'user',
topic: 'topic',
sent: new Date('2014-02-01T00:00:00.000Z')
}
});
it('serializes correctly', function () {
var strategy = new Strategy();
var user = fixture.user;
var forum = fixture.forum;
var topic = fixture.topic;
var reply = fixture.reply;
var result = strategy.map(reply, user, topic, forum);
assert.equal(result.user.id, user._id);
// dont bother testing the user serializer, just check that the user is there
delete result.user;
assertStringifiedEqual(result, {
id: reply._id,
body: {},
commentsTotal: 0,
sent: "2014-02-01T00:00:00.000Z",
editedAt: null,
lastChanged: "2014-02-01T00:00:00.000Z",
lastModified: "2014-02-01T00:00:00.000Z",
uri: forum.uri + "/topic/" + topic._id + "/" + topic.slug
});
});
});
"use strict";
var assert = require('assert');
var fixtureLoader = require('gitter-web-test-utils/lib/test-fixtures');
var Strategy = require('../lib/notifications/aggregated-topic-strategy');
var assertStringifiedEqual = require('./assert-stringified-equal');
describe('aggregated-topic-strategy', function() {
var fixture = fixtureLoader.setup({
user: {},
forum: {},
category: {
forum: 'forum',
},
topic: {
user: 'user',
forum: 'forum',
category: 'category',
sent: new Date('2014-01-01T00:00:00.000Z')
}
});
it('serializes correctly', function () {
var strategy = new Strategy();
var user = fixture.user;
var forum = fixture.forum;
var topic = fixture.topic;
var result = strategy.map(topic, user, forum);
assert.equal(result.user.id, user._id);
// dont bother testing the user serializer, just check that the user is there
delete result.user;
assertStringifiedEqual(result, {
id: topic._id,
title: topic.title,
slug: topic.slug,
body: {},
sticky: 0,
tags: [],
repliesTotal: 0,
sent: "2014-01-01T00:00:00.000Z",
editedAt: null,
lastChanged: "2014-01-01T00:00:00.000Z",
lastModified: "2014-01-01T00:00:00.000Z",
uri: forum.uri + "/topic/" + topic._id + "/" + topic.slug
});
});
});
"use strict";
var assert = require('assert');
function assertStringifiedEqual(value, expected) {
assert.strictEqual(
JSON.stringify(value, null, ' '),
JSON.stringify(expected, null, ' '));
}
module.exports = assertStringifiedEqual;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment