mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-10 07:55:46 +01:00
social tests
This commit is contained in:
@@ -1,20 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
|
||||
var social = require('../../social');
|
||||
|
||||
var socialController = {};
|
||||
|
||||
var socialController = module.exports;
|
||||
|
||||
socialController.get = function (req, res, next) {
|
||||
social.getPostSharing(function (err, posts) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
res.render('admin/general/social', {
|
||||
posts: posts,
|
||||
});
|
||||
});
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
social.getPostSharing(next);
|
||||
},
|
||||
function (posts) {
|
||||
res.render('admin/general/social', {
|
||||
posts: posts,
|
||||
});
|
||||
},
|
||||
], next);
|
||||
};
|
||||
|
||||
module.exports = socialController;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
var social = require('../../social');
|
||||
var SocketSocial = {};
|
||||
var SocketSocial = module.exports;
|
||||
|
||||
SocketSocial.savePostSharingNetworks = function (socket, data, callback) {
|
||||
social.setActivePostSharingNetworks(data, callback);
|
||||
};
|
||||
|
||||
module.exports = SocketSocial;
|
||||
|
||||
@@ -391,10 +391,20 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load /admin/general/social', function (done) {
|
||||
request(nconf.get('url') + '/api/admin/general/social', { jar: jar, json: true }, function (err, res, body) {
|
||||
var socketAdmin = require('../src/socket.io/admin');
|
||||
socketAdmin.social.savePostSharingNetworks({ uid: adminUid }, ['facebook', 'twitter', 'google'], function (err) {
|
||||
assert.ifError(err);
|
||||
assert(body);
|
||||
done();
|
||||
request(nconf.get('url') + '/api/admin/general/social', { jar: jar, json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert(body);
|
||||
body = body.posts.map(function (network) {
|
||||
return network && network.id;
|
||||
});
|
||||
assert(body.indexOf('facebook') !== -1);
|
||||
assert(body.indexOf('twitter') !== -1);
|
||||
assert(body.indexOf('google') !== -1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user