mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-10 16:05:49 +01:00
social tests
This commit is contained in:
@@ -1,20 +1,20 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var async = require('async');
|
||||||
|
|
||||||
var social = require('../../social');
|
var social = require('../../social');
|
||||||
|
|
||||||
var socialController = {};
|
var socialController = module.exports;
|
||||||
|
|
||||||
|
|
||||||
socialController.get = function (req, res, next) {
|
socialController.get = function (req, res, next) {
|
||||||
social.getPostSharing(function (err, posts) {
|
async.waterfall([
|
||||||
if (err) {
|
function (next) {
|
||||||
return next(err);
|
social.getPostSharing(next);
|
||||||
}
|
},
|
||||||
|
function (posts) {
|
||||||
res.render('admin/general/social', {
|
res.render('admin/general/social', {
|
||||||
posts: posts,
|
posts: posts,
|
||||||
});
|
});
|
||||||
});
|
},
|
||||||
|
], next);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = socialController;
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ var plugins = require('./plugins');
|
|||||||
var db = require('./database');
|
var db = require('./database');
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
|
|
||||||
var social = {};
|
var social = module.exports;
|
||||||
|
|
||||||
social.postSharing = null;
|
social.postSharing = null;
|
||||||
|
|
||||||
@@ -36,32 +36,31 @@ social.getPostSharing = function (callback) {
|
|||||||
plugins.fireHook('filter:social.posts', networks, next);
|
plugins.fireHook('filter:social.posts', networks, next);
|
||||||
},
|
},
|
||||||
function (networks, next) {
|
function (networks, next) {
|
||||||
db.getSetMembers('social:posts.activated', function (err, activated) {
|
db.getSetMembers('social:posts.activated', next);
|
||||||
if (err) {
|
},
|
||||||
return next(err);
|
function (activated, next) {
|
||||||
}
|
networks.forEach(function (network, i) {
|
||||||
|
networks[i].activated = (activated.indexOf(network.id) !== -1);
|
||||||
networks.forEach(function (network, i) {
|
|
||||||
networks[i].activated = (activated.indexOf(network.id) !== -1);
|
|
||||||
});
|
|
||||||
|
|
||||||
social.postSharing = networks;
|
|
||||||
next(null, networks);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
social.postSharing = networks;
|
||||||
|
next(null, networks);
|
||||||
},
|
},
|
||||||
], callback);
|
], callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
social.getActivePostSharing = function (callback) {
|
social.getActivePostSharing = function (callback) {
|
||||||
social.getPostSharing(function (err, networks) {
|
async.waterfall([
|
||||||
if (err) {
|
function (next) {
|
||||||
return callback(err);
|
social.getPostSharing(next);
|
||||||
}
|
},
|
||||||
networks = networks.filter(function (network) {
|
function (networks, next) {
|
||||||
return network && network.activated;
|
networks = networks.filter(function (network) {
|
||||||
});
|
return network && network.activated;
|
||||||
callback(null, networks);
|
});
|
||||||
});
|
next(null, networks);
|
||||||
|
},
|
||||||
|
], callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
social.setActivePostSharingNetworks = function (networkIDs, callback) {
|
social.setActivePostSharingNetworks = function (networkIDs, callback) {
|
||||||
@@ -81,5 +80,3 @@ social.setActivePostSharingNetworks = function (networkIDs, callback) {
|
|||||||
},
|
},
|
||||||
], callback);
|
], callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = social;
|
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var social = require('../../social');
|
var social = require('../../social');
|
||||||
var SocketSocial = {};
|
var SocketSocial = module.exports;
|
||||||
|
|
||||||
SocketSocial.savePostSharingNetworks = function (socket, data, callback) {
|
SocketSocial.savePostSharingNetworks = function (socket, data, callback) {
|
||||||
social.setActivePostSharingNetworks(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) {
|
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.ifError(err);
|
||||||
assert(body);
|
request(nconf.get('url') + '/api/admin/general/social', { jar: jar, json: true }, function (err, res, body) {
|
||||||
done();
|
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