mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 19:46:01 +01:00
add widget reset test
This commit is contained in:
@@ -218,34 +218,31 @@ widgets.reset = function (callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
widgets.resetTemplate = function (template, callback) {
|
widgets.resetTemplate = function (template, callback) {
|
||||||
db.getObject('widgets:' + template + '.tpl', function (err, area) {
|
var toBeDrafted = [];
|
||||||
if (err) {
|
async.waterfall([
|
||||||
return callback();
|
function (next) {
|
||||||
}
|
db.getObject('widgets:' + template + '.tpl', next);
|
||||||
|
},
|
||||||
var toBeDrafted = [];
|
function (area, next) {
|
||||||
for (var location in area) {
|
for (var location in area) {
|
||||||
if (area.hasOwnProperty(location)) {
|
if (area.hasOwnProperty(location)) {
|
||||||
toBeDrafted = toBeDrafted.concat(JSON.parse(area[location]));
|
toBeDrafted = toBeDrafted.concat(JSON.parse(area[location]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
db.delete('widgets:' + template + '.tpl', next);
|
||||||
|
},
|
||||||
db.delete('widgets:' + template + '.tpl');
|
function (next) {
|
||||||
db.getObjectField('widgets:global', 'drafts', function (err, draftWidgets) {
|
db.getObjectField('widgets:global', 'drafts', next);
|
||||||
if (err) {
|
},
|
||||||
return callback();
|
function (draftWidgets, next) {
|
||||||
}
|
|
||||||
|
|
||||||
draftWidgets = JSON.parse(draftWidgets).concat(toBeDrafted);
|
draftWidgets = JSON.parse(draftWidgets).concat(toBeDrafted);
|
||||||
db.setObjectField('widgets:global', 'drafts', JSON.stringify(draftWidgets), callback);
|
db.setObjectField('widgets:global', 'drafts', JSON.stringify(draftWidgets), next);
|
||||||
});
|
},
|
||||||
});
|
], callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
widgets.resetTemplates = function (templates, callback) {
|
widgets.resetTemplates = function (templates, callback) {
|
||||||
async.eachSeries(templates, function (template, next) {
|
async.eachSeries(templates, widgets.resetTemplate, callback);
|
||||||
widgets.resetTemplate(template, next);
|
|
||||||
}, callback);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = widgets;
|
module.exports = widgets;
|
||||||
|
|||||||
@@ -702,7 +702,7 @@ describe('Controllers', function () {
|
|||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.equal(res.statusCode, 200);
|
assert.equal(res.statusCode, 200);
|
||||||
assert(body.widgets);
|
assert(body.widgets);
|
||||||
assert.equal(Object.keys(body.widgets), 0);
|
assert.equal(Object.keys(body.widgets).length, 0);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -717,6 +717,19 @@ describe('Controllers', function () {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should reset templates', function (done) {
|
||||||
|
widgets.resetTemplates(['categories', 'category'], function (err) {
|
||||||
|
assert.ifError(err);
|
||||||
|
request(nconf.get('url') + '/api/categories', { json: true }, function (err, res, body) {
|
||||||
|
assert.ifError(err);
|
||||||
|
assert.equal(res.statusCode, 200);
|
||||||
|
assert(body.widgets);
|
||||||
|
assert.equal(Object.keys(body.widgets).length, 0);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('tags', function () {
|
describe('tags', function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user