Repository navigation
Expand file tree
/
Copy pathtopic.js
More file actions
124 lines (113 loc) · 3.5 KB
/
Copy pathtopic.js
File metadata and controls
124 lines (113 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
var Topic = require('../../proxy/topic');
var support = require('../support/support');
var should = require('should');
describe('proxy/topic.js', function () {
var user;
var topic;
before(function (done) {
support.createUser(function (err, _user) {
should.not.exist(err);
user = _user;
support.createTopic(_user._id, function (err, _topic) {
should.not.exist(err);
topic = _topic;
done();
});
});
});
describe('updateLastReply()', function () {
it('should update a topic reply count success when topic not exists', function (done) {
Topic.updateLastReply('aaaaaaaaaaaaaaaaaaaaaaaa', 'aaaaaaaaaaaaaaaaaaaaaaaa', function (err, result) {
should.not.exist(err);
should.not.exist(result);
done();
});
});
});
describe('newAndSave', function () {
it('should ok', function (done) {
Topic.newAndSave('title', 'content', user._id, function (err, topic) {
should.not.exist(err);
topic.title.should.equal('title');
topic.content.should.equal('content');
done();
});
});
});
describe('getTopicById', function () {
it('should empty', function (done) {
Topic.getTopicById(null, function (err, topic, tags, author, lastReply) {
should.not.exist(err);
should.not.exist(topic);
tags.should.have.length(0);
should.not.exist(author);
should.not.exist(lastReply);
done();
});
});
it('should ok', function (done) {
Topic.getTopicById(topic._id, function (err, topic, tags, author, lastReply) {
should.not.exist(err);
should.exist(topic);
tags.should.have.length(0);
author.loginname.should.equal(user.loginname);
should.not.exist(lastReply);
done();
});
});
});
describe('getFullTopic', function () {
it('should empty', function (done) {
Topic.getFullTopic(null, function (err, message, topic, tags, author, replies) {
should.not.exist(err);
message.should.be.equal("此话题不存在或已被删除。");
done();
});
});
it('should ok', function (done) {
Topic.getFullTopic(topic._id, function (err, message, topic, tags, author, replies) {
should.not.exist(err);
message.should.be.equal("");
topic.author_id.should.eql(user._id);
tags.should.have.length(0);
author.loginname.should.be.equal(user.loginname);
replies.should.have.length(0);
done();
});
});
});
describe('getTopic', function () {
it('should empty', function (done) {
Topic.getTopic(null, function (err, topic) {
should.not.exist(err);
should.not.exist(topic);
done();
});
});
it('should ok', function (done) {
Topic.getTopic(topic._id, function (err, topic) {
should.not.exist(err);
topic.author_id.should.eql(user._id);
done();
});
});
});
describe('reduceCount', function () {
it('should empty', function (done) {
Topic.reduceCount(null, function (err, topic) {
should.exist(err);
err.should.have.property('message', '该主题不存在');
should.not.exist(topic);
done();
});
});
it('should ok', function (done) {
var count = topic.reply_count;
Topic.reduceCount(topic._id, function (err, topic) {
should.not.exist(err);
topic.reply_count.should.equal(count - 1);
done();
});
});
});
});