social tests

This commit is contained in:
Barış Soner Uşaklı
2017-05-23 20:43:09 -04:00
parent b2cef4846c
commit b8cc67dfff
4 changed files with 47 additions and 42 deletions

View File

@@ -4,7 +4,7 @@ var plugins = require('./plugins');
var db = require('./database');
var async = require('async');
var social = {};
var social = module.exports;
social.postSharing = null;
@@ -36,32 +36,31 @@ social.getPostSharing = function (callback) {
plugins.fireHook('filter:social.posts', networks, next);
},
function (networks, next) {
db.getSetMembers('social:posts.activated', function (err, activated) {
if (err) {
return next(err);
}
networks.forEach(function (network, i) {
networks[i].activated = (activated.indexOf(network.id) !== -1);
});
social.postSharing = networks;
next(null, networks);
db.getSetMembers('social:posts.activated', next);
},
function (activated, next) {
networks.forEach(function (network, i) {
networks[i].activated = (activated.indexOf(network.id) !== -1);
});
social.postSharing = networks;
next(null, networks);
},
], callback);
};
social.getActivePostSharing = function (callback) {
social.getPostSharing(function (err, networks) {
if (err) {
return callback(err);
}
networks = networks.filter(function (network) {
return network && network.activated;
});
callback(null, networks);
});
async.waterfall([
function (next) {
social.getPostSharing(next);
},
function (networks, next) {
networks = networks.filter(function (network) {
return network && network.activated;
});
next(null, networks);
},
], callback);
};
social.setActivePostSharingNetworks = function (networkIDs, callback) {
@@ -81,5 +80,3 @@ social.setActivePostSharingNetworks = function (networkIDs, callback) {
},
], callback);
};
module.exports = social;