more api tests

v1.18.x
barisusakli 9 years ago
parent 687cce6089
commit 777914b762

@ -21,36 +21,36 @@ module.exports = function (Posts) {
}; };
Posts.getCidsByPids = function (pids, callback) { Posts.getCidsByPids = function (pids, callback) {
Posts.getPostsFields(pids, ['tid'], function (err, posts) { var tids;
if (err) { var postData;
return callback(err); async.waterfall([
} function (next) {
Posts.getPostsFields(pids, ['tid'], next);
var tids = posts.map(function (post) { },
return post.tid; function (_postData, next) {
}).filter(function (tid, index, array) { postData = _postData;
return tid && array.indexOf(tid) === index; tids = postData.map(function (post) {
}); return post.tid;
}).filter(function (tid, index, array) {
topics.getTopicsFields(tids, ['cid'], function (err, topics) { return tid && array.indexOf(tid) === index;
if (err) { });
return callback(err);
}
topics.getTopicsFields(tids, ['cid'], next);
},
function (topicData, next) {
var map = {}; var map = {};
topics.forEach(function (topic, index) { topicData.forEach(function (topic, index) {
if (topic) { if (topic) {
map[tids[index]] = topic.cid; map[tids[index]] = topic.cid;
} }
}); });
var cids = posts.map(function (post) { var cids = postData.map(function (post) {
return map[post.tid]; return map[post.tid];
}); });
next(null, cids);
callback(null, cids); }
}); ], callback);
});
}; };
Posts.filterPidsByCid = function (pids, cid, callback) { Posts.filterPidsByCid = function (pids, cid, callback) {

@ -16,6 +16,7 @@ describe('Controllers', function () {
var tid; var tid;
var cid; var cid;
var pid;
var fooUid; var fooUid;
before(function (done) { before(function (done) {
@ -38,6 +39,7 @@ describe('Controllers', function () {
topics.post({uid: results.user, title: 'test topic title', content: 'test topic content', cid: results.category.cid}, function (err, result) { topics.post({uid: results.user, title: 'test topic title', content: 'test topic content', cid: results.category.cid}, function (err, result) {
tid = result.topicData.tid; tid = result.topicData.tid;
pid = result.postData.pid;
done(err); done(err);
}); });
}); });
@ -462,6 +464,33 @@ describe('Controllers', function () {
}); });
}); });
it('should get post data', function (done) {
request(nconf.get('url') + '/api/post/pid/' + pid, function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});
it('should get topic data', function (done) {
request(nconf.get('url') + '/api/topic/tid/' + tid, function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});
it('should get category data', function (done) {
request(nconf.get('url') + '/api/category/cid/' + cid, function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});
after(function (done) { after(function (done) {
db.emptydb(done); db.emptydb(done);
}); });

Loading…
Cancel
Save