Skip to content

Commit 5dc7681

Browse files
committed
fix cnodejs#237 if topic not exists, do not modified it.
1 parent 913d268 commit 5dc7681

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"loader": "0.0.5"
2121
},
2222
"devDependencies": {
23+
"supertest": "*",
2324
"should": "*",
2425
"mocha": "*",
2526
"rewire": "*",

proxy/topic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ exports.getFullTopic = function (id, callback) {
172172
*/
173173
exports.updateLastReply = function (topicId, replyId, callback) {
174174
Topic.findOne({_id: topicId}, function (err, topic) {
175-
if (err) {
175+
if (err || !topic) {
176176
return callback(err);
177177
}
178178
topic.last_reply = replyId;

test/proxy/topic.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ describe('proxy/topic.js', function () {
1717
});
1818
});
1919

20+
describe('updateLastReply()', function () {
21+
it('should update a topic reply count success when topic not exists', function (done) {
22+
Topic.updateLastReply('aaaaaaaaaaaaaaaaaaaaaaaa', 'aaaaaaaaaaaaaaaaaaaaaaaa', function (err, result) {
23+
should.not.exist(err);
24+
should.not.exist(result);
25+
done();
26+
});
27+
});
28+
});
29+
2030
describe('newAndSave', function () {
2131
it('should ok', function (done) {
2232
Topic.newAndSave('title', 'content', user._id, function (err, topic) {

0 commit comments

Comments
 (0)