Skip to content

Node.js based forum software built for the modern web

breaking: remove deprecated socket.emit('admin.categories.update')

Barış Soner Uşaklı0b9c01f9a0d5
diff --git a/src/api/categories.js b/src/api/categories.js
index 3c2e6a96ec..2871b6cf9d 100644
--- a/src/api/categories.js
+++ b/src/api/categories.js
@@ -27,6 +27,9 @@ categoriesAPI.create = async function (caller, data) {
};
categoriesAPI.update = async function (caller, data) {
+ if (!data) {
+ throw new Error('[[error:invalid-data]]');
+ }
await categories.update(data);
};
diff --git a/src/privileges/admin.js b/src/privileges/admin.js
index 11ef66973b..cea44886a3 100644
--- a/src/privileges/admin.js
+++ b/src/privileges/admin.js
@@ -76,7 +76,6 @@ privsAdmin.socketMap = {
'admin.rooms.getAll': 'admin:dashboard',
'admin.analytics.get': 'admin:dashboard',
- 'admin.categories.update': 'admin:categories',
'admin.categories.copySettingsFrom': 'admin:categories',
'admin.categories.getPrivilegeSettings': 'admin:privileges',
diff --git a/src/socket.io/admin/categories.js b/src/socket.io/admin/categories.js
index 492d6811b3..2360e29da8 100644
--- a/src/socket.io/admin/categories.js
+++ b/src/socket.io/admin/categories.js
@@ -11,15 +11,6 @@ Categories.getNames = async function () {
return await categories.getAllCategoryFields(['cid', 'name']);
};
-Categories.update = async function (socket, data) {
- sockets.warnDeprecated(socket, 'PUT /api/v3/categories/:cid');
-
- if (!data) {
- throw new Error('[[error:invalid-data]]');
- }
- return await api.categories.update(socket, data);
-};
-
Categories.setPrivilege = async function (socket, data) {
sockets.warnDeprecated(socket, 'PUT /api/v3/categories/:cid/privileges/:privilege');
diff --git a/test/categories.js b/test/categories.js
index 78e953f8a9..979f1c7593 100644
--- a/test/categories.js
+++ b/test/categories.js
@@ -363,50 +363,49 @@ describe('Categories', () => {
cid = category.cid;
});
- it('should return error with invalid data', (done) => {
- socketCategories.update({ uid: adminUid }, null, (err) => {
- assert.equal(err.message, '[[error:invalid-data]]');
- done();
- });
+ it('should return error with invalid data', async () => {
+ let err;
+ try {
+ await apiCategories.update({ uid: adminUid }, null);
+ } catch (_err) {
+ err = _err;
+ }
+ assert.strictEqual(err.message, '[[error:invalid-data]]');
});
- it('should error if you try to set parent as self', (done) => {
+ it('should error if you try to set parent as self', async () => {
const updateData = {};
updateData[cid] = {
parentCid: cid,
};
- socketCategories.update({ uid: adminUid }, updateData, (err) => {
- assert.equal(err.message, '[[error:cant-set-self-as-parent]]');
- done();
- });
+ let err;
+ try {
+ await apiCategories.update({ uid: adminUid }, updateData);
+ } catch (_err) {
+ err = _err;
+ }
+ assert.strictEqual(err.message, '[[error:cant-set-self-as-parent]]');
});
- it('should error if you try to set child as parent', (done) => {
- let child1Cid;
- let parentCid;
- async.waterfall([
- function (next) {
- Categories.create({ name: 'parent 1', description: 'poor parent' }, next);
- },
- function (category, next) {
- parentCid = category.cid;
- Categories.create({ name: 'child1', description: 'wanna be parent', parentCid: parentCid }, next);
- },
- function (category, next) {
- child1Cid = category.cid;
- const updateData = {};
- updateData[parentCid] = {
- parentCid: child1Cid,
- };
- socketCategories.update({ uid: adminUid }, updateData, (err) => {
- assert.equal(err.message, '[[error:cant-set-child-as-parent]]');
- next();
- });
- },
- ], done);
+ it('should error if you try to set child as parent', async () => {
+ const parentCategory = await Categories.create({ name: 'parent 1', description: 'poor parent' });
+ const parentCid = parentCategory.cid;
+ const childCategory = await Categories.create({ name: 'child1', description: 'wanna be parent', parentCid: parentCid });
+ const child1Cid = childCategory.cid;
+ const updateData = {};
+ updateData[parentCid] = {
+ parentCid: child1Cid,
+ };
+ let err;
+ try {
+ await apiCategories.update({ uid: adminUid }, updateData);
+ } catch (_err) {
+ err = _err;
+ }
+ assert.strictEqual(err.message, '[[error:cant-set-child-as-parent]]');
});
- it('should update category data', (done) => {
+ it('should update category data', async () => {
const updateData = {};
updateData[cid] = {
name: 'new name',
@@ -415,18 +414,14 @@ describe('Categories', () => {
order: 3,
icon: 'fa-hammer',
};
- socketCategories.update({ uid: adminUid }, updateData, (err) => {
- assert.ifError(err);
- Categories.getCategoryData(cid, (err, data) => {
- assert.ifError(err);
- assert.equal(data.name, updateData[cid].name);
- assert.equal(data.description, updateData[cid].description);
- assert.equal(data.parentCid, updateData[cid].parentCid);
- assert.equal(data.order, updateData[cid].order);
- assert.equal(data.icon, updateData[cid].icon);
- done();
- });
- });
+ await apiCategories.update({ uid: adminUid }, updateData);
+
+ const data = await Categories.getCategoryData(cid);
+ assert.equal(data.name, updateData[cid].name);
+ assert.equal(data.description, updateData[cid].description);
+ assert.equal(data.parentCid, updateData[cid].parentCid);
+ assert.equal(data.order, updateData[cid].order);
+ assert.equal(data.icon, updateData[cid].icon);
});
it('should not remove category from parent if parent is set again to same category', async () => {